You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit beb1807
Browse filesBrowse the repository at this point in the historyBrowse files
Addresses Codex P1, Greptile P2, and Aisle Med #1/#2/#3 on #73260:
# Streaming bounded hash (Codex P1 / Aisle Med #2)
The previous oversize-branch in readAuthProfilesStableHash still did
fs.readFile(path) which loaded the entire file into memory \u2014 the
MAX_AUTH_PROFILES_BYTES cap was effectively unenforced. Same problem
for readModelsJsonContentHash (no cap at all).
New helper safeHashRegularFile():
- lstat first; reject symlinks and non-regular files
- bail at lstat-time if size exceeds maxBytes (returns sentinel hash
so size-change still invalidates the cache)
- open with O_NOFOLLOW where supported (closes lstat\u2192open TOCTOU)
- fstat after open to verify it's still a regular file
- createReadStream(fd) with bounded highWaterMark; destroy if accumulated
bytes exceed maxBytes (handles the case where attacker grows the
file between lstat and stream completion)
Both readers now route through safeHashRegularFile. Models.json gets
a 1 MiB cap (MAX_MODELS_JSON_BYTES); auth-profiles keeps its 8 MiB cap.
# O_NOFOLLOW chmod (Aisle Med #1, CWE-367)
The previous lstat-then-chmod sequence was racy: an attacker who
could rename/replace ${agentDir}/models.json between the two syscalls
could have chmod() follow a swapped-in symlink to an arbitrary file.
Replaced with fs.open(path, O_RDONLY | O_NOFOLLOW) \u2192 fchmod via the
file handle. The open itself refuses symlinks atomically; the
fchmod operates on the validated fd, eliminating the race. When
O_NOFOLLOW is unavailable (rare but possible), falls back to plain
O_RDONLY \u2014 the prior lstat protection was already best-effort.
# Symlink-safe reads (Aisle Med #3, CWE-59)
Previous fs.readFile in the hash readers followed symlinks. With
the safeHashRegularFile refactor above, both auth-profiles.json and
models.json now reject symlinks before reading.
# JSDoc fix (Greptile P2)
readModelsJsonContentHash's prior comment said "forces a re-plan"
when the file is absent, but the call site does null === null
comparison which is a cache hit, not a re-plan (the steady-state
skip case for plan.action === 'skip'). Updated the comment to
explain the actual semantics: stable absence is a stable result;
drift is a re-plan.
# Tests
14/14 existing tests pass. No new test cases needed \u2014 the existing
file-mode and fingerprint-cache tests cover both the symlink-rejection
paths (via lstat shortcut) and the modelsJsonHash second-factor.
Lint: 0 errors.
0 commit comments