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 ability to expose CSP nonces/hashes to server hook for header based CSP #13208

Open
hhvrc opened this issue Dec 20, 2024 · 1 comment
Open
Labels
feature / enhancement New feature or request

Comments

@hhvrc
Copy link

hhvrc commented Dec 20, 2024

Describe the problem

I cannot have a dynamic environment variable control a CSP directive.
This is needed to configure the CSP on startup of the sveltekit app in a docker container, the image cannot compile the application on the deployment machine because it has a relativley weak cpu and will take a while to spin up the instance then.

This problem makes it so that people that want to self-host the frontend either need to completely re-build it and re-publish their own docker image, or the project needs to get changed to not support inline script injection protection.

Describe the proposed solution

It would be really nice to be able to get the CSP hash/nonce for a intercepted page in the hooks.server.ts to be able to append those to the header of the response.

Alternatives considered

Considered reading the file in the hook, locating the CSP meta element, reading it, removing it, and then adding the hash to the header.

Importance

i cannot make my SvelteKit app selfhostable without it

Additional Information

No response

@notramo
Copy link

notramo commented Dec 21, 2024

This is also useful for other types of CSP manipulation.

form-action could be restricted to the server form actions of the given page.

A Typebot widget e.g. TypeBotIntegration.svelte could add dynamic values to the page only if it's rendered, so only those pages can load a Typebot that have the widget component rendered.

So, there could be 2 levels of configurability: route based (e.g. if route is /posts/, allow loading certain resources), or component-based, e.g. (add this to the style-src if this component is rendered anywhere on the page).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants