Skip to content

Commit 12f5187

Browse files
committed
feat: add traefik ingress support to media-auth
1 parent 50b90f9 commit 12f5187

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/backend/core/api/viewsets.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1182,13 +1182,19 @@ def _auth_get_original_url(self, request):
11821182
to let this request go through (by returning a 200 code) or if we block it (by returning
11831183
a 403 error). Note that we return 403 errors without any further details for security
11841184
reasons.
1185+
1186+
Traefik and other ingresses that aren't nginx don't send HTTP_X_ORIGINAL_URL but all
1187+
should send the standard X-Forwarded-* headers, fallback to that when HTTP_X_ORIGINAL_URL
1188+
is not found.
11851189
"""
11861190
# Extract the original URL from the request header
11871191
original_url = request.META.get("HTTP_X_ORIGINAL_URL")
11881192
if not original_url:
1189-
logger.debug("Missing HTTP_X_ORIGINAL_URL header in subrequest")
1190-
raise drf.exceptions.PermissionDenied()
1191-
1193+
logger.debug( request.META )
1194+
if not request.META.get("HTTP_X_FORWARDED_URI"):
1195+
logger.debug("Missing HTTP_X_ORIGINAL_URL header and HTTP_X_FORWARDED_URI http header.")
1196+
raise drf.exceptions.PermissionDenied()
1197+
original_url = request.META.get("HTTP_X_FORWARDED_PROTO") + "://" + request.META.get("HTTP_X_FORWARDED_HOST") + request.META.get("HTTP_X_FORWARDED_URI")
11921198
logger.debug("Original url: '%s'", original_url)
11931199
return urlparse(original_url)
11941200

0 commit comments

Comments
 (0)