-
-
Notifications
You must be signed in to change notification settings - Fork 337
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
apiconsole: allow uploads in console #1126
Conversation
d595eb3
to
9876c7f
Compare
By adding an XHR to "Try it out" requests, we can make non-JSON requests pass a CORS check.
9876c7f
to
7760fe5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading the note at
grist-core/app/server/lib/Authorizer.ts
Lines 229 to 237 in a9521a8
// If we haven't already been authenticated, and this is not a GET/HEAD/OPTIONS, then | |
// require a header that would trigger a CORS pre-flight request, either: | |
// - X-Requested-With: XMLHttpRequest | |
// - https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#use-of-custom-request-headers | |
// - https://markitzeroday.com/x-requested-with/cors/2017/06/29/csrf-mitigation-for-ajax-requests.html | |
// - Content-Type: application/json | |
// - https://www.directdefense.com/csrf-in-the-age-of-json/ | |
// This is trivial for legitimate web clients to do, and an obstacle to | |
// nefarious ones. |
// that they pass a same origin request, even if they're not GET, | ||
// HEAD, or OPTIONS. "Try it out" requests are the requests to the | ||
// same origin. | ||
if (url.origin === window.origin) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be sure to verify this works once it reaches staging or prod, since there it's common, I think, to have the window on a URL like https://<org-subdomain>.getgrist.com/apiconsole
and the request going to https://api.getgrist.com/...
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ this is a good point. I just double-checked in prod, and the api console sends requests to the same domain.
By adding an XHR to "Try it out" requests, we can make non-JSON requests pass a CORS check.