🐛(backend) accept configurable media-auth forward headers (Traefik X-Forwarded-Uri)#743
Open
mosa-riel wants to merge 1 commit into
Open
🐛(backend) accept configurable media-auth forward headers (Traefik X-Forwarded-Uri)#743mosa-riel wants to merge 1 commit into
mosa-riel wants to merge 1 commit into
Conversation
ItemViewSet._authorize_subrequest() only read HTTP_X_ORIGINAL_URL, an nginx-ingress convention. On clusters running Traefik (or any RFC-7239 style proxy), the equivalent header is X-Forwarded-Uri, so the lookup returned None and every /media/... request 403'd — uploads succeeded but downloads/previews never resolved. Read the original URL from the first present header in the new MEDIA_AUTH_FORWARD_HEADERS setting (default ["X-Original-Url", "X-Forwarded-Uri"]), tried in order. nginx-ingress users are unaffected since X-Original-Url stays first; other proxies can be supported by overriding the env var with no code change.
kernicPanel
self-requested a review
July 8, 2026 05:55
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.
Summary
ItemViewSet._authorize_subrequest()only readsHTTP_X_ORIGINAL_URL, an nginx-ingress convention. On clusters running Traefik (or any RFC-7239-style proxy) the equivalent header isX-Forwarded-Uri, so the lookup returnsNoneand every/media/...subrequest is denied with a 403 — uploads succeed but downloads/previews never resolve.This reads the original URL from the first present header in a new, configurable
MEDIA_AUTH_FORWARD_HEADERSsetting (default["X-Original-Url", "X-Forwarded-Uri"], tried in order). nginx-ingress deployments are unaffected becauseX-Original-Urlstays first; other proxies can be supported purely by overriding the env var, with no code change.Changes
core/api/viewsets.py— iterate the configured headers, convert each to itsMETAkey (HTTP_prefix, uppercased, dashes→underscores) and use the first one present.drive/settings.py— newMEDIA_AUTH_FORWARD_HEADERSlist setting (envMEDIA_AUTH_FORWARD_HEADERS), defaulting to["X-Original-Url", "X-Forwarded-Uri"].core/tests/items/test_api_items_media_auth.py— mirror tests exercisingX-Forwarded-Urifor the 200 (public) and 403 (authenticated/restricted) paths, plus a no-header 403 case.Test plan
test_api_items_media_auth.pysuite still green (X-Original-Urlpath unchanged).X-Forwarded-Uricases reach the same authorization decisions (200/403).GET /media/<key>returns 200 for an authorized user (previously 403).22 passedlocally (DJANGO_CONFIGURATION=Test pytest core/tests/items/test_api_items_media_auth.py).