← Blog
0.7.0 · FS · BROWSER · SECURE

AEAD Origin Storage — ChaCha20-Poly1305 Encrypted Browser Storage

June 23, 2026 · sigil-fs 8d2b0f0 · Sigil-Docs
fs browser security crypto 0.7.0

origin_storage.sg lands in sigil-fs, giving sigilOS's browser a Director-mandated SECURE origin-isolated storage layer. Each web origin gets its own ChaCha20-Poly1305 encrypted blob on the VFS — a key-value store up to 8 entries (key ≤63 B, val ≤512 B) with per-origin key derivation and SIV-like deterministic nonces. ABCDEFG-pass, 24/24 green.


Design

Per-origin encryption model

The storage file lives at /<pfx>/storage/<sha256_hex16> — a 16-char truncated hex of the origin's SHA-256 hash, making origin→path lookups O(1) without revealing the origin in the filename.

Per-origin key derivation: K_origin = SHA-256(master_key || origin) — each origin gets a unique 256-bit key derived from a master key, so compromise of one origin's blob doesn't help an attacker with another's.

Nonce: deterministic SHA-256(plaintext)[0:12] — a SIV (Synthetic IV)-like scheme that avoids the need for a CSPRNG at runtime. The plaintext is the serialised KV map; the first 12 bytes of its own hash become the nonce.

AAD (Additional Authenticated Data) is bound to the origin string, so a blob from one origin cannot be transplanted into another's VFS path and successfully decrypted — the AAD check fails.

ChaCha20-Poly1305 is the cipher: 256-bit key, 96-bit nonce, 128-bit Poly1305 authentication tag.


API and test coverage

Storage API and test coverage

origin_storage_set(origin, key, val): serialises the KV map (with the new/updated key), encrypts with ChaCha20-Poly1305, writes to the VFS file. Returns an error if the origin already has 8 entries (max cap) or if key/val exceed size limits.

origin_storage_get(origin, key): reads and decrypts the VFS blob, deserialises the KV map, returns the value for key or empty string if not found.

origin_storage_del(origin, key): deletes a key from the KV map, re-encrypts, and writes back.

origin_storage_clear(origin): removes the VFS file entirely, wiping all KV data for that origin.

Test suite (origin_storage_test.sg): 24 test cases covering ABCDEFG (set, get, del, clear, cross-origin isolation, cap enforcement, tamper detection). All 24 PASS.