angular / angular/angular-cli

Content Security Policy and SPAs

Offen
#32,405 1 Kommentar 13 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
angular/build:application area: @angular/build feature feature: votes required
Vorherrschende Sprache
TypeScript
Sterne
27k
Forks
11.8k
Ø Merge
14 Std. 23 Min.
Gemergte PRs (30 T.)
162

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der Angular CLI-Build-Pipeline und untersuche, wie Bootstrap-JavaScript und index.html verarbeitet werden. Definiere das Ausgabeformat für hashes.json und überprüfe, dass darin Hashes für alle Bootstrap-Skripte aufgeführt sind, damit ein Backend sie in seinem CSP-Header verwenden kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
build-system, security
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.