-
Originally posted by @mrobst in #1309 (comment) |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
I cleared cookies and logged in. New cookie is set ok. No error. Then navigated to the first collection and I get a 401 error from /api/_preferences/categories-list with this log |
Beta Was this translation helpful? Give feedback.
-
Working through the issue now. Its all working with postman using the jwt from the (failing) browser session as a bearer token. The request that is failing in the browser is using |
Beta Was this translation helpful? Give feedback.
-
The issue is resolved by adding the csrf option to my buildConfig. I'm not sure yet a) how it worked at all after initial deployment, b) why it stopped working or c) why I need to add the (sub) domain for the admin page to the build options csrf. Thinking about it though I'm using https://admin.mysite.com/admin for the URL and I think Payload expects to see https://mysite.com/admin so this is probably the explanation? (Context I'm hosting payload on DO and the front end site on a different provider so using the subdomain to handle the separate DNS). Please let me know if I've resolved this the right way. Is there something in the documentation that I missed related to this? I don't mind contributing to update the docs if needed. thanks |
Beta Was this translation helpful? Give feedback.
-
Hey @mrobst — good catch RE: CSRF. I think it's pretty tricky to properly diagnose a cookie being rejected due to CSRF reasons. Basically, if you have a serverURL defined, Payload will only allow a cross-origin cookie from that This is obviously done for protection but it can be tough to expect.
Did you maybe add a Regarding updating the docs, we do have lots of info about our CSRF prevention in the docs including a warning that says:
If you want to make it more clear or add context, I would be pumped. But personally I think the issue is more or less in the logging / reporting of why a cookie is rejected, when it is rejected. We could add a log to our JWT strategy that reports when an auth cookie is rejected due to CSRF. What are your thoughts? PS - I'm gonna bump this to a discussion now that you've solved the issue so we can keep conversation going there. Maybe turn it into a feature request once we decide what to do to clarify this 👍 |
Beta Was this translation helpful? Give feedback.
-
Seeing 401 Unauthorized error on POST request . Works locally, but fails in dev environment despite being logged in. |
Beta Was this translation helpful? Give feedback.
Hey @mrobst — good catch RE: CSRF.
I think it's pretty tricky to properly diagnose a cookie being rejected due to CSRF reasons. Basically, if you have a serverURL defined, Payload will only allow a cross-origin cookie from that
serverURL
unless you explicitly define other domains that are safe.This is obviously done for protection but it can be tough to expect.
Did you maybe add a
serverURL
at some point to your production instance? That would explain why it maybe started happening.Regarding updating the doc…