fix(tests): R4.9 security gate findings: serve.mjs refuses an empty or unspecified --host (an unset FAUNOSTEO_DEV_HOST bound every interface); report-compare reads at most the 50 MiB cap + 1 byte after its size check; recettes source dev-env.sh first
This commit is contained in:
1 parent
24e05cecd5
commit
80cc261c24
4 files changed
+18
-4
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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://<FAUNOSTEO_DEV_HOST>: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
|
||||
|
||||
@@ -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://<FAUNOSTEO_DEV_HOST>: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://<FAUNOSTEO_DEV_HOST>:4173`. Surface 2 is the one that matters for
|
||||
the memory items and the CSP.
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user