Skip to content

Commit 06e13cd

Browse files
committed
fix the docs and test
1 parent 22f40bb commit 06e13cd

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

docs/csp-headers.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ The base headers are defined in `vercel.json` and imported into `vite.config.ts`
1111
The `content-security-policy` is based on the recommendation by the [OWASP Secure Headers Project](https://owasp.org/www-project-secure-headers/index.html) (click the "Best Practices" tab). The directives:
1212

1313
- `default-src 'self'`: By default, restrict all resources to same-origin.
14-
- `style-src 'unsafe-inline' 'self'`: Restrict CSS to same-origin and inline use. `style=` attributes on React elements seem to count as inline.
1514
- `frame-src 'none'`: Disallow nested browsing contexts (`<frame>` and `<iframe>`).
1615
- `object-src 'none'`: Disallow `<object>` and `<embed>`.
1716
- `form-action 'none'`: Disallow submitting any forms with an `action` attribute (none of our forms are the traditional kind and instead post to the server in JS).
1817
- `frame-ancestors 'none'`: Disallow embedding this site with things like `<iframe>`; used to prevent click-jacking attacks.
1918

20-
In development mode, an additional `script-src` CSP directive is added which references a randomly-generated nonce. [Vite injects this in the generated index.html](https://vitejs.dev/guide/features.html#content-security-policy-csp) so that the dev-mode scripts can load. We do this instead of allowing `'unsafe-inline'` because I'm not sure whether tests run against dev bits or not, and this helps get dev builds much closer to production.
19+
In development mode, additional `script-src` and `style-src` CSP directives are added which reference a randomly-generated nonce. [Vite injects this in the generated index.html](https://vitejs.dev/guide/features.html#content-security-policy-csp) so that the dev-mode scripts and stylesheets can load. We do this instead of allowing `'unsafe-inline'` because I'm not sure whether tests run against dev bits or not, and this helps get dev builds much closer to production.
2120

2221
Also set are `x-content-type-options: nosniff` and `x-frame-options: DENY`.

test/e2e/meta.e2e.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('CSP headers', async ({ page }) => {
1313
expect(response?.headers()).toMatchObject({
1414
// note nonce is represented as [0-9a-f]+
1515
'content-security-policy': expect.stringMatching(
16-
/^default-src 'self'; style-src 'unsafe-inline' 'self'; frame-src 'none'; object-src 'none'; form-action 'none'; frame-ancestors 'none'; script-src 'nonce-[0-9a-f]+' 'self'$/
16+
/^default-src 'self'; frame-src 'none'; object-src 'none'; form-action 'none'; frame-ancestors 'none'; script-src 'nonce-[0-9a-f]+' 'self'; style-src 'nonce-[0-9a-f]+' 'self'$/
1717
),
1818
'x-content-type-options': 'nosniff',
1919
'x-frame-options': 'DENY',

0 commit comments

Comments
 (0)