sveltejs / sveltejs/kit

Add ability to expose CSP nonces/hashes to server hook for header based CSP

Open
#13,208 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the server hook entry point in hooks.server.ts and the issue's CSP handling path. Determine how a page's CSP nonce or hash could be exposed there so it can be appended to the response header; done means the hook can access the value without rebuilding the application at deployment time.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, javascript
Domain
backend, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.