fix: enforce representation blob ownership and secure SSR access
This commit is contained in:
@@ -65,6 +65,93 @@ test("document/getAwaitingSubmissionFromBlob logs and returns undefined on failu
|
||||
assert.strictEqual(logger.calls.length, 1);
|
||||
});
|
||||
|
||||
test("document/getRepsFromBlob forwards cookies only to trusted origin without redirects", async () => {
|
||||
const axios = createAxiosMock();
|
||||
const logger = createLoggerMock();
|
||||
|
||||
axios.getHandler = async () => ({
|
||||
data: { value: ["representation"] }
|
||||
});
|
||||
|
||||
const document = loadServiceModule("documentDirectService.js", {
|
||||
axios,
|
||||
BASE_URL: "http://example.local",
|
||||
consoleLogger: logger.consoleLogger,
|
||||
hashAPIPath: () => "&hash=abc123"
|
||||
});
|
||||
|
||||
const result = await document.getRepsFromBlob("container-1", {
|
||||
headers: {
|
||||
Cookie: "next-auth.session-token=test-session"
|
||||
}
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(normalize(result), {
|
||||
value: ["representation"]
|
||||
});
|
||||
|
||||
assert.strictEqual(axios.calls.length, 1);
|
||||
assert.strictEqual(
|
||||
axios.calls[0].url,
|
||||
"http://example.local/api/file/getrepsblob?container=container-1&hash=abc123"
|
||||
);
|
||||
assert.strictEqual(
|
||||
axios.calls[0].config.headers.Cookie,
|
||||
"next-auth.session-token=test-session"
|
||||
);
|
||||
assert.strictEqual(axios.calls[0].config.maxRedirects, 0);
|
||||
assert.strictEqual(logger.calls.length, 0);
|
||||
});
|
||||
|
||||
test("document/getRepsFromBlob rejects untrusted origin before HTTP request", async () => {
|
||||
const axios = createAxiosMock();
|
||||
const logger = createLoggerMock();
|
||||
|
||||
const document = loadServiceModule("documentDirectService.js", {
|
||||
axios,
|
||||
BASE_URL: "https://untrusted.example",
|
||||
consoleLogger: logger.consoleLogger,
|
||||
hashAPIPath: () => "&hash=abc123"
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
document.getRepsFromBlob("container-1", {
|
||||
headers: {
|
||||
Cookie: "next-auth.session-token=test-session"
|
||||
}
|
||||
}),
|
||||
/Untrusted representation request destination/
|
||||
);
|
||||
|
||||
assert.strictEqual(axios.calls.length, 0);
|
||||
assert.strictEqual(logger.calls.length, 0);
|
||||
});
|
||||
|
||||
test("document/getRepsFromBlob preserves requests without forwarded cookies", async () => {
|
||||
const axios = createAxiosMock();
|
||||
const logger = createLoggerMock();
|
||||
|
||||
axios.getHandler = async () => ({
|
||||
data: { value: ["representation"] }
|
||||
});
|
||||
|
||||
const document = loadServiceModule("documentDirectService.js", {
|
||||
axios,
|
||||
BASE_URL: "http://example.local",
|
||||
consoleLogger: logger.consoleLogger,
|
||||
hashAPIPath: () => "&hash=abc123"
|
||||
});
|
||||
|
||||
const result = await document.getRepsFromBlob("container-1");
|
||||
|
||||
assert.deepStrictEqual(normalize(result), {
|
||||
value: ["representation"]
|
||||
});
|
||||
assert.strictEqual(axios.calls.length, 1);
|
||||
assert.strictEqual(axios.calls[0].config, undefined);
|
||||
assert.strictEqual(logger.calls.length, 0);
|
||||
});
|
||||
|
||||
test("portal/deleteWatchedCases uses signer hash and returns data", async () => {
|
||||
const axios = createAxiosMock();
|
||||
const logger = createLoggerMock();
|
||||
|
||||
Reference in New Issue
Block a user