Skip to content

Multiple url support#635

Open
schmurtzm wants to merge 2 commits intocmintey:mainfrom
schmurtzm:Multiple-url-support
Open

Multiple url support#635
schmurtzm wants to merge 2 commits intocmintey:mainfrom
schmurtzm:Multiple-url-support

Conversation

@schmurtzm
Copy link
Copy Markdown

This PR adds multiple allowed origins for CSRF protection, making it possible to access the application from several URLs (such as a domain name and a local IP address).
It achieves this by adding a new ALLOWED_ORIGINS environment variable, implementing custom CSRF verification logic that checks requests against this list (it also includes updated documentation and configuration accordingly).

CSRF Protection & Allowed Origins:

  • Added support for specifying multiple allowed origins via a new ALLOWED_ORIGINS environment variable, and implemented helper functions (isAllowedOrigin, getAllowedOrigins) to parse and validate origins in src/lib/server/auth.ts.
  • Replaced SvelteKit's default CSRF protection with a custom hook (csrfProtection) in src/hooks.server.ts that checks incoming requests' origins against the allowed list, and combined it with the main handler using sequence.
  • Disabled SvelteKit's built-in CSRF origin checking in svelte.config.js to avoid conflicts with the new custom implementation.

Documentation & Configuration:

  • Updated .env.example and README.md to document the new ALLOWED_ORIGINS variable and provide usage examples.
  • Enabled the Vite dev server to listen on all network interfaces (host: true) in vite.config.ts, making local network access easier for development and testing.

Add ALLOWED_ORIGINS environment variable to allow multiple origins for CORS and CSRF protection. Implements a custom CSRF protection hook in hooks.server.ts that checks requests against the allowed origins. Updates documentation and disables SvelteKit's default CSRF origin check to support this custom logic.
Set 'host: true' in the Vite server configuration to allow access from other network addresses.
@schmurtzm schmurtzm mentioned this pull request Jan 29, 2026
Copy link
Copy Markdown
Owner

@cmintey cmintey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand why this change is needed? I don't love turning off the built in CSRF protection for a home baked one

Comment thread vite.config.ts
})
],
server: {
host: true,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. You can run the dev server with the --host option

@schmurtzm
Copy link
Copy Markdown
Author

I wanted to be able to access thru my reverse proxy but also locally.
At least, if you put your website offline (for example, by disabling your reverse proxy,) you can still access to it.

By the way, when you fail the configuration of the url, if you start the account configuration, then after that you have to delete all the data, you wont be able to register again even if you modify the url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants