Content Security Policy and SPAs

Open
#32,405 1 comment 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
angular, typescript

Research direction

Start with the Angular CLI build pipeline and inspect how bootstrap JavaScript and index.html are handled. Define the output format for hashes.json and verify that it lists hashes for all bootstrap scripts so a backend can use them in its CSP header.

Written by the indexing model from the issue text.

Description

angular/build:application area: @angular/build feature feature: votes required
Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

Currently CSP and SPAs don't work well together.

There is however something very simple we could do to make CSP 100% compatible with SPA.

Proposed solution

When Angular builds the app, also output a file called hashes.json. This file contains a list of hashes of all of the bootstrap js scripts. Then, in your backend, say asp.net core, you read this file and add the hashes to your CSP header.

This would be a very simple change that would make a lot of people's lives much easier.

Alternatives considered
  • AutoCSP is not ideal because it uses the meta tag, not http headers.
  • Setting the nonce to CSP_NONCE doesn't work with strict-dynamic.
  • Setting the nonce in index.html breaks caching.
Dominant language
TypeScript
Stars
27k
Forks
11.8k
Avg merge
16h 35m
Merged PRs (30d)
176

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.

More from angular/angular-cli

All issues in angular/angular-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.