fix(auth): trust forwarded headers only from trusted proxies - #4715
Open
rain02333z-spec wants to merge 2 commits into
Open
fix(auth): trust forwarded headers only from trusted proxies#4715rain02333z-spec wants to merge 2 commits into
rain02333z-spec wants to merge 2 commits into
Conversation
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.
Why
csrf_middleware.pytrustedForwarded/X-Forwarded-*on direct requests, so a client could spoof the browser-facing scheme/origin used by auth same-origin checks and OIDC fallbackredirect_uriconstruction.What changed
Forwarded/X-Forwarded-*are only honored when the TCP peer matchesAUTH_TRUSTED_PROXIES.Host.redirect_uricontinues to use the shared origin resolver.Surface area
frontend/backend/applanggraph.json, or prompt changedocker/or sandboxed executionskills/backend/pyproject.tomlorfrontend/package.json(say what it buys us)Screenshots / Recording
N/A - backend security hardening only.
Bug fix verification
backend/tests/test_csrf_middleware.py::test_auth_post_rejects_spoofed_forwarded_same_origin_without_trusted_proxybackend/tests/test_oidc_auth.py::test_oidc_redirect_uri_fallback_ignores_forwarded_headers_from_untrusted_peermainand green on this branch? Not run onmainlocally; the regression tests encode the previous unconditional forwarded-header trust path and are green on this branch.Validation
cd backend && uv run pytest tests/test_csrf_middleware.py tests/test_oidc_auth.py tests/test_auth_type_system.py -qwithTEMP/TMP/TMPDIRpointed atbackend/.tmp:105 passed.cd backend && uv run ruff format --check app/gateway/csrf_middleware.py tests/test_csrf_middleware.py tests/test_oidc_auth.py tests/test_auth_type_system.py && uv run ruff check app/gateway/csrf_middleware.py tests/test_csrf_middleware.py tests/test_oidc_auth.py tests/test_auth_type_system.py: passed.cd backend && uv run pytest tests -k "auth or csrf or oidc" -qhit unrelated environment/platform failures in Lark/WeChat auth tests (lark-cliexit/path separator and Windows chmod mode assertions):674 passed, 5 skipped, 7 failed, 10475 deselected.AI assistance
Tool(s) used: Codex
How you used it: Implemented the trusted-proxy guard, added regression tests/docs, ran focused backend validation, and opened this PR from the requested plan.