diff --git a/crates/core/src/bin/report_compare.rs b/crates/core/src/bin/report_compare.rs index ca90efcf..64931d90 100644 --- a/crates/core/src/bin/report_compare.rs +++ b/crates/core/src/bin/report_compare.rs @@ -11,7 +11,7 @@ #![allow(clippy::disallowed_methods)] use std::collections::HashMap; -use std::io::{self, ErrorKind, Write}; +use std::io::{self, ErrorKind, Read, Write}; use std::path::{Path, PathBuf}; use std::{env, fs, process}; @@ -125,7 +125,15 @@ impl Files for Disk { if meta.len() > MAX_PDF_BYTES as u64 { return Err(FileFailure::TooLarge); } - fs::read(path).map_err(|e| failure_of(&e)) + // Bounded read: a file that grew after the size check is still refused. + let mut bytes = Vec::new(); + fs::File::open(path) + .and_then(|f| f.take(MAX_PDF_BYTES as u64 + 1).read_to_end(&mut bytes)) + .map_err(|e| failure_of(&e))?; + if bytes.len() > MAX_PDF_BYTES { + return Err(FileFailure::TooLarge); + } + Ok(bytes) } } diff --git a/docs/development/R4_J1.md b/docs/development/R4_J1.md index 8531c2d3..8d6dbfce 100644 --- a/docs/development/R4_J1.md +++ b/docs/development/R4_J1.md @@ -20,7 +20,7 @@ Two surfaces, both on the DEV origin (`scripts/dev-env.sh`, No CSP header, HMR on. 2. The production build behind the DEPLOY CSP (what the proofs ran): `pnpm build:preview` then - `node scripts/browser/serve.mjs --host "$FAUNOSTEO_DEV_HOST" --port 4173`, + `. scripts/dev-env.sh && node scripts/browser/serve.mjs --host "$FAUNOSTEO_DEV_HOST" --port 4173` (the server refuses an empty or unspecified address), `http://:4173`. Static files, the nginx SPA fallback, the DEPLOY `Content-Security-Policy` with `'wasm-unsafe-eval'` on every response. `--csp without` serves the same build without the keyword (the diff --git a/docs/development/R4_J2.md b/docs/development/R4_J2.md index 6f98b8b2..34ff67e1 100644 --- a/docs/development/R4_J2.md +++ b/docs/development/R4_J2.md @@ -18,7 +18,7 @@ As for J1, on the DEV origin (`scripts/dev-env.sh`, `FAUNOSTEO_DEV_HOST`): 1. `pnpm dev:offline` (the local tool), `http://:5173`. 2. The production build behind the DEPLOY CSP: `pnpm build:preview` then - `node scripts/browser/serve.mjs --host "$FAUNOSTEO_DEV_HOST" --port 4173`, + `. scripts/dev-env.sh && node scripts/browser/serve.mjs --host "$FAUNOSTEO_DEV_HOST" --port 4173` (the server refuses an empty or unspecified address), `http://:4173`. Surface 2 is the one that matters for the memory items and the CSP. diff --git a/scripts/browser/serve.mjs b/scripts/browser/serve.mjs index a23e4ea3..e3274768 100644 --- a/scripts/browser/serve.mjs +++ b/scripts/browser/serve.mjs @@ -27,6 +27,7 @@ import { parseArgs } from 'node:util' import { DIST_DIR, HARNESS_DIR, REPO_ROOT } from './lib/paths.mjs' const HOST = '127.0.0.1' +const UNSPECIFIED_HOSTS = new Set(['', '0.0.0.0', '::', '::0', '[::]']) const WASM_KEYWORD = "'wasm-unsafe-eval'" const REPORT_PATH = '/__csp-report' const MAX_REPORT_BYTES = 64 * 1024 @@ -220,6 +221,11 @@ async function main() { if (!['with', 'without'].includes(values.csp)) { throw new Error('--csp is "with" or "without"') } + // An empty or unspecified address would bind every interface (an unset + // FAUNOSTEO_DEV_HOST expands to ''): refused, the server never starts. + if (UNSPECIFIED_HOSTS.has(values.host.trim())) { + throw new Error(`--host must name one address, not "${values.host}"`) + } const server = await startServer({ port: Number(values.port), csp: values.csp,