English
Boundaries & Security Model
Pagehaven enforces seven foundational engineering laws verified automatically by scripts/check.mjs, tests, and Git hooks.
The Seven Iron Laws
- Web-Standard APIs Only in Core, Search & Site
packages/core/,packages/site/, andpackages/search/must use only Web-standard APIs (crypto.subtle,Uint8Array,TextEncoder,fetch,URL, Wasm) and never importnode:*built-ins. Node-only filesystem/CLI tooling belongs strictly inscripts/andpackages/platform/. - Pure-Static Baseline With
features.platform_config: false(no_headers,_redirects, oredgeone.json), all series, chapters, text layers, shelves, backups, and SQLite Wasm search must remain 100% functional. Cloud functions are optional slots, never prerequisites. - Strict R2 Privacy & Read/Write Split Cloudflare R2 remains strictly private. Write keys (
R2_*) exist only in CI secrets; browsers read WebP pages and.sqlitefiles solely viaimages.hosts(1–2 CDN domains backed by S3v4 private origin access). - Aligned SQLite Page & Chunk Sizes
db.page_sizeandsearch.request_chunk_sizemust stay aligned (4096default), with WAL mode disabled (journal_mode=DELETE) andVACUUMapplied before export. - One Static HTML per Chapter Every chapter compiles into a single HTML page containing all page
<img>tags and transparent.boxoverlays, keeping file counts within free-tier limits while lazy-loading/index/<series>.jsonTOC chunks. - Zero Secret or Private Path Leakage Account IDs, bucket names, API tokens, local workstation paths, and internal drafts must never enter source, configs, fixtures, commits, or docs. Example domains default to
gallery.example.organdimages.example.org. - Fail Loud on Misconfiguration Missing secrets, invalid YAML,
sourceSha256drift, unsafe object keys, or oversized bundles fail immediately with non-zero exit codes rather than silently degrading or shipping partial outputs.
Security & Trust Boundaries
Object Paths & Bounded Database Fetch
- Safe Object Paths (
packages/core/src/object-path.js):isSafeObjectPrefixandisSafeObjectKeyallow only unescaped ASCII relative paths, rejecting whitespace,./.., empty segments, and control characters. - Stream-Guarded Whole Download (
packages/search/src/whole.js): Before opening SQLite Wasm,loadGalleryDbvalidates embeddedgallery.searchDbmetadata (key,size > 0, 64-hexsha256,size <= whole_download_max_bytes), aborts any response stream exceeding declared or max byte caps, and verifies full-file SHA-256 before passing bytes to SQLite.
Local Shelf & JSON Backup Hardening
packages/site/src/lib/reading-backup.js validates v1 and v2 files. A v2 progress entry can include longOffset, an integer from 1 to 9999 measured in ten-thousandths of the image height.
- Hard cap of 5 MiB (
5 * 1024 * 1024 B) and 20,000 total records; - Exact schema & plain-object prototype checks across
library,progress,bookmarks, andnotes(max 200 chars per note); rejects arbitrary keys, URLs, or executable payloads.
Privacy & Known Limitations
/library/andpreviewbuilds emit<meta name="robots" content="noindex" />without canonical tags.- Fonts (
IBM Plex Sans) and licenses are bundled locally inpackages/site/public/— zero third-party font beacons or analytics. - Enable
features.range_searchinsite.config.yamland rebuild to read verified SQLite blocks on demand in a dedicated worker. The default build uses a bounded whole-file download (30 MiB by default).