angular / angular/angular-cli

Content Security Policy and SPAs

Aperta
#32,405 1 commento 13 reazioni 0 assegnatari Vedi su GitHub
angular/build:application area: @angular/build feature feature: votes required
Lingua principale
TypeScript
Stelle
27k
Fork
11.8k
Merge medio
14h 23m
PR unite (30g)
162

Descrizione

### 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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dalla pipeline di build di Angular CLI e analizza come vengono gestiti il JavaScript di bootstrap e index.html. Definisci il formato di output di hashes.json e verifica che elenchi gli hash di tutti gli script di bootstrap, in modo che un backend possa usarli nel proprio header CSP.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
build-system, security
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.