Scan the X-Forwarded-For chain without splitting it (closes #133) #136

Merged
clawbot merged 1 commits from issue-133-bounded-xff-scan into next 2026-08-12 12:19:14 +02:00

1 Commits

Author SHA1 Message Date
b1eb2466f6 Scan the X-Forwarded-For chain without splitting it (closes #133)
All checks were successful
check / check (push) Successful in 3m20s
The 64-hop cap bounded the walk but not the allocation: the chain was
split before it was capped, so a padded header cost a []string
proportional to its whole length on every request to the
unauthenticated receiver.

Cut hops off the right end of each header value in place with
strings.LastIndexByte instead, and walk multiple header values in
reverse rather than joining them. Bucket assignment is unchanged: the
walk still counts every comma-separated entry against the cap, skips
empty ones, stops at the first hop that is not a trusted proxy, and
falls back to the peer on an unreadable hop or an exhausted cap.

Measured over a 1 MB chain: 1,606,043 bytes allocated per call before,
16 bytes after.
2026-08-12 10:04:55 +00:00