fix: parse comma-separated X-Forwarded-Proto in Scheme#3055
Conversation
Proxies may send multi-value X-Forwarded-Proto (e.g. "https, http"). The whole string failed isValidProto, so Scheme fell through incorrectly. Use the left-most valid token for X-Forwarded-Proto/Protocol and X-Url-Scheme.
|
in which case that header has comma separated values? When I read https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-Proto it only seems to refer single value |
|
Agreed that MDN describes a single token. Multi-value
If you’d rather not support the multi-value case, I can close this and leave |
1305e35 to
4f38bea
Compare
|
after asking this from LLM it seems that there are few things that do that. but when we start to choosing one from list - which one to trust? When proxies append these values - which proxy in that chain was fist to be trusted and which ones before that are/can be probably spoofed? @sonnemusk are you having actual problem in production - is there Proxy application that causes this problem? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3055 +/- ##
=======================================
Coverage 93.34% 93.35%
=======================================
Files 43 43
Lines 4735 4741 +6
=======================================
+ Hits 4420 4426 +6
Misses 192 192
Partials 123 123 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
No production issue — I was just being defensive about multi-value headers. On the trust question: you're right that picking left vs right isn't well-defined without knowing the proxy chain, so baking a choice into Scheme() is the wrong place. Closing this. Happy to revisit if someone hits a concrete proxy that appends and needs documented behavior. |
Summary
Context.Scheme()treated the entireX-Forwarded-Protoheader as one token. Multi-proxy values likehttps, httpfailed validation and were ignored.Change
firstValidPrototo take the left-most valid scheme token.X-Forwarded-Proto,X-Forwarded-Protocol, andX-Url-Scheme.Test plan
go test . -run TestContext_Scheme