Configurable CORS and site headers#15397
Conversation
|
Hi Brandon @brandonkelly, When I try to login from the Nuxt.js application using Is there a way to handle the "preflight request"? Best |
|
@vettndr The <?php
return [
'as corsFilter' => [
'class' => \craft\filters\Cors::class,
'cors' => [
'Origin' => [
'https://my-nuxt-app.com',
],
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
'Access-Control-Request-Headers' => ['*'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Max-Age' => 86400,
'Access-Control-Expose-Headers' => [],
],
],
]; |
Hey @timkelty I tried as you suggested me.... and now I'm facing a I'm pretty sure the credentials I'm using are working in the backend when I try to access on it. Thanks in advance for your support. Best |
|
@vettndr your request is failing CSRF validation. You need to fetch a CSRF token first, then include it along with your request. |
@timkelty yes, I’m fetching the CSRF token when the app is loaded for the first time and then I’m including it in the POST request. I don’t know why it’s triggering that 400 exception. |
|
How are you making the request (fetch, axios, etc)? |
Hi @timkelty as you can see I'm setting the best |
|
What are the domains involved? Are they subdomains of the same root? I'm not seeing anything jump out from your example, so if you could, please email [email protected] with as much of the project as possible, specifically:
|
Hi @timkelty Anyway I did a little debugging process and I found that in the It seems like it's comparing the token I passed in the header with another one. I would really appreciate to read your thoughts about it. Best |
|
Hi, any updates on this? To investigate, I added some debug output and noticed that when validateCsrfToken() is called, Craft runs loadCsrfToken(), but it doesn't generate the same token as expected. |
Hi @vnali Best cc @timkelty |
|
Thanks for the nudge, @vettndr. |
|
@timkelty @vettndr If I’m right, it might be worth mentioning this in the documentation here. @AugustMiller |
hey @vnali, |
|
@vettndr It's the same domain but a different subdomain. I can email you a link that you can check in your browser, if you'd like. |
thank you for your answer @vnali I can check internally to move the frontend under the same domain/subdomain to solve it. |
|
@vettndr Also, here's how it's configured in Craft: I'd also be interested to know if you've heard anything from the dev team about a possible solution. |
Description
allowedGraphqlOriginsin favor of using CORS filterpermissionsPolicyHeaderin favor of using headers filterExample config:
config/app.web.phpRelated issues