fix(gateway): trim trusted proxy entries before matching

This commit is contained in:
Rain
2026-02-16 21:28:24 +08:00
committed by Peter Steinberger
parent e24e465c00
commit d3698f4eb6
2 changed files with 15 additions and 3 deletions

View File

@@ -22,6 +22,10 @@ describe("isTrustedProxyAddress", () => {
true,
);
});
it("ignores surrounding whitespace in exact IP entries", () => {
expect(isTrustedProxyAddress("10.0.0.5", [" 10.0.0.5 "])).toBe(true);
});
});
describe("CIDR subnet matching", () => {
@@ -101,6 +105,10 @@ describe("isTrustedProxyAddress", () => {
expect(isTrustedProxyAddress("10.42.0.59", ["10.42.0.0/-1"])).toBe(false); // negative prefix
expect(isTrustedProxyAddress("10.42.0.59", ["invalid/24"])).toBe(false); // invalid IP
});
it("ignores surrounding whitespace in CIDR entries", () => {
expect(isTrustedProxyAddress("10.42.0.59", [" 10.42.0.0/24 "])).toBe(true);
});
});
});