Skip to content
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 Content-Security-Policy to Svelte config #1079

Merged
merged 1 commit into from
Jul 5, 2024

Conversation

andersju
Copy link
Member

@andersju andersju commented Jul 3, 2024

See https://kbse.atlassian.net/browse/LWS-215

Protects against XSS (among other things). https://kit.svelte.dev/docs/configuration#csp

Svelte automatically adds/sets nonces:

~ curl -I http://localhost:5173/
HTTP/1.1 200 OK
...
content-security-policy: default-src 'self'; img-src 'self' kb.se *.kb.se data:; script-src 'self' https://analytics.kb.se 'nonce-KS7ArPuN4IbXFqoAts03vg=='; style-src 'self' 'unsafe-inline'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'

I don't like style-src's unsafe-inline, but Svelte adds it automatically anyway; perhaps it can't (at this point) work without it. There's an open issue: sveltejs/kit#11747

I set style-src explicitly in svelte.config.js because otherwise, for some reason, unsafe-inline is not automatically added when running the integration tests, resulting in two tests failing.

Copy link
Contributor

@jesperengstrom jesperengstrom left a comment

Choose a reason for hiding this comment

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

Nice work, LGTM 👍

@andersju andersju merged commit fd45b67 into develop Jul 5, 2024
1 check passed
@andersju andersju deleted the feature/LWS-215-add-content-security-policy branch July 5, 2024 11:23
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