fix(api/auth): gate X-Forwarded-Proto on trusted_proxies for session cookie Secure flag#5581
Merged
Merged
Conversation
…cookie Secure flag `request_is_https` read `X-Forwarded-Proto` unconditionally, and `session_cookie_attrs` used that decision to attach `Secure` to the session cookie. The `trusted_proxies` config already existed (and is already consulted by `client_ip.rs` for the real-client-IP decision) but was not consulted here. Two consequences: 1. An attacker against a plain-HTTP bind could set `X-Forwarded-Proto: https` to force `Secure` on their own session cookie — low impact, but the operator should be in control of transport posture. 2. (Critical case) A naive nginx setup that does NOT forward `X-Forwarded-Proto` made real HTTPS sessions emit cookies WITHOUT `Secure`. A single accidental HTTP redirect on that host would leak the cookie on the wire — and the operator had no signal that it was missing. Fix: gate `X-Forwarded-Proto` interpretation behind the existing `trusted_proxies` allowlist, mirroring the pattern in `client_ip.rs`. Untrusted peers can no longer forge the header. The naive-nginx case now fails closed at deploy time — the operator notices the absent `Secure` flag while testing and fixes the proxy config, instead of discovering the gap post-leak. `dashboard_login` extracts the TCP peer via `ConnectInfo<SocketAddr>` (already wired by `into_make_service_with_connect_info` at the listener) and passes it through alongside the existing `AppState. trusted_proxies` allowlist. Refs `docs/issues/x-forwarded-proto-trusted-proxies.md`.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This was referenced May 23, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5580
Summary
request_is_httpsincrates/librefang-api/src/server.rspreviously readX-Forwarded-Protounconditionally.session_cookie_attrsused that decision to attachSecureto session cookies. Thetrusted_proxiesconfig existed (and was already consulted byclient_ip.rsfor the real-client-IP decision) but was not consulted here.Two failure modes closed:
X-Forwarded-Proto: https→ daemon forcesSecureon the cookie. Operator now controls when this is honored.Secure. A single accidental HTTP redirect could leak the cookie on the wire. Now fails-closed at deploy time — operator notices the missingSecureflag during testing.The gate mirrors
client_ip.rs:trusted_proxiesANDX-Forwarded-Proto: https→ honour.trusted_proxies→ ignore the header regardless.trusted_proxies→ never honourX-Forwarded-Proto.Multi-value
X-Forwarded-Proto: https, httpuses the leftmost value (origin scheme), matching the convention.Files changed
crates/librefang-api/src/server.rs(+137 / -19 — single file; pre-existing main drift NOT swept)Tests added (5 pass)
xfp_honored_when_peer_is_trustedxfp_ignored_when_peer_is_untrustedtrusted_peer_without_xfp_is_plain_httpempty_trusted_proxies_ignores_xfp_unconditionallyxfp_multi_value_uses_leftmost_when_peer_trustedVerification
cargo fmt -p librefang-api -- --check— clean (onlyserver.rs)cargo check -p librefang-api --lib— cleancargo test -p librefang-api --lib xfp_— 5 passedRefs
docs/issues/x-forwarded-proto-trusted-proxies.md.