fix(gateway): enforce trusted-proxy HTTP origin checks (#58229)

* fix(gateway): enforce trusted-proxy HTTP origin checks

* Update CHANGELOG.md
This commit is contained in:
Vincent Koc
2026-03-31 19:49:26 +09:00
committed by GitHub
parent 9abcfdadf5
commit 6b3f99a11f
9 changed files with 228 additions and 4 deletions

View File

@@ -5,6 +5,16 @@ vi.mock("./auth.js", () => ({
authorizeHttpGatewayConnect: vi.fn(),
}));
vi.mock("../config/config.js", () => ({
loadConfig: vi.fn(() => ({
gateway: {
controlUi: {
allowedOrigins: ["https://control.example.com"],
},
},
})),
}));
vi.mock("./http-common.js", () => ({
sendGatewayAuthFailure: vi.fn(),
}));
@@ -66,6 +76,39 @@ describe("authorizeGatewayHttpRequestOrReply", () => {
});
});
it("forwards browser-origin policy into HTTP auth", async () => {
vi.mocked(authorizeHttpGatewayConnect).mockResolvedValue({
ok: true,
method: "trusted-proxy",
user: "operator",
});
await authorizeGatewayHttpRequestOrReply({
req: createReq({
host: "gateway.example.com",
origin: "https://evil.example",
}),
res: {} as ServerResponse,
auth: {
mode: "trusted-proxy",
allowTailscale: false,
trustedProxy: { userHeader: "x-user" },
},
trustedProxies: ["127.0.0.1"],
});
expect(vi.mocked(authorizeHttpGatewayConnect)).toHaveBeenCalledWith(
expect.objectContaining({
browserOriginPolicy: {
requestHost: "gateway.example.com",
origin: "https://evil.example",
allowedOrigins: ["https://control.example.com"],
allowHostHeaderOriginFallback: false,
},
}),
);
});
it("replies with auth failure and returns null when auth fails", async () => {
const res = {} as ServerResponse;
vi.mocked(authorizeHttpGatewayConnect).mockResolvedValue({