Repository navigation
fix(oidc): gate public-origin forwarded headers behind TRUST_PROXY_HEADERS - #2289
Conversation
…ADERS getPublicOrigin() read x-forwarded-host and x-forwarded-proto directly, so TRUST_PROXY_HEADERS=false was ignored, a comma-separated forwarded host produced an invalid URL that crashed the OIDC routes with a 500, and a Host-only fallback was always rebranded https. Read the forwarded values only behind readTrustProxyHeaders(), take the first comma entry, accept only http/https, validate the authority before use, and fall back through the Host header to the request URL. Part of libredb#2270
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thanks, this is good and I will merge it shortly. I put main's oidc.ts under your tests: 14 of the 15 new cases fail there, and all 116 pass on your head. The trust gate, the host split, the proto allowlist and the '@' and '/' checks each fail a case when I remove them. One correction to the body: the IPv6 case also passes on the old helper, so it is a regression guard, not proof of the fix. There are two small test gaps, and neither holds the merge. First, the comma case sends "HTTPS , http". If I drop either the lowercasing or the proto split, it still returns https because of the forwarded-host default. Sending "HTTP , https" and expecting http://app.example:8443 would pin both. Second, if I drop '?', '#', '*' or the backslash check, all tests stay green, and URL parsing quietly turns good.example?x into https://good.example. One case each in the invalid-authority table would cover that. If you push these before I merge, great. Otherwise I will add them. #2270 stays open for the redirect allowlist. That part is our decision. |
|
FYI: @Maaz2212 |
The comma test now sends HTTP , https and expects the http origin, so it fails if either the lowercasing or the comma split is dropped. The invalid-authority table gains query, fragment, star and backslash hosts, which URL parsing would otherwise silently accept.
|
Both gaps are closed in 7926842. The comma case now sends "HTTP , https" and expects http://app.example:8443, so it fails if either the lowercasing or the proto split is dropped. The authority table gains one case each for '?', '#', '*' and the backslash. I verified each row by removing the matching guard from the helper and watching exactly one test fail, with everything restored afterwards. The file is 120/120 green. I also corrected the body: the IPv6 case is a regression guard, not proof of the fix. Thanks for running main's helper under the tests, and for the empty-field and numeric-name notes. |
Brief Description
getPublicOrigin()built the public origin for the auth flows by concatenatingx-forwarded-hostandx-forwarded-protowithout the trust gate the rest of the app applies to those headers (request-scheme.ts, origin-check.ts, client-address.ts), soTRUST_PROXY_HEADERS=falsewas ignored here, a comma-separatedX-Forwarded-Hostproduced an invalid URL that crashed the OIDC login and callback routes with a 500, and a Host-only fallback was always rebranded https even on a direct http deployment.The helper now reads forwarded headers only behind
readTrustProxyHeaders(), uses the first comma-separated entry, accepts only http/https protocols, validates the host as an authority before using it, and falls back through the Host header to the request URL. When no valid trusted forwarded protocol is available, a forwarded host keeps the https default and a Host fallback uses the request URL's scheme.Part of #2270. This gates the helper's direct forwarded-header reads and handles malformed origin inputs. It does not introduce a redirect allowlist, and trusted forwarded headers still require a proxy that overwrites client-supplied values.
How Did You Test
15 new parameterized cases in
tests/unit/lib/oidc.test.ts(env-snapshot pattern of request-scheme.test.ts): all fail on the previous helper with the reported symptoms and pass with the change; 116/116 in the file. Consumer suites green: oidc-login 17, oidc-callback 50, oidc-callback-access-review 16, logout 22, oidc-rancher 16. Security neighbors green: csrf-origin 25, cross-origin-headers 9, request-scheme 11, client-address 10, config 17. biome clean; tsc shows only the three pre-existing e2e-helper module errors, identical to main.Follow-up in 7926842: the comma case now sends "HTTP , https" so dropping either the lowercasing or the proto split fails it, the invalid-authority table gains one case each for '?', '#', '*' and the backslash, and each new row was verified by removing the matching guard and watching exactly one test fail. The IPv6 case also passes on the previous helper, so it is a regression guard rather than proof of the fix. The file is 120/120.