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-apache.conf.md 2.5 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Content-Security-Policy (Apache)
  2. Self-hosted fonts: no `fonts.googleapis.com` or `fonts.gstatic.com`. Static assets (including `woff2`) are served from `'self'`.
  3. Adjust `report-uri` if your API base path or host differs (UAT example below; PROD uses `https://pnsps.gld.gov.hk/api/csp-report`).
  4. See also: [csp-report-review-2026-08-03.md](./csp-report-review-2026-08-03.md) for the PROD report analysis that drove `frame-src` / `media-src` updates.
  5. ## Enforcing
  6. ```apache
  7. Header always set Content-Security-Policy "default-src 'self'; \
  8. base-uri 'self'; \
  9. object-src 'none'; \
  10. frame-ancestors 'none'; \
  11. form-action 'self'; \
  12. frame-src 'self' data: blob:; \
  13. script-src 'self'; \
  14. style-src 'self' 'unsafe-inline'; \
  15. style-src-elem 'self' 'unsafe-inline'; \
  16. img-src 'self' data: https://www.w3.org https://w3.org; \
  17. media-src 'self' blob: data:; \
  18. font-src 'self' data:; \
  19. connect-src 'self'; \
  20. upgrade-insecure-requests"
  21. ```
  22. ## Report-Only
  23. Same policy plus violation reporting:
  24. ```apache
  25. Header always set Content-Security-Policy-Report-Only "default-src 'self'; \
  26. base-uri 'self'; \
  27. object-src 'none'; \
  28. frame-ancestors 'none'; \
  29. form-action 'self'; \
  30. frame-src 'self' data: blob:; \
  31. script-src 'self'; \
  32. style-src 'self' 'unsafe-inline'; \
  33. style-src-elem 'self' 'unsafe-inline'; \
  34. img-src 'self' data: https://www.w3.org https://w3.org; \
  35. media-src 'self' blob: data:; \
  36. font-src 'self' data:; \
  37. connect-src 'self'; \
  38. upgrade-insecure-requests; \
  39. report-uri https://pnspsuat.gld.gov.hk/api/csp-report"
  40. ```
  41. ## Notes
  42. - **`frame-src`**: Required for proof file preview iframes that use `data:` / `blob:` URLs (`UploadFileTable.js`). Without this, framing falls back to `default-src 'self'` and browsers report `frame-src` violations (often with empty `blocked-uri`).
  43. - **`style-src-elem`**: Explicit, alongside `style-src`, for `<link rel="stylesheet">` behaviour in modern browsers.
  44. - **`img-src`**: Includes `https://www.w3.org` and `https://w3.org` so W3C WCAG badge URLs are allowed.
  45. - **`media-src`**: `blob:` for captcha audio object URLs; `data:` for data-URI media if used.
  46. - **`font-src`**: `'self' data:` covers bundled fonts and `data:` URLs if used.
  47. - **Report noise**: Browser extensions (Kaspersky, Perplexity, Youdao, Quark, Google Fonts injected by tooling, `wasm-eval` from chrome-extension) will still appear under Report-Only. Do **not** allowlist those origins.
  48. - Add origins to the relevant directive only if you introduce third-party scripts, styles, fonts, or APIs that the **application** itself loads.