Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -66,6 +66,34 @@ export function getClientIPAddress(requestOrHeaders: Request | Headers): string
return ipAddress ?? null;
}
/**
* Trusted client-IP headers, in order of preference. These are set by the
* edge/proxy and OVERWRITE any client-supplied value, so — unlike
* X-Forwarded-For's leftmost entry or X-Client-IP — they cannot be spoofed by
* the client. In this estate every public request passes through Cloudflare
* (proxied), which sets CF-Connecting-IP. X-Real-IP is the immediate reverse
* proxy (Traefik) hop as a fallback for non-Cloudflare paths.
*/
const trustedHeaderNames = Object.freeze(["CF-Connecting-IP", "True-Client-Ip", "X-Real-IP"] as const);
/**
* Get the client IP from a TRUSTED, proxy-set header only. Use this for
* security-sensitive decisions (rate limiting, abuse throttles) where an
* attacker must not be able to rotate their apparent IP by forging
* X-Forwarded-For. Returns "unknown" when no trusted header is present (e.g.
* local development without a proxy) so callers can still key a shared bucket.
*/
export function getTrustedClientIp(requestOrHeaders: Request | Headers): string {
const headers = requestOrHeaders instanceof Request ? requestOrHeaders.headers : requestOrHeaders;
for (const headerName of trustedHeaderNames) {
const value = headers.get(headerName)?.trim();
if (value && isIP(value)) {
return value;
}
}
return "unknown";
}
function parseForwardedHeader(value: string | null): string | null {
if (!value) return null;
for (let part of value.split(";")) {