Content Security Policy and SPAs
- Langage dominant
- TypeScript
- Étoiles
- 27k
- Forks
- 11.8k
- Merge moyen
- 14 h 23 min
- PR mergées (30 j)
- 162
Description
### 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.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par le pipeline de build d’Angular CLI et examinez la manière dont sont gérés le JavaScript de bootstrap et index.html. Définissez le format de sortie de hashes.json et vérifiez qu’il répertorie les hashes de tous les scripts de bootstrap afin qu’un backend puisse les utiliser dans son en-tête CSP.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- angular, typescript
- Domaine
- build-system, security
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 48/100