Skip to content

Django HTTPS urls are reported as HTTP url behind proxy (ECS + ALB) #5955

@ReneGreen27

Description

@ReneGreen27

How do you use Sentry?

Sentry Saas (sentry.io)

Version

v2.57.0

Steps to Reproduce

Deploy a Django application behind a reverse proxy / load balancer (e.g. AWS ALB) with SSL termination.

Ensure the load balancer sends the following header:

X-Forwarded-Proto: https

Configure Django with:

SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
USE_X_FORWARDED_HOST = True

Add a test endpoint to confirm how Django interprets the request:

def debug_headers(request):
    return JsonResponse({
        "X-Forwarded-Proto": request.META.get("HTTP_X_FORWARDED_PROTO"),
        "request.scheme": request.scheme,
    })

Verify that hitting this endpoint returns:

{
  "X-Forwarded-Proto": "https",
  "request.scheme": "https"
}

Enable Sentry in the Django app with default request integration.
Trigger an error and inspect the event in Sentry.

Expected Result

Sentry reports the request URL as http://...

Actual Result

Sentry should report the request URL as https://..., since Django resolves the request scheme as HTTPS.

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions