test(tests): R4.3d browser proofs on the production build: app import baseline on the Rust path, CSP with and without the keyword, leak series, WebKit repetition
Same perimeter as the TS baseline (226 files, 3 engines, real Home page): 666/678 outcome and message agreements, the 12 others the 4 declared files; W5 0 long tasks (TS 91 and 173 ms); 50 MiB file in WebKit 145/126 MiB against 324 with the worker read and 76 for the TS. CSP: editor opens with the keyword, the engine message without, in 3 engines, the worker's wasm-eval refusal reported by Chromium and Firefox. Leak series on the app: Chromium ≤ 2 MiB per import after init, Firefox GC sawtooth reclaimed, WebKit grows with same-tab navigations (control too) and levels off on one page; 20/20 WebKit workers closed.
This commit is contained in:
1 parent
8ddf185aa6
commit
08f01ef363
17 files changed
+26759
-28
No files matched your search
@@ -14,6 +14,10 @@
|
||||
// r4-import.mjs): /r4/ (scripts/browser/r4-import-page), /pkg/ and
|
||||
// /pkg-proofs/ (packages/core-wasm). A mounted path is a file or a 404,
|
||||
// never the SPA fallback. Without it nothing changes.
|
||||
//
|
||||
// startServer({ reportViolations: true }) (r4-app-csp.mjs) appends
|
||||
// `report-uri /__csp-report` to the policy and keeps the reports POSTed
|
||||
// there; not a CLI option.
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { readFile, stat } from 'node:fs/promises'
|
||||
import { createServer } from 'node:http'
|
||||
@@ -24,6 +28,8 @@ import { DIST_DIR, HARNESS_DIR, REPO_ROOT } from './lib/paths.mjs'
|
||||
|
||||
const HOST = '127.0.0.1'
|
||||
const WASM_KEYWORD = "'wasm-unsafe-eval'"
|
||||
const REPORT_PATH = '/__csp-report'
|
||||
const MAX_REPORT_BYTES = 64 * 1024
|
||||
const MIME = {
|
||||
'.html': 'text/html; charset=utf-8',
|
||||
'.js': 'text/javascript; charset=utf-8',
|
||||
@@ -137,7 +143,27 @@ async function route(root, path, mounts) {
|
||||
return { body: await readFile(join(root, 'index.html')), type: MIME['.html'] }
|
||||
}
|
||||
|
||||
async function respond(req, res, { root, csp, mounts }) {
|
||||
/** A violation report the browser POSTs (`report-uri`), kept as sent. */
|
||||
async function collectReport(req, res, { csp, reports }) {
|
||||
const chunks = []
|
||||
let size = 0
|
||||
for await (const chunk of req) {
|
||||
size += chunk.length
|
||||
if (size > MAX_REPORT_BYTES) break
|
||||
chunks.push(chunk)
|
||||
}
|
||||
try {
|
||||
reports.push(JSON.parse(Buffer.concat(chunks).toString('utf8')))
|
||||
} catch {
|
||||
reports.push({ unparsed: true, bytes: size })
|
||||
}
|
||||
send(res, { status: 204, csp })
|
||||
}
|
||||
|
||||
async function respond(req, res, { root, csp, mounts, reports }) {
|
||||
if (reports && req.method === 'POST' && req.url === REPORT_PATH) {
|
||||
return collectReport(req, res, { csp, reports })
|
||||
}
|
||||
const head = req.method === 'HEAD'
|
||||
if (req.method !== 'GET' && !head) return send(res, { status: 405, csp })
|
||||
const path = requestPath(req.url)
|
||||
@@ -150,22 +176,31 @@ async function respond(req, res, { root, csp, mounts }) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Starts the server; `port` 0 picks a free one; `mounts` see --r4. */
|
||||
/**
|
||||
* Starts the server; `port` 0 picks a free one; `mounts` see --r4;
|
||||
* `reportViolations` appends `report-uri` to the policy (its directives
|
||||
* unchanged) and keeps every report the browser POSTs in `reports`.
|
||||
*/
|
||||
export function startServer({
|
||||
root = DIST_DIR,
|
||||
port = 0,
|
||||
csp = 'with',
|
||||
mounts = {},
|
||||
reportViolations = false,
|
||||
} = {}) {
|
||||
const policy = cspVariant(productionCsp(), csp)
|
||||
const enforced = cspVariant(productionCsp(), csp)
|
||||
const policy = reportViolations
|
||||
? `${enforced}; report-uri ${REPORT_PATH}`
|
||||
: enforced
|
||||
const reports = reportViolations ? [] : null
|
||||
const server = createServer((req, res) =>
|
||||
respond(req, res, { root, csp: policy, mounts }),
|
||||
respond(req, res, { root, csp: policy, mounts, reports }),
|
||||
)
|
||||
return new Promise((done, fail) => {
|
||||
server.once('error', fail)
|
||||
server.listen(port, HOST, () => {
|
||||
const url = `http://${HOST}:${server.address().port}`
|
||||
done({ url, csp: policy, close: () => server.close() })
|
||||
done({ url, csp: policy, reports, close: () => server.close() })
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user