Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
886ca0e
[hooks] Guard failproofai's installed code and refuse future-dated pa…
NiveditJain Nov 24, 2026
de65e59
[hooks] Block agent edits to its own hook settings (#1794)
NiveditJain Nov 24, 2026
8cd29d1
Merge remote-tracking branch 'origin/main' into claude/sec-1794-setti…
NiveditJain Nov 24, 2026
18328b0
[hooks] Address review: kernel-order symlink walk, pnpm store, $NVM_B…
NiveditJain Nov 24, 2026
8956fde
[hooks] CHANGELOG: cite #1050
NiveditJain Nov 24, 2026
ed5eb18
[hooks] Address hermes review: walk through missing directories; fail…
NiveditJain Nov 24, 2026
a57c623
Merge remote-tracking branch 'origin/main' into claude/sec-1796-dist-…
NiveditJain Nov 24, 2026
bda88fd
[hooks] CHANGELOG: move #1050's lines to 1.0.17-beta.0
NiveditJain Nov 24, 2026
770d7c4
[hooks] Close the review's shell bypasses and false positives (#1794)
NiveditJain Nov 24, 2026
95d2434
Merge remote-tracking branch 'origin/main' into claude/sec-1794-setti…
NiveditJain Nov 24, 2026
c386dbb
Move the #1794 changelog entry under 1.0.17-beta.0
NiveditJain Nov 24, 2026
cb51b5d
Name the PR in the #1794 changelog entry
NiveditJain Nov 24, 2026
314623a
[hooks] Read commands with one shell lexer; close the re-review's hol…
NiveditJain Nov 24, 2026
26571cc
[hooks] Close the third review pass's holes and super-linear inputs (…
NiveditJain Nov 24, 2026
bedf1a4
Merge remote-tracking branch 'origin/main' into claude/sec-1794-setti…
NiveditJain Nov 24, 2026
efccfea
[hooks] Close the last review pass: echo-to-script bodies, piped CLI,…
NiveditJain Nov 24, 2026
f4d5eab
Merge FailproofAI/failproofai#1050 (bda88fde) to build #1795 on its i…
NiveditJain Nov 24, 2026
41ef679
[hooks] Test: the always-on guard must protect the entry a project-sc…
NiveditJain Nov 24, 2026
5347275
[hooks] Guard node_modules/.bin/failproofai, the entry project-scope …
NiveditJain Nov 24, 2026
65e9f10
Merge remote-tracking branch 'origin/main' into claude/sec-1796-dist-…
NiveditJain Nov 24, 2026
248036e
[hooks] Address review: redirects, -t spellings, cd, globs and .bin s…
NiveditJain Nov 24, 2026
87045a6
[hooks] CHANGELOG: move #1050's lines to 1.0.18-beta.0 (1.0.17 shipped)
NiveditJain Nov 24, 2026
d3f19e5
[hooks] Close hermes round 1: links, .. after a link, quoted hooks-of…
NiveditJain Nov 24, 2026
2baab1c
[hooks] Address second review: quoted words, cd cost, false positives…
NiveditJain Nov 24, 2026
9b7113b
Merge FailproofAI/failproofai#1050 (87045a6c): its CHANGELOG lines mo…
NiveditJain Nov 24, 2026
c50991c
[hooks] Read a copy's destination past its redirects; open 1.0.18-bet…
NiveditJain Nov 24, 2026
f57b5ae
[hooks] CHANGELOG: #1795's guard fix under 1.0.18-beta.0 (#1058)
NiveditJain Nov 24, 2026
697fac9
[hooks] Address CodeRabbit: dotted pnpm-store glob; state the one-min…
NiveditJain Nov 24, 2026
d7f776c
Merge FailproofAI/failproofai#1050 (697fac99): dotted pnpm-store glob
NiveditJain Nov 24, 2026
9b3f34a
[hooks] Fix CI (unused commandWords); follow popd on an empty stack a…
NiveditJain Nov 24, 2026
49cdb01
Merge origin/main (95fb3c77) into claude/sec-1795-npx-local-bin-a18bab
NiveditJain Nov 24, 2026
6258224
Merge remote-tracking branch 'origin/main' into claude/sec-1796-dist-…
NiveditJain Nov 24, 2026
b962880
[hooks] Keep a line of heredocs linear; null means no managed setting…
NiveditJain Nov 24, 2026
6f645ea
Merge remote-tracking branch 'origin/main' into claude/sec-1794-setti…
NiveditJain Nov 24, 2026
658c5dd
[hooks] Address third review: quote-aware words, cd as bash runs it, …
NiveditJain Nov 24, 2026
486ca28
Merge origin/main into claude/sec-1795-npx-local-bin-a18bab
NiveditJain Nov 24, 2026
5910a41
Merge origin/main into claude/sec-1795-npx-local-bin-a18bab
NiveditJain Nov 24, 2026
e91e18f
Merge remote-tracking branch 'origin/main' into claude/sec-1796-dist-…
NiveditJain Nov 24, 2026
a1e52a6
Merge remote-tracking branch 'origin/main' into claude/sec-1794-setti…
NiveditJain Nov 24, 2026
6d31038
[hooks] Close CodeRabbit's later reviews: quoted redirect targets, ~/…
NiveditJain Nov 24, 2026
876e086
Merge remote-tracking branch 'origin/main' into claude/sec-1794-setti…
NiveditJain Nov 24, 2026
ff15069
Merge origin/main into claude/sec-1795-npx-local-bin-a18bab
NiveditJain Nov 24, 2026
603bb46
Merge remote-tracking branch 'origin/main' into claude/sec-1796-dist-…
NiveditJain Nov 24, 2026
13b27d4
[hooks] Read through filters that write no file of their own (#1794)
NiveditJain Nov 24, 2026
4795940
Close the walk gaps CodeRabbit found in the npx entry guard
NiveditJain Nov 24, 2026
70f0e1b
[hooks] Match node_modules and .pnpm only as whole path components
NiveditJain Nov 24, 2026
6a163ae
Keep 64 segments of the shell's whole path, and cut the tail without …
NiveditJain Nov 24, 2026
7ac5740
[hooks] Let a path component start right after a short-option cluster
NiveditJain Nov 24, 2026
4a7e40e
Refuse downloads and remote copies that write the npx entry
NiveditJain Nov 24, 2026
2377174
Resolve shell writes as the kernel does, and never forget where a cd …
NiveditJain Nov 24, 2026
d2f4f28
[hooks] Fix quadratic installed-code match: check the component start…
NiveditJain Nov 24, 2026
1bc07b4
Keep the guard linear on padded commands
NiveditJain Nov 24, 2026
dfdbe78
Leave the glued-option cluster before .bin unbounded
NiveditJain Nov 24, 2026
02b4258
Merge #1050's head (d2f4f287) into claude/sec-1795-npx-local-bin-a18bab
NiveditJain Nov 24, 2026
43bd947
[hooks] Start a path component only after a separator or a shell word…
NiveditJain Nov 24, 2026
684ac2d
Merge #1050's head (43bd9475) into claude/sec-1795-npx-local-bin-a18bab
NiveditJain Nov 24, 2026
e8577a7
[hooks] Close hermes round 2: link names, plugin trees, -t, git -C, c…
NiveditJain Nov 24, 2026
1388f38
[hooks] Address hermes: daemon-store globs and case-insensitive glob …
NiveditJain Nov 24, 2026
57f817a
[hooks] Close hermes round 3: parameter defaults, pushd -n, OLDPWD, g…
NiveditJain Nov 24, 2026
b6ff221
[hooks] Match globs case-insensitively, as macOS resolves paths (#1794)
NiveditJain Nov 24, 2026
8494c99
Merge #1050's head (1388f38c) into claude/sec-1795-npx-local-bin-a18bab
NiveditJain Nov 24, 2026
a0c7b1e
[hooks] Test upper-case .bin globs against the case-insensitive glob …
NiveditJain Nov 24, 2026
fc5caeb
[hooks] Close hermes round 4: variable values, stack rotation, git -C…
NiveditJain Nov 24, 2026
b003e0f
[hooks] Close hermes round 5: expansion-built CLI words, assigned lin…
NiveditJain Nov 24, 2026
34c2eb8
[hooks] Close hermes's four findings: native patches, glued outputs, …
NiveditJain Nov 24, 2026
87c4207
[hooks] Close hermes round 6: linear name matching, cp --parents, mor…
NiveditJain Nov 24, 2026
d011ea9
[hooks] Close hermes's second round: Codex workdir, cd -P, linked glo…
NiveditJain Nov 24, 2026
43c7a9e
[hooks] Close hermes round 7: dangling settings links, overflow, chai…
NiveditJain Nov 24, 2026
ebbac14
[hooks] Test: the always-on guard must protect the entry a project-sc…
NiveditJain Nov 24, 2026
b6f5272
[hooks] Guard node_modules/.bin/failproofai, the entry project-scope …
NiveditJain Nov 24, 2026
525acaf
[hooks] Address review: redirects, -t spellings, cd, globs and .bin s…
NiveditJain Nov 24, 2026
59a9cf8
[hooks] Address second review: quoted words, cd cost, false positives…
NiveditJain Nov 24, 2026
49b688a
[hooks] CHANGELOG: #1795's guard fix under 1.0.18-beta.0 (#1058)
NiveditJain Nov 24, 2026
d96730a
[hooks] Fix CI (unused commandWords); follow popd on an empty stack a…
NiveditJain Nov 24, 2026
f7b3e2d
[hooks] Address third review: quote-aware words, cd as bash runs it, …
NiveditJain Nov 24, 2026
cefee6b
Close the walk gaps CodeRabbit found in the npx entry guard
NiveditJain Nov 24, 2026
a97fb8a
Keep 64 segments of the shell's whole path, and cut the tail without …
NiveditJain Nov 24, 2026
79fb8e8
Refuse downloads and remote copies that write the npx entry
NiveditJain Nov 24, 2026
5e673ae
Resolve shell writes as the kernel does, and never forget where a cd …
NiveditJain Nov 24, 2026
2421afb
Keep the guard linear on padded commands
NiveditJain Nov 24, 2026
570dca2
Leave the glued-option cluster before .bin unbounded
NiveditJain Nov 24, 2026
85b52c1
[hooks] Test upper-case .bin globs against the case-insensitive glob …
NiveditJain Nov 24, 2026
afc7c42
[hooks] Close hermes's four findings: native patches, glued outputs, …
NiveditJain Nov 24, 2026
358bacd
[hooks] Close hermes's second round: Codex workdir, cd -P, linked glo…
NiveditJain Nov 24, 2026
35317e6
[hooks] Preserve reviewed .bin boundaries when rebasing #1058
hermes-exosphere Nov 25, 2026
4e00bf6
Merge remote-tracking branch 'origin/main' into claude/sec-1794-setti…
NiveditJain Nov 25, 2026
428826b
[hooks] Resolve #1058 conflicts while preserving branch history
hermes-exosphere Nov 25, 2026
27cc830
Merge main (#1050 squash 39d1afb3, #1061, #1060) into claude/sec-1795…
NiveditJain Nov 25, 2026
a5aa3f3
[hooks] Resolve variable chains of any length and protect relocated s…
NiveditJain Nov 25, 2026
e9574a2
[hooks] Close hermes's third round: disk globs, curl --output-dir, Co…
NiveditJain Nov 25, 2026
3296d8b
Merge hermes's push (428826bf) into claude/sec-1795-npx-local-bin-a18bab
NiveditJain Nov 25, 2026
3f0205f
[hooks] Read the files a sed script writes as writes
NiveditJain Nov 25, 2026
afbf193
[hooks] Close hermes's fifth round: linked glob matches, curl transfe…
NiveditJain Nov 25, 2026
ae95198
[hooks] Bound variable resolution and protect a worktree's main-check…
NiveditJain Nov 25, 2026
b93822d
[hooks] Read a sed write after an address, and keep quoted separators…
NiveditJain Nov 25, 2026
a33d8d1
[hooks] Judge destinations built by parameter expansion and globs tha…
NiveditJain Nov 25, 2026
7d7ebdd
[hooks] Close hermes's three P1s: quoted interpreters, unexamined bra…
NiveditJain Nov 25, 2026
79f9a9f
[hooks] Follow values assigned by for, read, printf -v, namerefs and …
NiveditJain Nov 25, 2026
c76a845
[hooks] Guard OpenClaw's apply_patch, which reaches policies by its o…
NiveditJain Nov 25, 2026
6fcdfdd
[hooks] Guard OpenClaw's native apply_patch, which reaches policies u…
NiveditJain Nov 25, 2026
8ac9b10
[hooks] Check every path a glob expands to, follow cd to a variable, …
NiveditJain Nov 25, 2026
52c478d
[hooks] Close hermes's seventh round: oversized globs, values through…
NiveditJain Nov 25, 2026
b5b4a70
[hooks] Read shell globs as zsh expands them too (#1795)
chhhee10 Nov 25, 2026
547ce19
[hooks] Give a glob after ** the directories it walked (#1795)
chhhee10 Nov 25, 2026
3a341d8
[hooks] Harden option parsing for curl and tar, and two shell expansi…
chhhee10 Nov 25, 2026
6a68b96
[hooks] Match parameter-operator patterns as bash does, not as paths …
chhhee10 Nov 25, 2026
336194e
[hooks] Address review round 11: globs, assigned values, git -C and t…
chhhee10 Nov 26, 2026
e0d88d8
[hooks] Harden Codex and Copilot tool input handling
chhhee10 Nov 26, 2026
556a5b1
[hooks] Compute printf conversions as bash does and read every tar -C…
chhhee10 Nov 27, 2026
3dbf325
[hooks] Refuse typed shell input that continues into a later write
chhhee10 Nov 27, 2026
db41109
[hooks] Refuse a Codex command that opens an interactive shell or REPL
chhhee10 Nov 27, 2026
2b3dc85
Merge #1058 (and its Codex/Copilot input hardening) into #1053
chhhee10 Nov 29, 2026
36fa1f2
[hooks] Address hermes's latest rounds on #1053 and #1058
chhhee10 Nov 29, 2026
a497cb6
[hooks] Bound two slow paths in the state walk
chhhee10 Nov 29, 2026
0f53de9
fix(audit): read Codex code-mode transcripts
chhhee10 Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- `failproofai audit` reads Codex's code-mode transcripts. From about Codex 0.146, and for every tool call on 0.172, Codex logs a tool call as a `custom_tool_call` (`exec`, whose input is a script calling `tools.exec_command(…)` and the other tools, or a freeform `apply_patch`), which audit skipped, so those sessions scanned as zero tool calls. Each call in the script is now read as its own event without running it; a command built from a variable is kept as the script. Codex's `exec_command {cmd, workdir}` now maps to `Bash {command, cwd}`, so the Bash builtins fire on older Codex transcripts too, and an `apply_patch` names the file it touches. Codex entries already in the audit cache are re-scanned once (#1053)
- Retire the hook-sync agent and stop publishing its image: `docker-hook-sync/`, its prompt and `build-image.yml` (which pushed `ghcr.io/failproofai/hook-sync` publicly every day) are removed. The agent ran Claude Code with permission checks skipped, a GitHub write token and a Claude token in its environment and no failproofai hooks, after reading a third-party npm README. Nothing had run it since July (FailproofAI/agenteye#1797, #1055)
- `fp`, the dashboard's api-server client, and the collector's uploader and OTLP relay refuse a plain `http://` URL for any host but `localhost` and loopback addresses, so `FP_DASHBOARD_URL`, `FAILPROOF_API_URL` or `FAILPROOFAI_INGEST_URL` can no longer put a session, a token, a sign-in code or the ingest key on the network in clear, and the api-server client no longer follows redirects; `fp logout` still clears a session saved against such a URL, without sending it (#1057)
- A dashboard bound off loopback (`FAILPROOFAI_DASHBOARD_HOST`) requires a per-launch access token on every request: the launch screen and `failproofai audit` print the address with `?token=` (audit no longer hands it to a browser opener, whose command line other local users can read), and the browser trades it for an HttpOnly cookie. Before, any machine on the network could set `Host` and `Origin` itself and read transcripts, change policies, or install a policy pack, which runs its code (#1057)
Expand All @@ -18,6 +19,9 @@
- Harden the privileged service install. Every file failproofai writes as root (the systemd unit, the launchd plist, Codex's system config and the daemon's copy under `/opt`) now reaches root as bytes on stdin and is checked against its SHA-256 before it is put in place; the daemon's copy is also held to the digest the build recorded, and a daemon binary that is a symbolic link is refused. `sudo` and every program it runs are named by absolute path from `/usr/bin`, `/bin`, `/usr/sbin` and `/sbin` and start with a minimal environment, the credential prompt included. The commands printed when sudo is not available do the same, run as printed, and on macOS carry the plist itself (#1060)
- The always-on guard (`block-failproofai-commands`) now protects failproofai's installed code, not only its state. A user-scope hook runs the package `which failproofai` found, which under nvm, Homebrew, Volta, bun, pnpm, yarn or the npx cache the agent's own user can write, so a Write of `process.exit(0)` over `dist/cli.mjs` turned every later hook into an allow. File-tool writes to `node_modules/failproofai/…`, pnpm's `.pnpm/failproofai@…`, the daemon's `@failproofai/failproofaid-*` package, or the `…/bin/failproofai` and `…/pnpm/failproofai` entry a hook runs are now denied, including through a symlink, and so are shell commands that name those paths literally. The protected paths match case-insensitively, because macOS volumes are case-insensitive by default (FailproofAI/agenteye#1796, #1050)
- A session pause whose recorded start is more than a minute in the future, or later than its latest renewal, is no longer honoured. The 8-hour ceiling was measured from that start, which comes from the same owner-writable file, so a hand-written pause dated 2100 stayed live until 2100. `failproofai config --resume --all` now also removes pause files that are not honoured yet, and exits 1 instead of reporting success when one cannot be removed (FailproofAI/agenteye#1796, #1050)
- An agent can no longer switch its own enforcement off by editing its CLI's settings: the always-on guard (`block-failproofai-commands`) refused writes to `~/.failproofai` only, so `"disableAllHooks": true` in the Claude Code settings layer that decides it, or failproofai's entries taken out of any agent's hooks file, stopped every policy, the guard included. It now refuses agent writes to every integration's settings and hook files (Claude Code, Codex `hooks.json` and `config.toml`, Copilot, Cursor, OpenCode, Pi, Antigravity, Goose, Factory, Devin, Hermes, OpenClaw, and the file the hook was loaded from when `CLAUDE_CONFIG_DIR` or `CODEX_HOME` moved it): Write, Edit, MultiEdit, NotebookEdit and `apply_patch` edits, checked after symlinks (a `..` after a link included, and every file behind Hermes' installed plugin link or in failproofai's own plugin directories), and shell writes, through a link's name too, by the same walk that protects `~/.failproofai`, plus `codex features disable hooks`. That walk now reads a command the way a shell does (quotes, comments, `${…}`, `$(…)`, heredocs), judges text piped into a shell (the failproofai CLI's too), follows a `cd` to the file a relative destination lands on (`cd -`, `cd -P` and a `cd` that may fail included), and catches `yq -i`, `awk -i inplace`, `sed`'s `e`/`W` and bundled `-i`, output options (`git log --output`, `sort -o<file>`), commands git runs (`rebase -x`, `filter-branch`) and file-moving `git` subcommands, `xargs`, process substitutions, variables spliced into a path, a copy followed by a redirect (`2>/dev/null`) or given a target directory however spelled (`-t<dir>`), and interpreters' inline programs, for the state as well; it no longer reads commit messages, PR bodies, comments or other quoted arguments as commands, and git hooks in `.github/hooks/` stay editable. A shell write that never names the file (a script written earlier and run later) is not seen. This guard leaves reads alone (the opt-in `block-read-outside-cwd` refuses them when enabled), and `failproofai config --status` now reports a `disableAllHooks` that is switching failproofai's Claude Code hooks off (#1053, FailproofAI/agenteye#1794)
- The always-on guard (`block-failproofai-commands`) also refuses agent writes of `node_modules/.bin/failproofai`, the file a project-scope hook's `npx -y failproofai` runs before the installed CLI, in the project or any directory above it: through the file tools (symlinks included) and every file a patch names (Codex's native `apply_patch` carries no `file_path`, and OpenClaw's reaches policies under its own name), and through shell commands that write it, copy, move, link or download a file of that name (`scp`, `wget`, `curl -O` included), name it as a value glued to an option (`curl -so<file>`), in curl's `--output-dir` or as a file a sed script writes, or put a whole directory into npm's `.bin`, including after a `cd` (or one that may have failed, or a `cd -P` through a link), through a symlink (one the same line makes is resolved as the kernel resolves it, and a glob is expanded where its directories really are, on disk as the shell expands it), through a variable the same line sets (whichever of its values a subshell or a one-command assignment leaves it, read when it is assigned, through another variable, an operator such as `${D%/}` or `${X:-bins}`, a `cd`, a loop, `read`, `printf -v` or `declare -n`), through a glob however many names it matches (`tee many/*` with a link among them) and a write that sweeps a bin directory (`tee bins/*`), through a long option cut short as curl before 8 and getopt_long take it (`--output-di`), wget's `--default-page` and `-e`, curl's other output files (`--stderr`, the cookie jar), a sed script, patch or curl config read from a file, an archive extracted into a bin directory, or behind a trailing redirect. A Codex command, which may run in a `workdir` its hook does not report, is refused when a relative destination would plant the entry, through any directory on the way. One Write of an `exit 0` stub there had turned every later hook in that tree into an allow. The same fixes close five ways around the state guard: a native patch naming it, a redirect after the destination (`cp /dev/null ~/.failproofai/policies-config.json 2>/dev/null`), another user's home in a glob (`rm -rf /home/alice/.failproof*`), a variable spliced into the path (`X=ai; rm -rf ~/.failproof$X`), and an output file glued to curl's option (`curl -so~/.failproofai/policies-config.json <url>`); and quoted text that `echo` or `printf` only prints (`echo 'cat > ~/.failproofai/policies-config.json'`), to the terminal or into a documentation file nothing on the line runs, is no longer read as a redirect. npx's other inputs (a `package.json` `bin` entry, `.npmrc`, dependency installs) are not covered (FailproofAI/agenteye#1795, #1058)
- Harden Codex and Copilot tool input handling: text sent to a running shell (Copilot `write_bash` and `write_powershell`, Codex `write_stdin`) is checked by the shell policies as the command lines it runs where the agent reports it, input that cannot be read as whole command lines is refused, and a Codex command that opens an interactive shell or REPL is refused (#1058)

### Docs

Expand Down
31 changes: 31 additions & 0 deletions __tests__/audit/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createHash } from "node:crypto";
import {
CACHE_SCHEMA_VERSION,
CACHE_TTL_MS,
TRANSCRIPT_PARSER_VERSIONS,
readCachedTranscriptResult,
writeCachedTranscriptResult,
} from "../../src/audit/cache";
Expand Down Expand Up @@ -163,4 +164,34 @@ describe("per-transcript audit cache", () => {
const intervalMs = DEFAULT_AUDIT_INTERVAL_DAYS * 24 * 60 * 60_000;
expect(CACHE_TTL_MS).toBeGreaterThan(intervalMs * 2);
});

// A parser that starts reading records it used to skip changes neither the
// transcript's mtime/size nor the builtins' hash, so without a parser
// version a Codex session cached as "0 tool calls" would be served for 30
// days after the fix shipped.
it("re-scans a Codex entry written before its parser version existed", () => {
const codex: TranscriptAuditResult = { ...FAKE_RESULT, cli: "codex", eventsScanned: 0 };
writeCachedTranscriptResult(TRANSCRIPT_PATH, MTIME, SIZE, codex);
const path = cachePathFor(TRANSCRIPT_PATH);
const entry = JSON.parse(readFileSync(path, "utf-8"));
expect(entry.parserVersion).toBe(TRANSCRIPT_PARSER_VERSIONS.codex);
expect(readCachedTranscriptResult(TRANSCRIPT_PATH, MTIME, SIZE)?.cli).toBe("codex");

delete entry.parserVersion; // what every pre-upgrade entry looks like
writeFileSync(path, JSON.stringify(entry));
expect(readCachedTranscriptResult(TRANSCRIPT_PATH, MTIME, SIZE)).toBeNull();

writeFileSync(path, JSON.stringify({ ...entry, parserVersion: 1 }));
expect(readCachedTranscriptResult(TRANSCRIPT_PATH, MTIME, SIZE)).toBeNull();
});

it("keeps serving a cached entry for a CLI whose parser has no version", () => {
expect(TRANSCRIPT_PARSER_VERSIONS.claude).toBeUndefined();
writeCachedTranscriptResult(TRANSCRIPT_PATH, MTIME, SIZE, FAKE_RESULT);
const path = cachePathFor(TRANSCRIPT_PATH);
const entry = JSON.parse(readFileSync(path, "utf-8"));
expect(entry.parserVersion).toBeUndefined();
writeFileSync(path, JSON.stringify(entry));
expect(readCachedTranscriptResult(TRANSCRIPT_PATH, MTIME, SIZE)?.eventsScanned).toBe(12);
});
});
80 changes: 80 additions & 0 deletions __tests__/audit/codex-code-mode-audit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// @vitest-environment node
//
// End to end for the audit's Codex path: a Codex 0.172 code-mode transcript
// (record shapes copied from a real session) through the parser, the shared
// LogEntry → event mapping and the replay engine. Before code mode was parsed
// this produced zero events, so no builtin could fire on any Codex 0.172
// session; and before exec_command mapped to Bash, none could fire on an older
// one either.
import { describe, it, expect, beforeEach } from "vitest";
import { parseCodexLog } from "@/lib/codex-sessions";
import { logEntriesToEvents } from "@/src/audit/cli-adapters/shared";
import { resetReplay, replayEvent } from "@/src/audit/replay";
import { canonicalizeToolInput, canonicalizeToolName } from "@/src/hooks/tool-name-canonicalize";

const rec = (o: Record<string, unknown>) => JSON.stringify(o);
const ctx = { cli: "codex" as const, sessionId: "s1", transcriptPath: "/tmp/codex.jsonl", cwd: "/home/u/proj" };

async function eventsOf(lines: string[]) {
const { entries } = await parseCodexLog(lines.join("\n"));
return logEntriesToEvents(entries, ctx);
}

describe("audit: Codex code-mode transcripts", () => {
beforeEach(() => resetReplay());

it("sees the shell command inside an exec snippet as Bash, and a builtin fires on it", async () => {
const events = await eventsOf([
rec({ timestamp: "2026-11-29T18:15:42.000Z", type: "session_meta", payload: { id: "s1", cwd: "/home/u/proj", cli_version: "0.172.0" } }),
rec({
timestamp: "2026-11-29T18:15:43.000Z",
type: "response_item",
payload: {
type: "custom_tool_call",
status: "completed",
call_id: "call_1",
name: "exec",
input: 'const r = await tools.exec_command({cmd:"sudo ls /root","workdir":"/home/u/proj","yield_time_ms":10000}); text(r.output);\n',
},
}),
rec({ timestamp: "2026-11-29T18:15:43.200Z", type: "response_item", payload: { type: "custom_tool_call_output", call_id: "call_1", output: [{ type: "input_text", text: "Script completed\n" }] } }),
]);
expect(events).toHaveLength(1);
expect(events[0]).toMatchObject({
toolName: "Bash",
rawToolName: "exec_command",
toolInput: { command: "sudo ls /root", cwd: "/home/u/proj" },
toolResultText: "Script completed\n",
});
const hits = await replayEvent(events[0]);
expect(hits.map((h) => h.policyName).some((n) => n.includes("block-sudo"))).toBe(true);
});

it("sees an apply_patch to .env as an Edit of that file, and a builtin fires on it", async () => {
const patch = "*** Begin Patch\n*** Update File: /home/u/proj/.env\n@@\n-A=1\n+A=2\n*** End Patch\n";
const events = await eventsOf([
rec({ timestamp: "2026-11-29T18:16:00.000Z", type: "response_item", payload: { type: "custom_tool_call", call_id: "call_2", name: "apply_patch", input: patch } }),
]);
expect(events).toHaveLength(1);
expect(events[0]).toMatchObject({ toolName: "Edit", rawToolName: "apply_patch", toolInput: { file_path: "/home/u/proj/.env" } });
const hits = await replayEvent(events[0]);
expect(hits.map((h) => h.policyName).some((n) => n.includes("block-env-files"))).toBe(true);
});

it("maps an older function_call exec_command to Bash too", async () => {
const events = await eventsOf([
rec({ timestamp: "2026-06-01T00:00:00.000Z", type: "response_item", payload: { type: "function_call", name: "exec_command", arguments: '{"cmd":"sudo whoami","workdir":"/w"}', call_id: "c" } }),
]);
expect(events[0]).toMatchObject({ toolName: "Bash", toolInput: { command: "sudo whoami", cwd: "/w" } });
});

it("does not change the live hook's Codex Bash payload", () => {
// Live PreToolUse already delivers `Bash {command}`; the cmd → command map
// must be a no-op on it.
const live = { command: "ls", description: "list" };
expect(canonicalizeToolName("Bash", "codex")).toBe("Bash");
expect(canonicalizeToolInput("Bash", live, "codex")).toEqual(live);
expect(canonicalizeToolName("write_stdin", "codex")).toBe("Bash");
expect(canonicalizeToolInput("Bash", { session_id: 3, chars: "ls\n" }, "codex")).toEqual({ session_id: 3, chars: "ls\n" });
});
});
12 changes: 12 additions & 0 deletions __tests__/e2e/helpers/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ export const CodexPayloads = {
tool_input: { command },
};
},
// Codex's native file edit, as it reaches the hook: `apply_patch`, with the
// patch in `tool_input.command` and no `file_path` at all.
applyPatch(patch: string, cwd: string): Record<string, unknown> {
return {
session_id: CODEX_SESSION_ID,
transcript_path: TRANSCRIPT_PATH,
cwd,
hook_event_name: "pre_tool_use",
tool_name: "apply_patch",
tool_input: { command: patch },
};
},
write(filePath: string, content: string, cwd: string): Record<string, unknown> {
// Codex aliases Edit/Write → apply_patch in matchers, so policies that
// filter on toolNames: ["Write"] continue to fire for Codex.
Expand Down
Loading