-
-
Notifications
You must be signed in to change notification settings - Fork 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
Block cross-site form POSTs by default #6510
Conversation
🦋 Changeset detectedLatest commit: 65508b0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I'm wondering whether we should only do this for POSTs, because those are the only ones that can be done with old-fashioned form submits. The other ones would already be blocked anyway, right, unless you specifically took action to deal with the preflight CORS stuff? And if there were a way to only do this check for old-fashioned form submits and not other cross-origin fetch requests, that also might be nice, but I don't know that that's something we can reliably determine. If this is something people are going to have to turn off before they can even start to do the legwork to allow CORS requests, that seems like it's inviting someone to then forget to close the form submit hole. |
Good point. Changed it to just |
Could we block it only if it's a POST and the Origin doesn't match and it has a form Content-Type? If someone wanted to expose a POST endpoint for legitimate use by other servers, they would likely write it to accept JSON, so that wouldn't get in their way. And I think it still provides the same amount of protection. |
Oh you know what? That should definitely work. D'oh |
Until ~6 years ago the following would've bypassed the current implementation in Chrome and Firefox: <script>
navigator.sendBeacon(
'http://localhost:5173/todos',
new Blob([JSON.stringify({ text: 'pwned' })], { type: 'application/json' })
);
</script> Spice in some
|
This broke my implementation of Auth0 as an openid-connect module (rough draft but working - starbasehq/sveltekit-openid-connect#11). In order to use the POST callback from Auth0 I have to set this option to false to disable CSRF checks. Would it be possible to whitelist certain domains/urls and still have the rest of the CSRF protection? |
Perhaps eventually. But for now, until we figure out what that API looks like, it should be pretty simple to disable that setting in the configuration and then re-create the adjusted check in your |
That solution works for now. Here is how I did it: top of hooks.js
Inside handle
function at bottom of hooks.js
|
Closes #72. Adds a
config.kit.csrf.checkOrigin
option that defaults totrue
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0