You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

csp-report-review-2026-08-03.md 5.1 KiB

1 kuukausi sitten
1 kuukausi sitten
1 kuukausi sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # CSP Report Review (PROD, 2026-08-03)
  2. Review of Content-Security-Policy-Report-Only violations from PNSPS PROD
  3. (`https://pnsps.gld.gov.hk`), for deciding Apache CSP updates.
  4. Source logs (external):
  5. - `PNSPS PROD CSP Report 2026-08-03.txt`
  6. - `summary.txt`
  7. - `CSP Issue 1.txt` (`script-src` / `eval` samples)
  8. Related app docs:
  9. - [csp-apache.conf.md](./csp-apache.conf.md) — Apache header snippets to deploy
  10. - [csp-report-review-2026-08-14.md](./csp-report-review-2026-08-14.md) — later PROD + UAT review (add/remove summary)
  11. ---
  12. ## Policy in effect at report time
  13. ```
  14. default-src 'self';
  15. base-uri 'self';
  16. object-src 'none';
  17. frame-ancestors 'none';
  18. form-action 'self';
  19. script-src 'self';
  20. style-src 'self' 'unsafe-inline';
  21. style-src-elem 'self' 'unsafe-inline';
  22. img-src 'self' data: https://www.w3.org https://w3.org;
  23. media-src 'self' blob:;
  24. font-src 'self' data:;
  25. connect-src 'self';
  26. upgrade-insecure-requests;
  27. report-uri https://pnsps.gld.gov.hk/api/csp-report
  28. ```
  29. Notes:
  30. - Disposition was `report` (Report-Only); nothing was enforced.
  31. - No `frame-src` → framing falls back to `default-src 'self'`.
  32. ---
  33. ## Summary of findings
  34. Most reports are **browser / extension noise**. Only one directive change is
  35. required for **app functionality**: add `frame-src`.
  36. | Approx. volume | Directive | Blocked | Verdict |
  37. |---:|---|---|---|
  38. | ~3000 | `frame-src` | empty / `data:` (URI often stripped) | **App** — PDF preview iframes |
  39. | ~1500 | `script-src` | `wasm-eval` | Noise — `chrome-extension` |
  40. | ~1400 | `font-src` | `fonts.gstatic.com` (Inter / Nunito) | Noise — not app fonts |
  41. | ~500 | `img-src` | `https://www.w3.org/WAI/wcag2AA` | Already allowed; mostly doc `404` noise |
  42. | ~240 | `font-src` | `at.alicdn.com`, `cdn.yiban.io`, Perplexity CDN | Noise — toolbars / extensions |
  43. | ~180 | `style-src-elem` | `fonts.googleapis.com` | Noise — not loaded by app |
  44. | ~70 | `script-src` | `eval` (line ~67) | Noise — no app `eval` |
  45. | rest | various | Kaspersky, Youdao, Quark, `todesktop-internal`, etc. | Noise |
  46. App fonts are self-hosted (`@fontsource` Public Sans / Noto; see `public/index.html`
  47. and `src/assets/fonts.css`). Google Fonts (Roboto / Inter / Nunito) are **not**
  48. part of the app and must not be allowlisted.
  49. ---
  50. ## App-owned issue: `frame-src`
  51. ### Cause
  52. Proof upload preview in
  53. `src/pages/Proof/Create_FromApp/UploadFileTable.js`:
  54. 1. `FileReader.readAsDataURL(...)` builds a `data:` URL
  55. 2. `window.open("")` then `document.write` an `<iframe src="data:...">`
  56. With no `frame-src`, CSP uses `default-src 'self'`, which blocks `data:` frames.
  57. Browsers often report `blocked-uri` as empty (`""`) for privacy.
  58. Almost all of these hits are on `/proof/create/...`, source
  59. `static/js/4608.*.chunk.js`.
  60. ### Apache fix
  61. ```apache
  62. frame-src 'self' data: blob:;
  63. ```
  64. ### Optional follow-up (frontend)
  65. Prefer `URL.createObjectURL` + `blob:` for preview (still needs `frame-src ... blob:`).
  66. ---
  67. ## Optional: `media-src` and `data:`
  68. Small volume of `media-src` / `data` on login and related pages.
  69. Captcha audio already uses `blob:` (`CustomFormWizard.js` and similar). Adding
  70. `data:` is low risk:
  71. ```apache
  72. media-src 'self' blob: data:;
  73. ```
  74. ---
  75. ## Already covered / not a CSP gap
  76. ### WCAG badge (`img-src` / `www.w3.org`)
  77. `AuthFooter.js` loads `https://www.w3.org/WAI/wcag2AA`. Policy already allows
  78. `https://www.w3.org` and `https://w3.org`. Many reports had document
  79. `status-code: 404` (SPA shell). No Apache change required.
  80. Optional hardening: host the badge image locally.
  81. ### Payment gateway CSS (`epaygateway1.gcis.gov.hk`)
  82. Single `style-src-elem` hit on `/paymentPage/callback` with gateway referrer.
  83. Card payment uses `window.location.assign(redirecturl)`, not embedded gateway CSS.
  84. Do **not** allowlist unless a real UI break is confirmed.
  85. ---
  86. ## Do not add to CSP
  87. | Requested by reports | Why not |
  88. |---|---|
  89. | `'unsafe-eval'` / `'wasm-unsafe-eval'` | Extension / injected; app has no `eval` |
  90. | `fonts.googleapis.com` / `fonts.gstatic.com` | App uses self-hosted fonts |
  91. | Kaspersky (`*.kis.v2.scr.kaspersky-labs.com`) | AV injection |
  92. | Perplexity, Youdao, Quark, alicdn, yiban, NetEase CDN | Third-party client tooling |
  93. | `todesktop-internal` | Desktop wrapper noise |
  94. | `epaygateway1.gcis.gov.hk` (styles) | Not required for current payment flow |
  95. ---
  96. ## Recommended Apache policy
  97. Use the snippets in [csp-apache.conf.md](./csp-apache.conf.md).
  98. Changes vs the 2026-08-03 deployed policy:
  99. 1. Add `frame-src 'self' data: blob:;`
  100. 2. Change `media-src` to `'self' blob: data:;`
  101. ### Rollout
  102. 1. Deploy updated **Report-Only** header.
  103. 2. Watch `/api/csp-report` for a few days — expect `frame-src` volume to drop;
  104. remaining extension noise is OK.
  105. 3. Promote the same policy to **enforcing** when app-owned directives look clean.
  106. Adjust `report-uri` host for UAT vs PROD:
  107. - UAT: `https://pnspsuat.gld.gov.hk/api/csp-report`
  108. - PROD: `https://pnsps.gld.gov.hk/api/csp-report`
  109. ---
  110. ## Backend reference
  111. - Report endpoint: `POST /csp-report` (context path → `/api/csp-report`)
  112. - Spring Security also sets a short API CSP on API responses
  113. (`default-src 'self'; script-src 'self'; frame-ancestors 'self'`).
  114. Frontend/Apache CSP above is what browsers enforce for the SPA document.