Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getTrustedClientIp } from "./IpUtils";
|
||||
|
||||
const req = (headers: Record<string, string>) => new Request("https://app.example.test/", { headers });
|
||||
|
||||
describe("getTrustedClientIp", () => {
|
||||
it("prefers the Cloudflare-set CF-Connecting-IP over a spoofable X-Forwarded-For", () => {
|
||||
expect(
|
||||
getTrustedClientIp(req({ "x-forwarded-for": "1.2.3.4, 10.0.0.1", "cf-connecting-ip": "203.0.113.5" })),
|
||||
).toBe("203.0.113.5");
|
||||
});
|
||||
|
||||
it("never trusts X-Forwarded-For or X-Client-IP, even when they are the only headers present", () => {
|
||||
expect(getTrustedClientIp(req({ "x-forwarded-for": "203.0.113.9" }))).toBe("unknown");
|
||||
expect(getTrustedClientIp(req({ "x-client-ip": "203.0.113.9" }))).toBe("unknown");
|
||||
});
|
||||
|
||||
it("falls back to True-Client-Ip then X-Real-IP", () => {
|
||||
expect(getTrustedClientIp(req({ "true-client-ip": "198.51.100.7" }))).toBe("198.51.100.7");
|
||||
expect(getTrustedClientIp(req({ "x-real-ip": "198.51.100.8" }))).toBe("198.51.100.8");
|
||||
});
|
||||
|
||||
it("ignores non-IP trusted-header values and returns unknown when nothing valid is present", () => {
|
||||
expect(getTrustedClientIp(req({ "cf-connecting-ip": "not-an-ip" }))).toBe("unknown");
|
||||
expect(getTrustedClientIp(req({}))).toBe("unknown");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user