Managed Edge Functions: which client-IP header is guaranteed safe for rate limiting? #52040
Replies: 3 comments 1 reply
|
I'd be cautious about treating the last valid IP in Parsing a valid IP address and proving that it was inserted by a trusted proxy are two different things. Until Supabase confirms which headers are sanitized or overwritten across managed and custom domains, I'd avoid using client-supplied forwarding headers as a security-sensitive identity on their own. For authenticated endpoints, rate limiting by verified user identity can provide an additional control, although it doesn't replace IP-based abuse protection. The important detail to get from maintainers is the exact trusted-proxy contract, including duplicate headers and any routes that bypass the usual gateway. I don't think an isolated successful test would establish that guarantee across every hosted routing configuration. |
|
Here is the authoritative technical breakdown of the proxy chain and client IP extraction contract for hosted Supabase Edge Functions: 1. The Short Answer: Which Header is Authoritative?
const clientIp = req.headers.get('cf-connecting-ip') ||
req.headers.get('x-real-ip')2. Why Your Current Approach (Last IP in
|
|
Not a maintainer, so I can't give you the contract. But one thing in the snippet above is worth changing whatever the answer turns out to be: req.headers.get('cf-connecting-ip') || req.headers.get('x-real-ip')If the first header is ever missing, this falls through to a header you haven't shown to be trusted. For a security control, a missing or invalid value should fail closed: a shared "unknown" bucket with a strict limit, or a reject. import { isIP } from 'node:net'
const raw = req.headers.get('cf-connecting-ip') ?? ''
const ipKey = isIP(raw) ? `ip:${raw}` : 'ip:unknown'
// authenticated routes: limit on the verified user id first
const key = userId ? `user:${userId}` : ipKeyTwo other notes:
For signed-in traffic, the user id from a verified JWT is a better rate-limit key than any IP header. |
Uh oh!
There was an error while loading. Please reload this page.
For hosted Supabase Edge Functions, what is the authoritative client-IP extraction contract? An application currently selects the last valid IP in X-Forwarded-For, falling back to CF-Connecting-IP and X-Real-IP.
Is caller-supplied X-Forwarded-For stripped or overwritten, or is an authoritative address always appended? Which element represents the actual client rather than an internal proxy? Can caller-controlled CF-Connecting-IP/X-Real-IP survive when X-Forwarded-For is missing or malformed? Please cover duplicate header fields, default/custom function domains and bypass routes, and link current managed-service documentation.
This is a request to verify an application assumption, not a claim of a confirmed Supabase vulnerability. No production probes have been run. An official maintainer clarification is needed; an unverified community suggestion or one successful sample cannot close the trust question.
All reactions