Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/outbound-fetch-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ function outboundHeaders(input: RequestInfo | URL, init: RequestInit | undefined
}

function outboundBodyPresent(input: RequestInfo | URL, init: RequestInit | undefined): boolean {
if (init && Object.prototype.hasOwnProperty.call(init, "body")) {
return init.body !== null && init.body !== undefined;
if (
init
&& Object.prototype.hasOwnProperty.call(init, "body")
&& init.body !== null
&& init.body !== undefined
) {
return true;
}
return input instanceof Request && input.body !== null;
}
Expand Down
33 changes: 33 additions & 0 deletions test/outbound-request-body-inheritance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it, vi } from "vitest";
import { createFailClosedFetch } from "../src/outbound-fetch-policy";

const discoveryUrl =
"https://token.actions.githubusercontent.com/.well-known/openid-configuration";

describe("outbound request body inheritance", () => {
it.each([
["null", null],
["undefined", undefined],
] as const)(
"rejects an inherited Request body when RequestInit.body is %s",
async (_label, bodyOverride) => {
const rawFetch = vi.fn(async () => new Response("unexpected", { status: 200 }));
const guardedFetch = createFailClosedFetch(rawFetch);
const bodyfulRequest = new Request(discoveryUrl, {
method: "POST",
body: "credential-bearing payload",
});

const response = await guardedFetch(bodyfulRequest, {
method: "GET",
body: bodyOverride,
});

expect(response.status).toBe(502);
expect(response.headers.get("x-noema-egress-policy")).toBe(
"blocked-request-policy",
);
expect(rawFetch).not.toHaveBeenCalled();
},
);
});
4 changes: 2 additions & 2 deletions test/outbound-request-compartment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("outbound credential request compartmentalization", () => {
},
);

it("derives the effective request from Request input plus RequestInit overrides", () => {
it("does not treat null RequestInit body as clearing an inherited Request body", () => {
const unsafeInput = new Request(discoveryUrl, {
method: "POST",
headers: { authorization: "Bearer sensitive" },
Expand All @@ -45,7 +45,7 @@ describe("outbound credential request compartmentalization", () => {
method: "GET",
headers: {},
body: null,
})).toBe(true);
})).toBe(false);
});

it("allows public bodyless GitHub GETs and only the two reviewed App-JWT operations", () => {
Expand Down
Loading