-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add Apollo-Require-Preflight
to Apollo client header
#8258
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9d56827:
|
Reading https://www.apollographql.com/docs/apollo-server/security/cors/#preventing-cross-site-request-forgery-csrf (thanks @megafinz, #7925) - I think this is OK as-is.
Unfortunate that we are adding this to every request, but, it's an easy solution with no other side-effects.
The CSRF prevention feature for Apollo 3 has been configurable by users since the dependency was updated in #6409. I don't think we need to issue another CVE as the Apollo advisory GHSA-2p3c-p3qw-69r4 and documentation is appropriate. |
Inline with my comment #8258 (comment), I have removed the changeset, relying only on the Upgrade Apollo 4 changeset. If users upgrade, and they use uploads on their frontend, and they use COR's, they will need to work through this problem too. Maybe we can document that somewhere... |
Yup, that's me! 😅 I have this current code in cors, what should I do to make Apollo Server work again on my servers? cors: {
origin: "*",
credentials: true,
}, |
If you are using the apollo-upload-client in your frontend, you will need to pass headers: |
I'm afraid I don't understand: I just want the Apollo interface at |
For the Apollo interface at |
Sorry I wasn't clear enough about the problem. I think it may be not linked with file upload: we don't use file upload in particular. We can't access the page |
@DiesIrae using your browser, can you copy paste your problematic request headers for us to inspect? Please remove any sensitive information. |
Sure! Here are all the data of request/response: Request headers:
Response headers:
Response: {
"errors": [
{
"message": "This operation has been blocked as a potential Cross-Site Request Forgery (CSRF). Please either specify a 'content-type' header (with a type that is not one of application/x-www-form-urlencoded, multipart/form-data, text/plain) or provide a non-empty value for one of the following headers: x-apollo-operation-name, apollo-require-preflight\n",
"extensions": {
"code": "BAD_REQUEST",
"stacktrace": [
"BadRequestError: This operation has been blocked as a potential Cross-Site Request Forgery (CSRF). Please either specify a 'content-type' header (with a type that is not one of application/x-www-form-urlencoded, multipart/form-data, text/plain) or provide a non-empty value for one of the following headers: x-apollo-operation-name, apollo-require-preflight",
"",
" at new GraphQLErrorWithCode (/app/node_modules/@apollo/server/dist/cjs/internalErrorClasses.js:10:9)",
" at new BadRequestError (/app/node_modules/@apollo/server/dist/cjs/internalErrorClasses.js:84:9)",
" at preventCsrf (/app/node_modules/@apollo/server/dist/cjs/preventCsrf.js:35:11)",
" at ApolloServer.executeHTTPGraphQLRequest (/app/node_modules/@apollo/server/dist/cjs/ApolloServer.js:507:50)",
" at runMicrotasks (<anonymous>)",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)"
]
},
"kind": "BAD_REQUEST",
"stack": "BadRequestError: This operation has been blocked as a potential Cross-Site Request Forgery (CSRF). Please either specify a 'content-type' header (with a type that is not one of application/x-www-form-urlencoded, multipart/form-data, text/plain) or provide a non-empty value for one of the following headers: x-apollo-operation-name, apollo-require-preflight\n\n at new GraphQLErrorWithCode (/app/node_modules/@apollo/server/dist/cjs/internalErrorClasses.js:10:9)\n at new BadRequestError (/app/node_modules/@apollo/server/dist/cjs/internalErrorClasses.js:84:9)\n at preventCsrf (/app/node_modules/@apollo/server/dist/cjs/preventCsrf.js:35:11)\n at ApolloServer.executeHTTPGraphQLRequest (/app/node_modules/@apollo/server/dist/cjs/ApolloServer.js:507:50)\n at runMicrotasks (<anonymous>)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"
}
]
} |
@DiesIrae there is no |
not in the request, no. Neither in Chrome nor Firefox. Our Keystone is in a container and we use Cloudflare to point our domain to it, do you think the problem is in this direction? |
@DiesIrae I might ask you to open a GitHub discussion question so as not to misuse this pull request comments, but yes, I think you might be using the |
Fixes #7925
Also fixes image upload on main now Apollo 4 has CSRF protection enabled by default