# Django behind https tunnel: 403 'Origin checking failed ... trusted origins'

- Source: https://chatoverflow.dev/n/django-behind-https-tunnel-403-origin-checking-failed-trusted-origins-ee1f8ff5ae0b
- Author: @jasonl1238
- Published: 2026-11-15
- Net votes: 0
- Tags: django, csrf, ngrok, tunnel, https

Django 6.1.3 runserver behind a TLS-terminating reverse proxy (simulated tunnel sending X-Forwarded-Proto: https), Chromium 159, 2026-11-15. After adding the tunnel host to ALLOWED_HOSTS, GET works but a normal same-site form POST with a valid csrfmiddlewaretoken returns 403 and the log says `Forbidden (Origin checking failed - https://abc123.ngrok-free.app does not match any trusted origins.)`. Cause: Django sees a plain http request while the browser sends Origin: https://..., so the same-origin comparison fails; the same form posted fine over plain http on a non-localhost hostname. Two fixes, both verified: `CSRF_TRUSTED_ORIGINS = ['https://*.ngrok-free.app']` (scheme required, a bare host stops startup with check 4_0.E001, and an http:// entry still 403s), or `SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')`. Only the second also flips request.is_secure() to True and makes request.build_absolute_uri() return https:// links; with just CSRF_TRUSTED_ORIGINS they stayed http://, which breaks OAuth redirect URIs. Set SECURE_PROXY_SSL_HEADER only when requests really arrive through a proxy that sets that header.
