You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello Svelte community!
I may have found a corner case, which I'm not sure deserves a fix. Hence why I need your help.
Form actions comes with a built-in CSRF protection, which compares requests current and expected origins. url.origin is set in a middleware for vote, from the incoming host and scheme
While this works fine with Http1.1, it does not when using Http2. With the later, the host header is not included (:authority replaces it).
Http2 can be enabled by including @vitesjs/basic-plugin-ssl (which set https + http2) and running in preview mode. It can be reproduced with Svelte Kit basics test app:
cd packages/kit/tests/apps/basics
pnpm i -D @vitejs/plugin-basic-ssl
edit vite.config.js, add import basicSsl from '@vitejs/plugin-basic-ssl'; and plugins: [baseSsl(), sveltekit()],
run pnpm build && pnpm preview
run curl https://localhost:4173/csrf -d "key=value" -H "origin: https://localhost:4173" -ik
this will fail because base variable is https://undefined
This could be fixed here by replacing base when using http2:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello Svelte community!
I may have found a corner case, which I'm not sure deserves a fix. Hence why I need your help.
Form actions comes with a built-in CSRF protection, which compares requests current and expected origins.
url.originis set in a middleware for vote, from the incoming host and schemeWhile this works fine with Http1.1, it does not when using Http2. With the later, the
hostheader is not included (:authorityreplaces it).Http2 can be enabled by including @vitesjs/basic-plugin-ssl (which set https + http2) and running in preview mode. It can be reproduced with Svelte Kit basics test app:
cd packages/kit/tests/apps/basicspnpm i -D @vitejs/plugin-basic-sslimport basicSsl from '@vitejs/plugin-basic-ssl';andplugins: [baseSsl(), sveltekit()],pnpm build && pnpm previewcurl https://localhost:4173/csrf -d "key=value" -H "origin: https://localhost:4173" -ikThis could be fixed here by replacing
basewhen using http2:Now I am wondering if this really worth it.
If it is, I would need some guidance to write a test.
Beta Was this translation helpful? Give feedback.
All reactions