-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
Missing CSRF_TRUSTED_ORIGINS parameter in Django settings.py #1203
Comments
Not sure if I should've opened this issue in the docker repo - touches both worlds imo. Link to Discord Thread: https://discord.com/channels/754275926921052230/1051985104345497731 |
I'm thinking what the default should be, does |
Research tells me This thread discusses the same issue: maybe adding adding the mentioned lines to both DJANGO and the NGINX part (the one that is included here) might help. This example is for https, would need to understand how to do the same for http. If I get to it I will update the thread if it works. That being said: adding the CSRF as a mandatory env variable would be the quickest fix from my pov, at least for the docker case (as I haven't tested native). |
I played around for a bit but was unable to make it work without the CSRF setting. But I must say I am in no way very versed in dealing with NGINX und proxy settings. I can only point at my original proposition. As a default, it could be commented out so it doesn't interfere with setups that do not require it. |
thanks for looking into this. Having 127.0.0.1 in the default list won't hurt anyway, then users just have to add the domain they are using |
With my post in mind wger-project/docker#43 in mind, is there anything I can do to help ? |
Once the docker images are built, it will be possible to set the trusted origins with env variables, doing something like If this works I'll update the defaullt env file in the docker repo |
Validated the change, working flawlessly for me. Thanks a bunch @rolandgeider! |
Great! I still think this can be solved with some clever headers, will open a new issue for that |
Feel free to hit me up in Discord if you want some testing done with my setup :-) |
Hi, thanks all, As I don’t have a domain name set up/assigned (running local on a QNAP NAS), would it just be the following env variable for me?
|
Depends on what URL/IP you use to call it. Just try and you'll see :-) |
Hi @TheFitzZZ, sorry for perhaps an obvious question, but does that mean all source devices will have to be listed, so if i want to access wger from my phone, pad, pc, all will need a fixed IP and be listed as trusted here ? |
@nodecentral nono, it's the address you use to open it from these devices, ergo what you put into your browser. If you use an IP, put the IP. If you have a domain name, put that :-) |
Hi, picking this issue up again, as I’m still unable to get past the As @TheFitzZZ suggested, I entered the IP address that’s used when I try to connect to Wger via the This is the address of my QNAP NAS, where docker and the wger container(s) sit..
Any ideas/suggestions ? |
If I recall correctly, I had to enable Django debug and then look at the log as it states which origin was untrusted, e.g. |
@nodecentral I'm also not sure if this is needed without HTTPS, but setting debug to true and seeing where django complains is a good idea |
Hi @rolandgeider - is this what you are after..
Also not sure if it is related, but I can access Wger via either
The first url (IP/Port) returns a basic html only version of wger, but I can’t login to that (wger-project/docker#45) |
so setting |
That did it, seems it needed the port specifically defined.. One observation though, it did not recognise my username/password so I had to re-register…?? QQ: Why are there two ports made available to access Wger, yet only the |
Oh no, i spoke too soon. Tried to log in again from a different device, and get the following error..
|
Hi, I can see there’s been a few updates to the wger docker images since my last post (above) .. Are we any closer to the resolving the CSRF issue ? I only ask as I’ve been unable to use Wger for over a month now.. :-( To confirm, I have the following defined as an environment variable.
Yet upon logging on to Wger, i still get the following 403 errror when accessing
|
hey! There's been a bit of cleanup and so, but nothing substantial. There is also not much else we can do about the csrf stuff, whitelisting the origins is basically the only thing we can do from django's side. I also can't understand why it's not working for you :(( |
Thanks @rolandgeider Picking up on what you said about..
How can I be sure I’m not missing anything when it comes to the white listing? Is there anything that I can check, (it would be great to be presented in the error message) that tells me the exact details for me to whitelist? |
I think there is also an error in the logs that show the origin that is making problems. And just to make sure, you can run this command to check that the correct origins are actually the ones we want: |
Hi @rolandgeider , if i run that command, (result below) other than the addition of the square brackets, it returns the same info as i have in the environment variable.. ? Should I mirror exactly what it returned below in the docker compose ?
|
No the brackets are correct (the settings file reads the env variable set by docker and converts the values it to a python list). Honestly I have no idea what else we could try. In theory this is just a really simple setting that just allows the origin and everything works after that |
The only thing left that i can see as potentially related is the nginx.conf, does that relate in any way to the CSRF_TRUSTED_ORIGIN value ? The IP and port used is not reflected here in mine below ?
|
no that config is only used internally, it doesn't care about the external IP or domain |
Since Django 4 it is necessary to define trusted origins to prevent 403/CSRF errors.
Steps to repo:
Proposed solution:
Add
CSRF_TRUSTED_ORIGINS = ['https://*.mydomain.com','https://*.127.0.0.1']
in settings.py and make it configurable via environment variable.Tested on my end and works fine.
Source for solution:
https://stackoverflow.com/questions/70285834/forbidden-403-csrf-verification-failed-request-aborted-reason-given-for-fail
The text was updated successfully, but these errors were encountered: