liip / django-template

Project template for Django projects
MIT License
17 stars 13 forks source link

Configure SECURE_PROXY_SSL_HEADER #124

Closed OdyX closed 1 year ago

OdyX commented 2 years ago

Without this, admin site login doesn't work locally.

simonbru commented 2 years ago

As I understand, this issue is caused by a mismatch of the Origin/ Referer header sent by the browser (httpS://myproject.docker.test), and what Django thinks should be the allowed origin for the current request (http://example-project.d.test, without TLS).

I think a better fix for this issue would be to set the following in dev.py, so that Django calculates the allowed origin correctly for requests coming from traefik:

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

This would fix other issues, such as request.build_absolute_uri() only building HTTP URLs in dev. By the way, we already applied this setting in some Django 3 projects for this reason.

@OdyX Does that makes sense for you too ?

OdyX commented 2 years ago

@simonbru makes total sense. Works locally too !