-
Notifications
You must be signed in to change notification settings - Fork 61
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
POST request from mobile app never allowed #519
Comments
Yeah I tend to agree here. The preflight request and validation is a browser concern so I suspect there should be some way to make a straight POST without a 'fake' origin. |
Guys, maybe this just isn’t a priority? Maybe noone will ever build an app as a website companion using SilverStripe GraphQL, except for me? I know I can just override the GraphQL controller, and I’ll probably have to, but I’m kind of curious as to the why 😉 |
Had a glance. I suspect we would just need to remove these lines silverstripe-graphql/src/Controller.php Lines 234 to 236 in 6b4c9a2
And maybe tweak this line in silverstripe-graphql/src/Controller.php Line 197 in 6b4c9a2
Given that I don't quite know what I'm doing and that this touches some key security feature, I'm not quite ready to just jump in there and make the change. But I would be keen to support this use case. |
I’m not sure why we check CORS server side at all, isn’t the point of CORS that it’s a set of headers for the browser to check? I.e. it protects the site making the requests, not the site receiving them. The |
I would probably agree that the server doesn't need to check CORS headers. The server sends them, as instructed by the dev via config, to tell the browser what origins it can load content for your site/app. So I would say keep adding them as per the configuration (if not null), but we probably don't need to be checking for them back, or make that particular check configurable. If we receive a legitimate request that the server can handle based on its config and it goes to graphql, it should respond to it. |
Can we assume that, if there is no Origin header (nor other cors headers) in the request, then it isn't a browser cors request? In which case there is no need anyway to add cors headers to the response? |
Adding headers to the response is not an issue here, right? |
No, not if the issue is getting the request through, sure! It’s me wondering about the logic behind it and how it might be reflected in code… |
Proposed fix: #527 |
Nice! Thanks |
Closed by accident. The problem is still there |
ISSUE:
I'm building a mobile Flutter app that uses Silverstripe GraphQL to pull data via a POST request. Once I enable CORS, the request from the app will always fail because the app doesn't send an Origin header.
Please note that the app doesn't send a preflight check, as it isn't a browser, just a plain POST request. But the Silverstripe GraphQL Controller seems to handle a POST request in a similar manner to a preflight check, by calling the addCorsHeaders() function for it, requiring an Origin.
So the only way to to get through is manually adding an Origin Header to the POST, but afaik this is not according to the rules, and could even be considered a spoofing attempt, if a take the app to the app store...
https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
As far as I understand it by now, CORS is purely a browser thing, and handled in preflight. So I think restricting the actual POST request might maybe be handled separately, but at least the Origin thing can hopefully be tackled...
Thanks, Martine
Acceptance criteria
PRs
The text was updated successfully, but these errors were encountered: