-
Notifications
You must be signed in to change notification settings - Fork 37
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
"Cross-site POST form submissions are forbidden" #54
Comments
Hello, I'm having the exact same issue. My configuration is very similar to yours and is also using Docker. I tried a lot of things, but only switching to the Node adapter worked. This is what I pretty much always end up doing because of a few incompatibilities that this adapter seems to have. Here my Dockerfile if needed, I kept my original configuration but added Node with |
This is how I'm getting around the issue at the moment. I don't like doing this, but it's about the only wait that doesn't involve throwing yet another server in front of the app that fixes this. My svlete.config.js import adapter from 'svelte-adapter-bun';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
csrf: { // Did https://github.com/gornostay25/svelte-adapter-bun/pull/61 work? (I can't wait to find out)
checkOrigin: false
}
}
};
export default config; The server option would be to use something like this in front of your app with something like this: // @bun
import { build_options, env, handler_default } from './build/handler.js';
import './build/mime.conf.js';
var { serve } = globalThis.Bun;
/*! MIT © Volodymyr Palamar https://github.com/gornostay25/svelte-adapter-bun */
var hostname = env('HOST', '0.0.0.0');
var port = parseInt(env('PORT', 3000));
var { httpserver, websocket } = handler_default(build_options.assets ?? true);
var serverOptions = {
baseURI: env('ORIGIN', undefined),
fetch: httpserver,
hostname,
port,
development: env('SERVERDEV', build_options.development ?? false),
websocket
};
websocket && (serverOptions.websocket = websocket);
console.info(`Listening on ${hostname + ':' + port}` + (websocket ? ' (Websocket)' : ''));
serve(serverOptions); Instead of running your app directly, you'd |
bump this issue still persists, might be related or fixable py this pr: #61 |
Please fix this issue, it's still blocking our production release. |
Just reminding everyone here that origin checking is an insufficient CSRF protection measure. It's harmful by creating a false sense of security. Origin can be spoofed, so checking it only provides partial protection, but doesn't protect against sophisticated attacks. Feel free to set Edit: since #61 is merged, disabling origin checking may be not necessary anymore, but it's still an insufficient security measure, and CSRF token is still required. Edit again: I was wrong about the necessity of CSRF tokens, see my below comment #54 (comment) |
@notramo Thank you so much for this comment. |
I'm still getting this error with the latest version of the adapter in my SvelteKit action. It works with the node adapter |
I have the same issue, currently not smart enough to fix this with a pr 😓 Has #61 fixed this issue? I see its merged, But if so can a new release be build? |
Can confirm that issue still persists and @maietta's workaround ( I'm using:
|
Just to be clear, this, turning off CRSF origin checking is a bad idea and can lead to bigger issues. I would recommend the server wrapper instead until the underlying issue has been resolved. |
Setting both PROTOCOL_HEADER=x-forwarded-proto and HOST_HEADER=x-forwarded-host env vars is what fixed it for me |
@YpsilonTM You can use it this way in your package.json: The problem is that this doesn't fix it. I traced the error back to build/handler.js:677 where the request already comes as HTTP and right there could be changed to HTTPS as in merge #61. The thing is, while the merge included the neccessary changes for handler.js, when building the project, there's still the old version in the build folder. It contains the improved version somewhere nested but doesn't use it. |
Turns out I was wrong. Origin can not be spoofed if the scheme ( Origin checking is a modern and good protection (again, only if it checks the entire Origin with scheme and port, not only the domain). Cookie attributes and name prefixes
I also recommend setting the
Note that Google Chrome does not treat
|
My setup is a bit more complex but I observed something so maybe it can help solve this issue. I'm deploying behind Traefik to a subdomain + path (e.g. https://subdomain.example.com/project). On the /project route there is a login SvelteKit action. This is where the CSRF issue arises. I'm also using paraglide for i18n which runs in a hook or rather sequence of hooks Couldn't fix it with adapter-bun - neither ORIGIN, nor PROTOCOL_HEADER + HOST_HEADER (and optionally PORT_HEADER=x-forwarded-port) worked. I see in the client request that origin (lowercase) is set correctly, but none of the other headers exist. Switched back to adapter-node and it works out of the box now (I'm not even setting ORIGIN). Now I see following x-headers when logging the reguest in the action (=server-side) using adapter-node:
What is it with |
Just encountered this error while testing my website in production.
Setup:
I'm using docker with nginx proxy manager as a reverse proxy.
So i was building my multi-container through this docker-compose.yml
With my web Dockerfile looking like this:
I know that the ORIGIN env is set multiple times just wanted to check that it wasn't on the wrong spot.
I was also printing the url.origin in the load function in +layout.server.ts which resulted in the following output:
http://sub.domain.tld
Running
bun --print process.env
also tried with (Bun.env) resulted in:What i discovered was that when i didnt enforce https with my reverse proxy and use the website with "http://" it just works fine but that isnt the way i think
Hope somebody can help fixing this monster that cost me more then 2 hours of trying and failing
If you need some more infos just ask for it
The text was updated successfully, but these errors were encountered: