Set Content-Security-Policy
This commit is contained in:
1 parent
af0a8c9fee
commit
870d55b44f
7 files changed
+67
-25
No files matched your search
@@ -117,7 +117,8 @@ Then serve the `dist/` folder, with these requirements:
|
|||||||
HellCon must reach it unchanged, so don't rewrite them to `index.html`.
|
HellCon must reach it unchanged, so don't rewrite them to `index.html`.
|
||||||
|
|
||||||
Recommended, as response headers, a `<meta>` can't set them (`index.html` sets
|
Recommended, as response headers, a `<meta>` can't set them (`index.html` sets
|
||||||
`Referrer-Policy: no-referrer` itself):
|
`Referrer-Policy: no-referrer` and the rest of its Content-Security-Policy itself, which keeps out
|
||||||
|
scripts and styles from elsewhere but allows connections to any tracker):
|
||||||
|
|
||||||
```
|
```
|
||||||
Content-Security-Policy: frame-ancestors 'none'
|
Content-Security-Policy: frame-ancestors 'none'
|
||||||
|
|||||||
@@ -15,6 +15,13 @@
|
|||||||
deployments on different versions, the receiver only sees "No sender with this code". Open how a
|
deployments on different versions, the receiver only sees "No sender with this code". Open how a
|
||||||
mismatch would be reported, e.g. by trying the previous version's swarm too.
|
mismatch would be reported, e.g. by trying the previous version's swarm too.
|
||||||
|
|
||||||
|
- Keep a transfer alive on phones: while a share waits or a transfer runs, hold a Screen Wake Lock
|
||||||
|
(`navigator.wakeLock.request('screen')`), else a phone that dims and locks suspends the tab and
|
||||||
|
the connection dies. The browser releases it whenever the page is hidden, so it has to be
|
||||||
|
requested again on `visibilitychange`. In the same phases, a `beforeunload` handler makes the
|
||||||
|
browser ask before a reload or a closed tab ends the share or transfer. Both go once it's done,
|
||||||
|
stopped or failed.
|
||||||
|
|
||||||
## Open observations
|
## Open observations
|
||||||
|
|
||||||
- Firefox ignores an errored service worker response stream: when the sender vanishes, the receiver
|
- Firefox ignores an errored service worker response stream: when the sender vanishes, the receiver
|
||||||
|
|||||||
+11
@@ -152,6 +152,7 @@ async function open(
|
|||||||
page.on('websocket', (ws) => ws.url().startsWith(base.replace('http', 'ws')) || trackers.push(ws));
|
page.on('websocket', (ws) => ws.url().startsWith(base.replace('http', 'ws')) || trackers.push(ws));
|
||||||
page.on('pageerror', (error) => errors.push(`${name}: ${error.message}`));
|
page.on('pageerror', (error) => errors.push(`${name}: ${error.message}`));
|
||||||
await page.addInitScript(trackPeers);
|
await page.addInitScript(trackPeers);
|
||||||
|
await page.addInitScript(failOnCsp);
|
||||||
if (init) await page.addInitScript(init);
|
if (init) await page.addInitScript(init);
|
||||||
await page.goto(base);
|
await page.goto(base);
|
||||||
return page;
|
return page;
|
||||||
@@ -187,6 +188,14 @@ async function hash(path: string) {
|
|||||||
|
|
||||||
const log = (page: Page) => page.locator('#log').textContent();
|
const log = (page: Page) => page.locator('#log').textContent();
|
||||||
|
|
||||||
|
// Init script for every page: whatever index.html's Content-Security-Policy blocks fails the test, the
|
||||||
|
// browsers only log it.
|
||||||
|
function failOnCsp() {
|
||||||
|
document.addEventListener('securitypolicyviolation', ({ violatedDirective, blockedURI }) => {
|
||||||
|
throw new Error(`Content-Security-Policy blocked ${blockedURI || 'inline'} by ${violatedDirective}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Init script for every page: keeps its peer connections in window.peers, so a test can check that
|
// Init script for every page: keeps its peer connections in window.peers, so a test can check that
|
||||||
// they were closed. It runs in the hidden frames too, only the app's own window counts.
|
// they were closed. It runs in the hidden frames too, only the app's own window counts.
|
||||||
function trackPeers() {
|
function trackPeers() {
|
||||||
@@ -1241,7 +1250,9 @@ for (const name of Object.keys(BROWSERS)) {
|
|||||||
const [sender, receiver] = await Promise.all(profiles.map((profile) => profile.newPage()));
|
const [sender, receiver] = await Promise.all(profiles.map((profile) => profile.newPage()));
|
||||||
for (const page of [sender!, receiver!]) {
|
for (const page of [sender!, receiver!]) {
|
||||||
sockets.set(page, []);
|
sockets.set(page, []);
|
||||||
|
page.on('pageerror', (error) => errors.push(`${name}: ${error.message}`));
|
||||||
await page.addInitScript(trackPeers);
|
await page.addInitScript(trackPeers);
|
||||||
|
await page.addInitScript(failOnCsp);
|
||||||
}
|
}
|
||||||
await Promise.all([sender!.goto(url), receiver!.goto(url)]);
|
await Promise.all([sender!.goto(url), receiver!.goto(url)]);
|
||||||
await transfer('offline', sender!, receiver!, source, LARGE_SIZE);
|
await transfer('offline', sender!, receiver!, source, LARGE_SIZE);
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
<meta name="robots" content="noindex, nofollow, noarchive, nosnippet" />
|
<meta name="robots" content="noindex, nofollow, noarchive, nosnippet" />
|
||||||
<meta name="googlebot" content="noindex, nofollow, noarchive, nosnippet" />
|
<meta name="googlebot" content="noindex, nofollow, noarchive, nosnippet" />
|
||||||
<meta name="referrer" content="no-referrer" />
|
<meta name="referrer" content="no-referrer" />
|
||||||
|
<meta
|
||||||
|
http-equiv="Content-Security-Policy"
|
||||||
|
content="default-src 'self'; style-src 'self'; connect-src 'self' ws: wss:; object-src 'none'; base-uri 'none'; form-action 'none'"
|
||||||
|
/>
|
||||||
<link rel="icon" type="image/png" href="./HellNet_alt.png" />
|
<link rel="icon" type="image/png" href="./HellNet_alt.png" />
|
||||||
<title>HellCon</title>
|
<title>HellCon</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.6.3",
|
"@biomejs/biome": "2.6.3",
|
||||||
"@playwright/test": "^1.64.1",
|
"@playwright/test": "^1.64.1",
|
||||||
"@types/node": "^26.6.5",
|
"@types/node": "^26.6.6",
|
||||||
"@vitejs/plugin-vue": "^6.0.10",
|
"@vitejs/plugin-vue": "^6.0.10",
|
||||||
"typescript": "~6.0.3",
|
"typescript": "~6.0.3",
|
||||||
"vite": "^8.3.5",
|
"vite": "^8.3.5",
|
||||||
|
|||||||
Generated
+22
-22
@@ -177,20 +177,20 @@ importers:
|
|||||||
specifier: ^1.64.1
|
specifier: ^1.64.1
|
||||||
version: 1.64.1
|
version: 1.64.1
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^26.6.5
|
specifier: ^26.6.6
|
||||||
version: 26.6.5
|
version: 26.6.6
|
||||||
'@vitejs/plugin-vue':
|
'@vitejs/plugin-vue':
|
||||||
specifier: ^6.0.10
|
specifier: ^6.0.10
|
||||||
version: 6.0.10(vite@8.3.5(@types/node@26.6.5))(vue@3.5.44(typescript@6.0.3))
|
version: 6.0.10(vite@8.3.5(@types/node@26.6.6))(vue@3.5.44(typescript@6.0.3))
|
||||||
typescript:
|
typescript:
|
||||||
specifier: ~6.0.3
|
specifier: ~6.0.3
|
||||||
version: 6.0.3
|
version: 6.0.3
|
||||||
vite:
|
vite:
|
||||||
specifier: ^8.3.5
|
specifier: ^8.3.5
|
||||||
version: 8.3.5(@types/node@26.6.5)
|
version: 8.3.5(@types/node@26.6.6)
|
||||||
vitest:
|
vitest:
|
||||||
specifier: ^5.0.5
|
specifier: ^5.0.5
|
||||||
version: 5.0.5(@types/node@26.6.5)(vite@8.3.5(@types/node@26.6.5))
|
version: 5.0.5(@types/node@26.6.6)(vite@8.3.5(@types/node@26.6.6))
|
||||||
vue-tsc:
|
vue-tsc:
|
||||||
specifier: ^3.3.13
|
specifier: ^3.3.13
|
||||||
version: 3.3.13(typescript@6.0.3)
|
version: 3.3.13(typescript@6.0.3)
|
||||||
@@ -409,11 +409,11 @@ packages:
|
|||||||
'@types/deep-eql@4.0.2':
|
'@types/deep-eql@4.0.2':
|
||||||
resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==}
|
resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==}
|
||||||
|
|
||||||
'@types/estree@1.0.9':
|
'@types/estree@1.0.10':
|
||||||
resolution: {integrity: sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==}
|
resolution: {integrity: sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==}
|
||||||
|
|
||||||
'@types/node@26.6.5':
|
'@types/node@26.6.6':
|
||||||
resolution: {integrity: sha512-uMzsv9stDdofIZBx4UGh4Z9ZgXnGC9seRDscilBcTHAeOFk67MZg/k9bWVfO+bk4qZmG+l52hRnLwUiH2LnJTg==}
|
resolution: {integrity: sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==}
|
||||||
|
|
||||||
'@vitejs/plugin-vue@6.0.10':
|
'@vitejs/plugin-vue@6.0.10':
|
||||||
resolution: {integrity: sha512-b80aUQh3n+qEzzZm5oQp3rT2QImeCx58K6eFl/RkJ3d65KW0kTuv5lNsLRVAjbW9YRUpo/wzmvzMgV34bTAItA==}
|
resolution: {integrity: sha512-b80aUQh3n+qEzzZm5oQp3rT2QImeCx58K6eFl/RkJ3d65KW0kTuv5lNsLRVAjbW9YRUpo/wzmvzMgV34bTAItA==}
|
||||||
@@ -922,26 +922,26 @@ snapshots:
|
|||||||
|
|
||||||
'@types/deep-eql@4.0.2': {}
|
'@types/deep-eql@4.0.2': {}
|
||||||
|
|
||||||
'@types/estree@1.0.9': {}
|
'@types/estree@1.0.10': {}
|
||||||
|
|
||||||
'@types/node@26.6.5':
|
'@types/node@26.6.6':
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 8.9.0
|
undici-types: 8.9.0
|
||||||
|
|
||||||
'@vitejs/plugin-vue@6.0.10(vite@8.3.5(@types/node@26.6.5))(vue@3.5.44(typescript@6.0.3))':
|
'@vitejs/plugin-vue@6.0.10(vite@8.3.5(@types/node@26.6.6))(vue@3.5.44(typescript@6.0.3))':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@rolldown/pluginutils': 1.0.1
|
'@rolldown/pluginutils': 1.0.1
|
||||||
vite: 8.3.5(@types/node@26.6.5)
|
vite: 8.3.5(@types/node@26.6.6)
|
||||||
vue: 3.5.44(typescript@6.0.3)
|
vue: 3.5.44(typescript@6.0.3)
|
||||||
|
|
||||||
'@vitest/mocker@5.0.5(vite@8.3.5(@types/node@26.6.5))':
|
'@vitest/mocker@5.0.5(vite@8.3.5(@types/node@26.6.6))':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jridgewell/trace-mapping': 0.3.31
|
'@jridgewell/trace-mapping': 0.3.31
|
||||||
'@vitest/spy': 5.0.5
|
'@vitest/spy': 5.0.5
|
||||||
estree-walker: 3.0.3
|
estree-walker: 3.0.3
|
||||||
magic-string: 1.4.5
|
magic-string: 1.4.5
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
vite: 8.3.5(@types/node@26.6.5)
|
vite: 8.3.5(@types/node@26.6.6)
|
||||||
|
|
||||||
'@vitest/spy@5.0.5': {}
|
'@vitest/spy@5.0.5': {}
|
||||||
|
|
||||||
@@ -1041,7 +1041,7 @@ snapshots:
|
|||||||
|
|
||||||
estree-walker@3.0.3:
|
estree-walker@3.0.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/estree': 1.0.9
|
'@types/estree': 1.0.10
|
||||||
|
|
||||||
expect-type@1.4.0: {}
|
expect-type@1.4.0: {}
|
||||||
|
|
||||||
@@ -1171,7 +1171,7 @@ snapshots:
|
|||||||
|
|
||||||
undici-types@8.9.0: {}
|
undici-types@8.9.0: {}
|
||||||
|
|
||||||
vite@8.3.5(@types/node@26.6.5):
|
vite@8.3.5(@types/node@26.6.6):
|
||||||
dependencies:
|
dependencies:
|
||||||
lightningcss: 1.33.0
|
lightningcss: 1.33.0
|
||||||
picomatch: 4.0.7
|
picomatch: 4.0.7
|
||||||
@@ -1179,13 +1179,13 @@ snapshots:
|
|||||||
rolldown: 1.2.15
|
rolldown: 1.2.15
|
||||||
tinyglobby: 0.2.17
|
tinyglobby: 0.2.17
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/node': 26.6.5
|
'@types/node': 26.6.6
|
||||||
fsevents: 2.3.3
|
fsevents: 2.3.3
|
||||||
|
|
||||||
vitest@5.0.5(@types/node@26.6.5)(vite@8.3.5(@types/node@26.6.5)):
|
vitest@5.0.5(@types/node@26.6.6)(vite@8.3.5(@types/node@26.6.6)):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/chai': 5.2.3
|
'@types/chai': 5.2.3
|
||||||
'@vitest/mocker': 5.0.5(vite@8.3.5(@types/node@26.6.5))
|
'@vitest/mocker': 5.0.5(vite@8.3.5(@types/node@26.6.6))
|
||||||
chai: 6.3.0
|
chai: 6.3.0
|
||||||
es-module-lexer: 2.3.2
|
es-module-lexer: 2.3.2
|
||||||
expect-type: 1.4.0
|
expect-type: 1.4.0
|
||||||
@@ -1196,10 +1196,10 @@ snapshots:
|
|||||||
tinybench: 6.2.2
|
tinybench: 6.2.2
|
||||||
tinyexec: 1.3.1
|
tinyexec: 1.3.1
|
||||||
tinyglobby: 0.2.17
|
tinyglobby: 0.2.17
|
||||||
vite: 8.3.5(@types/node@26.6.5)
|
vite: 8.3.5(@types/node@26.6.6)
|
||||||
why-is-node-running: 3.2.1
|
why-is-node-running: 3.2.1
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/node': 26.6.5
|
'@types/node': 26.6.6
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- msw
|
- msw
|
||||||
|
|
||||||
|
|||||||
+20
-1
@@ -2,8 +2,27 @@
|
|||||||
import vue from '@vitejs/plugin-vue';
|
import vue from '@vitejs/plugin-vue';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
|
const DEV_STYLE_SRC = "style-src 'self'";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [vue()],
|
plugins: [
|
||||||
|
vue(),
|
||||||
|
// index.html's Content-Security-Policy allows no inline styles, the dev server injects the CSS
|
||||||
|
// through JavaScript. A nonce lets only those style elements through, so the dev server enforces
|
||||||
|
// the same policy as the production build, which links the CSS as files.
|
||||||
|
{
|
||||||
|
name: 'dev-csp',
|
||||||
|
apply: 'serve',
|
||||||
|
config: () => ({ html: { cspNonce: 'dev' } }),
|
||||||
|
transformIndexHtml(html) {
|
||||||
|
if (!html.includes(DEV_STYLE_SRC)) throw new Error(`dev-csp: index.html has no "${DEV_STYLE_SRC}"`);
|
||||||
|
return html.replace(DEV_STYLE_SRC, `${DEV_STYLE_SRC} 'nonce-dev'`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// The dev server would inline small images like gitea.svg as data: URLs, which index.html's
|
||||||
|
// Content-Security-Policy blocks. The production build links them as files either way.
|
||||||
|
build: { assetsInlineLimit: 0 },
|
||||||
// Playwright runs e2e.spec.ts and backend/, which Vitest would pick up too.
|
// Playwright runs e2e.spec.ts and backend/, which Vitest would pick up too.
|
||||||
test: { include: ['src/**/*.test.ts'] },
|
test: { include: ['src/**/*.test.ts'] },
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user