Internals: decision records
ADR-0006: Static file confinement
- Status: Accepted (2026-10-05), revised 2026-10-05 (openat2 implemented)
Decision
- Percent-decode the request path once. Reject NUL, backslash, decoded
/inside a segment (%2f), and any..segment. Collapse.and empty segments. - Deny any segment starting with
.except the first segment.well-known. - Linux: open the result with
openat2(RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS)relative to a directory fd of the root opened at prepare time, withO_NONBLOCK | O_NOCTTY | O_CLOEXEC. The kernel guarantees confinement for the whole resolution, so a concurrently swapped symlink cannot escape (closes the TOCTOU window of the canonicalise approach), and opening a FIFO cannot block. File type and size come fromfstaton the opened fd. - Fallback, Linux (kernels without
openat2; seccomp policies that reject it): walkrelone component at a time from the root fd withopenat(O_NOFOLLOW)(O_PATHdirectories, the leaf as in 3), never reopening a path; any symbolic link on the way is refused. A concurrent swap cannot leave the root (revised 2026-10-26: the earlier canonicalise-then-open fallback could be raced, security audit of panel mode). Other OSes: canonicaliseroot/reland require it to stay beneath the canonical root (checked, not race-free). - Directories serve configured index files (same lookup); never list.
Consequences
- With
RESOLVE_BENEATH, absolute symlinks are refused even if they point inside the root; relative symlinks that stay inside the root work. The Linux fallback is stricter still: it refuses every symbolic link. Both are documented for operators. - Non-blocking hot path (Linux): the lookup is first attempted on the async worker with
RESOLVE_CACHED(5.12+;EAGAINunless every component is in the dentry cache) and small files are read withpreadv2(RWF_NOWAIT)(EAGAINunless in the page cache). Anything that would block is redone on the blocking pool. Large files stream in 256 KiB positional reads, inline when cached, otherwise one blocking-pool hop per chunk; no thread is held between chunks, so slow clients cannot pin blocking threads. - On overlayfs (e.g. a container’s writable layer)
RESOLVE_CACHEDtypically returnsEAGAIN, so the blocking path is used: correct but slower. Serve document roots from a real filesystem (ext4/xfs, or a volume in containers).