added CSRF trusted origin config, added tzdata - needed in debug mode #22

Merged
mhu merged 2 commits from sst/some-weird-stuff-with-docker into develop 2024-11-21 00:50:08 +01:00
Collaborator
No description provided.
sst added 1 commit 2024-11-19 23:10:10 +01:00
mhu requested changes 2024-11-19 23:17:51 +01:00
Dismissed
@ -56,6 +56,7 @@ if get_env_value('DJANGO_FORCE_DEV_MODE', default=False) == 'True':
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', get_env_value('DJANGO_ALLOWED_HOST')]
CSRF_TRUSTED_ORIGINS =['https://' + get_env_value('DJANGO_ALLOWED_HOST')]
Owner

This seems very unsafe!

This seems very unsafe!
mhu marked this conversation as resolved
sst added 1 commit 2024-11-19 23:35:18 +01:00
Owner
Warning

Modifying this setting can compromise your site’s security. Ensure you fully understand your setup before changing it.

Make sure ALL of the following are true before setting this (assuming the values from the example above):

1. Your Django app is behind a proxy.
2. Your proxy strips the X-Forwarded-Proto header from all incoming requests, even when it contains a comma-separated list of protocols. In other words, if end users include that header in their requests, the proxy will discard it.
3. Your proxy sets the X-Forwarded-Proto header and sends it to Django, but only for requests that originally come in via HTTPS.

If any of those are not true, you should keep this setting set to None and find another way of determining HTTPS, perhaps via custom middleware.

I'm still processing that 😄 So I will probably come back to this PR tomorrow when I had a nights sleep over that.

``` Warning Modifying this setting can compromise your site’s security. Ensure you fully understand your setup before changing it. Make sure ALL of the following are true before setting this (assuming the values from the example above): 1. Your Django app is behind a proxy. 2. Your proxy strips the X-Forwarded-Proto header from all incoming requests, even when it contains a comma-separated list of protocols. In other words, if end users include that header in their requests, the proxy will discard it. 3. Your proxy sets the X-Forwarded-Proto header and sends it to Django, but only for requests that originally come in via HTTPS. If any of those are not true, you should keep this setting set to None and find another way of determining HTTPS, perhaps via custom middleware. ``` I'm still processing that 😄 So I will probably come back to this PR tomorrow when I had a nights sleep over that.
mhu reviewed 2024-11-20 10:39:07 +01:00
@ -240,2 +239,4 @@
SECURE_SSL_REDIRECT = False
# allow detection of https behind "old" nginx
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
Owner

I don't get this. This should only be a problem, if django actually wants to check for HTTPS.
I don't need tha toption and everything looks fine.

Have you checked that Line #239 says SECURE_SSL_REDIRECT = False in your case as well when running?
If this is the case:

Can you have a look at your docker ps when running it from the docker compose setup and see if the container is "healthy"?
This health check uses a curl command to get a static HTTP OK response. This only works without https, because inside the container there is not https setup.

Can you also have a look at:
https://stackoverflow.com/questions/28001659/django-secure-proxy-ssl-header-requires-referer

This describes some other stuff and mentions a sort of redirect loop, I think you also experienced before, right?

I don't get this. This should only be a problem, if django actually wants to check for HTTPS. I don't need tha toption and everything looks fine. Have you checked that Line #239 says ` SECURE_SSL_REDIRECT = False` in your case as well when running? If this is the case: Can you have a look at your `docker ps` when running it from the docker compose setup and see if the container is "healthy"? This health check uses a curl command to get a static HTTP OK response. This only works without https, because inside the container there is not https setup. Can you also have a look at: https://stackoverflow.com/questions/28001659/django-secure-proxy-ssl-header-requires-referer This describes some other stuff and mentions a sort of redirect loop, I think you also experienced before, right?
Owner
https://medium.com/django-deployment/how-to-fix-djangos-https-redirects-in-nginx-63d304ddb19c Tossing that into the mix as well...
Owner

Okay, I think I found the root cause of the issue:

HttpRequest.is_secure(): Returns True if the request is secure; that is, if it was made with HTTPS.
Django isn’t magic here: it goes on a couple of clues as to what to answer there:
SECURE_PROXY_SSL_HEADER setting, if set.
For WSGI, the value of the "wsgi.url_scheme" environ key, otherwise.

So django either detects it from the WSGI or from the set header if the setting sis set.
I guess our container IPs are differntly random bricking that?!

I will do some further tests on my side and look, what the formwarded protocol looks like.

Okay, I think I found the root cause of the issue: > HttpRequest.is_secure(): Returns True if the request is secure; that is, if it was made with HTTPS. > Django isn’t magic here: it goes on a couple of clues as to what to answer there: > SECURE_PROXY_SSL_HEADER setting, if set. > For WSGI, the value of the "wsgi.url_scheme" environ key, otherwise. So django either detects it from the WSGI or from the set header if the setting sis set. I guess our container IPs are differntly random bricking that?! I will do some further tests on my side and look, what the formwarded protocol looks like.
mhu approved these changes 2024-11-21 00:49:34 +01:00
Owner

As I was finally able to reproduce all that stuff, it's okay.

As I was finally able to reproduce all that stuff, it's okay.
mhu merged commit b873b1fd0f into develop 2024-11-21 00:50:08 +01:00
mhu deleted branch sst/some-weird-stuff-with-docker 2024-11-21 00:50:08 +01:00
Sign in to join this conversation.
No reviewers
mhu
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mhu/shimatta-kenkyusho#22
No description provided.