runtime/secure_file.ts

Hardened secret-file read — the TS twin of the Rust spine's fuz_sys::secure_file::load_secure_file.

The file this guards is typically the highest-value credential on the host (the bootstrap token mints the keeper account), so the read fails loud rather than degrading: a symlink, a non-regular file (FIFO, device node, directory), a group/other-accessible mode, or an oversized file is refused, never returned. The deploy recipe places the token at 0600, so the check ratifies the shape zap produces; a hand-placed 0644 file fails at boot instead of being read.

The real implementation lives here (load_secure_file_node, wired as create_node_runtime().read_secure_file), and the mock honors the mode/size checks over its in-memory map (it has no file types). Both refuse through the shared assert_secure_mode / assert_secure_size helpers, so the checks — and their operator-facing messages — can't drift between them.

view source

Declarations
#

4 declarations

assert_secure_mode
#

runtime/secure_file.ts view source

(path: string, mode: number): void import {assert_secure_mode} from '@fuzdev/fuz_app/runtime/secure_file.js';

Refuse any group/other-accessible mode (only 0600/0400 pass).

Callers own the platform gating: load_secure_file_node skips the check where modes aren't meaningful (Windows); the mock checks its simulated modes unconditionally.

path

type string

mode

type number

returns

void

throws

  • Error - naming the path, the offending mode, and the `chmod` fix

assert_secure_size
#

runtime/secure_file.ts view source

(path: string, size: number): void import {assert_secure_size} from '@fuzdev/fuz_app/runtime/secure_file.js';

Refuse a byte count over MAX_SECURE_FILE_SIZE.

path

type string

size

type number

returns

void

throws

  • Error - naming the path, the size, and the cap

load_secure_file_node
#

runtime/secure_file.ts view source

(path: string): Promise<Uint8Array<ArrayBufferLike>> import {load_secure_file_node} from '@fuzdev/fuz_app/runtime/secure_file.js';

Read a secret file with fail-loud checks (Node implementation).

  • O_NOFOLLOW atomically rejects symlinks during open (no TOCTOU window)
  • O_NONBLOCK keeps the open from waiting on a FIFO that has no writer (it has no effect on a regular file); the regular-file check on the open descriptor then refuses it, a device node, or a directory
  • O_NOCTTY keeps a terminal device at the path from becoming the process's controlling terminal in the moment before that check refuses it
  • the permission check runs on the open descriptor, not the path, so the file can't be swapped between check and read — any group/other access (not 0600/0400) is refused
  • a size cap bounds the read; the read itself is limited to cap + 1 so a file growing between stat and read is still caught

path

path to the secret file

type string

returns

Promise<Uint8Array<ArrayBufferLike>>

the file's bytes

throws

  • Error - on a missing file, symlink, non-regular file, permissive mode, oversized file, or I/O failure

MAX_SECURE_FILE_SIZE
#

runtime/secure_file.ts view source

4096 import {MAX_SECURE_FILE_SIZE} from '@fuzdev/fuz_app/runtime/secure_file.js';

Maximum size for secure files. Prevents DoS from unexpectedly large files; 4 KiB is generous for token/key material. Matches the Rust twin's MAX_SECURE_FILE_SIZE.

Imported by
#