[Umbrella] Make the DSpace UI deployable under a strict Content-Security-Policy
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 30/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- angular, typescript
Direzione di ricerca
This is an umbrella issue; its implementation work is split into #6077 (SSR nonce support) and #6078 (removing remaining inline scripts), with backend security headers tracked in DSpace/DSpace#12951. Read those sub-issues first to identify a scoped task; this issue is done when the UI can run without 'unsafe-inline' or 'unsafe-eval' in script-src or style-src while retaining supported features.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is your feature request related to a problem? Please describe.
Institutions are increasingly required by their security teams to serve DSpace under a
Content-Security-Policy (CSP). DSpace/DSpace#9881 already proposes documenting CSP as a
recommended production hardening measure.
The problem is that today the only CSP the DSpace UI can actually run under is one that
provides close to no XSS protection. A working policy has to include:
script-src 'self' 'unsafe-inline' 'unsafe-eval' https:;
style-src 'self' 'unsafe-inline' https:;
script-src with 'unsafe-inline', 'unsafe-eval' and a blanket https: permits arbitrary
inline script and script from any HTTPS host, which is the exact class of injection CSP exists
to stop. Deployers therefore take on the breakage risk and the maintenance burden of a CSP
without getting the benefit, and a security review is very likely to raise concerns about such a
policy, rightfully so.
Two separate things force 'unsafe-inline':
- Styles. Angular injects component styles as
<style>elements at runtime. This is
unavoidable without supplying Angular a CSP nonce.CSP_NONCE/ngCspNonceexist in the
Angular version we ship (@angular/core20.3.x), but nothing in dspace-angular provides them.
There is currently no occurrence ofCSP_NONCEorngCspNonceanywhere in this repository. - Scripts. The bundle
<script>tags in the served HTML carry no nonce, and several
integrations build<script>elements at runtime, two of them with inline content.
Describe the solution you'd like
Make it possible for a deployer to serve the DSpace UI under a policy with no
'unsafe-inline' and no 'unsafe-eval' in script-src or style-src, without losing any
currently supported feature.
Proposed phasing:
Phase 1 (keystone): nonce support in SSR
See #6077. Generate a per-request nonce, stamp it on the bundle script tags and on Angular's
injected styles, emit the header from Express, and solve the interaction with the SSR page cache.
Target policy after phase 1:
script-src 'nonce-{random}' 'strict-dynamic' https:;
style-src 'nonce-{random}';
'strict-dynamic' means the nonced bundle is trusted and anything it loads is trusted too, so
Google Analytics, Matomo, MathJax, reCAPTCHA and AddToAny keep working untouched and their hosts
no longer need to be allowlisted. The trailing https: is ignored by browsers that understand
'strict-dynamic' and acts as a fallback for those that do not.
This is a large improvement over the status quo and is achievable without touching any feature
code. It is not the endpoint: 'strict-dynamic' still trusts anything application code loads.
Phase 2: remove the remaining inline scripts
See #6078. Independent of phase 1 and mergeable on its own.
Phase 3 (follow-up, not yet scoped): drop 'strict-dynamic'
Once phases 1 and 2 land, the remaining blocker to an explicit-allowlist policy is that the hosts
of the optional integrations are runtime configuration, not build-time constants:
| Integration | Where the host comes from |
|---|---|
| Matomo | matomo.tracker.url, fetched from the backend configuration at runtime (src/app/statistics/matomo.service.ts:105,143) |
| Google reCAPTCHA | google.recaptcha.key.site from backend config (src/app/core/google-recaptcha/google-recaptcha.service.ts:95) |
| MathJax | jsdelivr or cdnjs, selected by markdown.mathjax (src/app/core/shared/client-math.service.ts:50,54) |
| AddToAny | environment.addToAnyPlugin.scriptUrl (config.yml) |
| IIIF / Mirador | manifest and tile hosts, potentially third-party |
A statically written Apache header goes stale the moment an admin enables one of these. Phase 3
would derive the source lists from configuration so that enabling a feature cannot silently break
it. Filing this as a follow-up rather than scoping it now.
Documentation
DSpace/DSpace#9881 should carry the recommended policy and, importantly, the rollout procedure
(Content-Security-Policy-Report-Only with a reporting endpoint first). This matters more than
usual for DSpace: because the UI is server-rendered and then hydrated, a CSP-blocked script
typically leaves the SSR HTML visible and fails only during hydration, so breakage does not show
up in a quick visual smoke test.
Describe alternatives or workarounds you've considered
- Document the permissive policy and stop there. This is the status quo and is what most
deployers currently do. It satisfies a checkbox but not a threat model. Worth documenting as an
interim step regardless, which is what #9881 covers. - Hashes instead of nonces.
'sha256-...'for each inline block avoids per-request state and
therefore avoids the SSR cache problem entirely. It does not work here, because Angular's
runtime-injected styles are not known at build time. - Eliminate all inline styles from Angular. Not under our control; this is framework behaviour.
Additional information
- Related: DSpace/DSpace#9881 (documentation of production security recommendations)
- Angular CSP guidance: https://angular.dev/best-practices/security#content-security-policy
- Sub-issues: #6077, #6078, and DSpace/DSpace#12951 (backend security headers)
- Lingua principale
- TypeScript
- Stelle
- 180
- Fork
- 577
- Merge medio
- 2g 12h
- PR unite (30g)
- 111
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di DSpace/dspace-angular
-
affects: 10.x affects: 9.x bug component: submission Difficulty: Low help wanted ux
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
DSpace/dspace-angular#6412 ·
I maintainer di solito rispondono entro 3 giorni
-
accessibility affects: 10.x affects: 8.x affects: 9.x bug help wanted ux
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
DSpace/dspace-angular#6364 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
Author browse links on item page open in a new tab, unlike other browse linksForse già presa @jesielviana l’ha presa 16 giorni fa. Apertaaffects: main bug component: Item low priority
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
DSpace/dspace-angular#6268 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 3 giorni
-
Mathjax single dollar sign delimiter configuration causes unintentional math rendering in abstractsApertabug needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
DSpace/dspace-angular#6263 ·
I maintainer di solito rispondono entro 3 giorni
-
UI spacing regression on ds-generic-item-page-field (extra spaces around metadata values) in v10.xApertaaffects: 10.x affects: main bug component: Item ux
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
DSpace/dspace-angular#6254 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di DSpace/dspace-angular
Issue simili
-
Native Web
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
digitalfabrik/integreat-app#4517 ·
I maintainer di solito rispondono entro 2 giorni
-
TLS guide repeats certs/ in the certificate directoryForse già presa @maheshrijal l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
prometheus/docs#3156 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
medusajs/dtc-starter#90 ·
I maintainer di solito rispondono entro 1 giorno
-
usability
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
inmanta/web-console#7632 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
zaidmukaddam/scira#261 ·