angular / angular/angular-cli

Content Security Policy and SPAs

Aberta
#32,405 1 comentário 13 reações 0 responsáveis Ver no GitHub
angular/build:application area: @angular/build feature feature: votes required
Linguagem predominante
TypeScript
Estrelas
27k
Forks
11.8k
Merge médio
14h 23min
PRs com merge (30d)
162

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Comece pelo pipeline de build do Angular CLI e inspecione como o JavaScript de bootstrap e o index.html são tratados. Defina o formato de saída de hashes.json e verifique se ele lista os hashes de todos os scripts de bootstrap para que um backend possa usá-los em seu cabeçalho CSP.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
angular, typescript
Domínio
build-system, security
Tipo de issue
Funcionalidade
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
48/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.