Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure SECURE_PROXY_SSL_HEADER #124

Merged
merged 1 commit into from
Feb 14, 2023
Merged

Configure SECURE_PROXY_SSL_HEADER #124

merged 1 commit into from
Feb 14, 2023

Conversation

OdyX
Copy link
Member

@OdyX OdyX commented Aug 24, 2022

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

@OdyX OdyX added the bug label Aug 24, 2022
@OdyX OdyX requested a review from simonbru August 24, 2022 14:45
@OdyX OdyX self-assigned this Aug 24, 2022
@simonbru
Copy link
Contributor

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
Copy link
Member Author

OdyX commented Sep 21, 2022

@simonbru makes total sense. Works locally too !

@OdyX OdyX changed the title Configure CSRF_TRUSTED_ORIGINS for Django > 4 Configure SECURE_PROXY_SSL_HEADER Sep 21, 2022
@simonbru simonbru merged commit 45af0c6 into master Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants