Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 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
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
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
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
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
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
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
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
1388f38
[hooks] Address hermes: daemon-store globs and case-insensitive glob …
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
34c2eb8
[hooks] Close hermes's four findings: native patches, glued outputs, …
NiveditJain Nov 24, 2026
d011ea9
[hooks] Close hermes's second round: Codex workdir, cd -P, linked glo…
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
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
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
b93822d
[hooks] Read a sed write after an address, and keep quoted separators…
NiveditJain Nov 25, 2026
7d7ebdd
[hooks] Close hermes's three P1s: quoted interpreters, unexamined bra…
NiveditJain Nov 25, 2026
6fcdfdd
[hooks] Guard OpenClaw's native apply_patch, which reaches policies u…
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
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
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- 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)
- 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
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
85 changes: 84 additions & 1 deletion __tests__/e2e/hooks/codex-integration.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { describe, it, expect } from "vitest";
import { execSync } from "node:child_process";
import { mkdtempSync, writeFileSync, readFileSync, existsSync, mkdirSync, rmSync } from "node:fs";
import { mkdtempSync, writeFileSync, readFileSync, existsSync, mkdirSync, rmSync, symlinkSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
Expand Down Expand Up @@ -166,6 +166,89 @@ describe("E2E: Codex integration — hook protocol", () => {
});
});

// Codex edits files with its native `apply_patch`, whose patch arrives in
// `tool_input.command` with no `file_path`. A patch planting
// `node_modules/.bin/failproofai` — the file a project-scope `npx -y failproofai`
// hook runs — passed the always-on guard until every file a patch names was
// checked (found by hermes on FailproofAI/failproofai#1058).
describe("E2E: Codex integration — native apply_patch", () => {
const patchOf = (...lines: string[]) => ["*** Begin Patch", ...lines, "*** End Patch", ""].join("\n");

it.each([
["adding the entry", patchOf("*** Add File: node_modules/.bin/failproofai", "+#!/bin/sh", "+exit 0")],
["updating the entry", patchOf("*** Update File: node_modules/.bin/failproofai", "@@", "-exec node cli.mjs", "+exit 0")],
["moving a file onto the entry", patchOf("*** Update File: scripts/stub.sh", "*** Move to: node_modules/.bin/failproofai", "@@", "+exit 0")],
["updating a link to the entry", patchOf("*** Update File: hook", "@@", "+exit 0")],
])("PreToolUse: a native patch %s is denied", (_label, patch) => {
const env = createCodexEnv();
try {
writeConfig(env.cwd, []);
mkdirSync(resolve(env.cwd, "node_modules", ".bin"), { recursive: true });
symlinkSync(resolve(env.cwd, "node_modules", ".bin", "failproofai"), resolve(env.cwd, "hook"));
const result = runHook("PreToolUse", CodexPayloads.preToolUse.applyPatch(patch, env.cwd), {
homeDir: env.home,
cli: "codex",
});
assertPreToolUseDeny(result);
} finally {
env.cleanup();
}
});

// Codex's shell tool runs a command in its `workdir`, but the hook payload
// carries the session's directory and the command only (found by hermes on
// FailproofAI/failproofai#1058). A native write that plants the entry if it
// runs in node_modules/.bin is refused from the project's root; with the
// workdir reported, it is read from there.
it("PreToolUse: a native shell write that may run in node_modules/.bin is denied", () => {
const env = createCodexEnv();
try {
writeConfig(env.cwd, []);
mkdirSync(resolve(env.cwd, "node_modules", ".bin"), { recursive: true });
const result = runHook(
"PreToolUse",
CodexPayloads.preToolUse.bash("printf '#!/bin/sh\\nexit 0\\n' > failproofai", env.cwd),
{ homeDir: env.home, cli: "codex" },
);
assertPreToolUseDeny(result);
} finally {
env.cleanup();
}
});

it("PreToolUse: a native shell write is read from the workdir the call reports", () => {
const env = createCodexEnv();
try {
writeConfig(env.cwd, []);
const withWorkdir = (workdir: string) => ({
...CodexPayloads.preToolUse.bash("printf x > failproofai", env.cwd),
tool_input: { command: "printf x > failproofai", workdir },
});
assertPreToolUseDeny(
runHook("PreToolUse", withWorkdir(resolve(env.cwd, "node_modules", ".bin")), { homeDir: env.home, cli: "codex" }),
);
assertAllow(runHook("PreToolUse", withWorkdir(resolve(env.cwd, "src")), { homeDir: env.home, cli: "codex" }));
} finally {
env.cleanup();
}
});

it("PreToolUse: a native patch to project files is allowed", () => {
const env = createCodexEnv();
try {
writeConfig(env.cwd, []);
const patch = patchOf("*** Update File: src/app.ts", "@@", "-a", "+b", "*** Add File: node_modules/.bin/my-tool", "+exit 0");
const result = runHook("PreToolUse", CodexPayloads.preToolUse.applyPatch(patch, env.cwd), {
homeDir: env.home,
cli: "codex",
});
assertAllow(result);
} finally {
env.cleanup();
}
});
});

describe("E2E: Codex integration — install/uninstall", () => {
it("policies --install --cli codex --scope project writes .codex/hooks.json with PascalCase keys", () => {
const env = createCodexEnv();
Expand Down
61 changes: 61 additions & 0 deletions __tests__/hooks/codex-interactive-session.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// @vitest-environment node
//
// Codex runs PreToolUse for the command that opens a session it keeps running,
// and none for what is typed into it afterwards (live codex-cli 0.172: the only
// hook call was `Bash` `{"command": "bash -i"}`). So opening one is refused.
import { describe, it, expect } from "vitest";
import { codexCallOpensSession, codexSessionGuardFor, opensInteractiveSession } from "../../src/hooks/codex-interactive-session";
import type { PolicyContext } from "../../src/hooks/policy-types";

describe("opensInteractiveSession", () => {
it.each([
"bash -i", "bash", "sh", "zsh -l", "/bin/bash --login", "fish", "bash -s", "exec bash", "env TERM=xterm bash -i",
"cd /tmp && bash", "FOO=1 bash -i", "busybox sh", "pwsh", "nu",
"python3", "python", "python3.12 -i", "python -i script.py", "python3 -m asyncio", "python -m pdb x.py", "python3 -", "ipython", "pypy3",
"node", "node -i", "deno", "bun repl", "irb", "pry", "ruby", "perl", "perl -de0", "php -a", "lua", "lua -i", "ghci", "R", "julia", "iex",
"tmux", "tmux new -s work", "tmux attach -t work", "screen", "screen -S x",
"ssh host", "ssh -p 2222 user@host", "ssh host bash", "mosh host", "telnet host", "sftp host",
"docker exec -it web sh", "docker run -it ubuntu", "docker run --interactive --rm img", "podman exec -i c bash", "docker attach web",
"kubectl exec -it pod -- sh", "kubectl run tmp -i --image=busybox", "kubectl debug -it pod",
"su", "su - root", "sudo -i", "sudo -s", "sudo bash", "sudo -u app bash", "doas sh",
"script", "script -q /dev/null", "nix-shell", "nix develop", "nix repl", "poetry shell", "pipenv shell", "vagrant ssh",
"vim notes.txt", "nvim", "ed file.txt", "emacs file", "nano x", "gdb ./a.out", "sqlite3 app.db", "psql", "mysql -u root", "redis-cli",
"nohup bash -i", "timeout 60 bash -i", "time python3",
])("refuses %s", (command) => {
expect(opensInteractiveSession(command)).not.toBeNull();
});

it.each([
"ls -la", "npm run dev", "npm test", "bun run build", "cargo run", "make", "git log", "git status",
"bash script.sh", "bash -c 'echo hi'", "bash -lc 'make test'", "sh ./configure", "zsh -c ls", "echo ls | bash", "bash < setup.sh",
"bash <<'EOF'\necho hi\nEOF",
"python3 script.py", "python -c 'print(1)'", "python3 -m pytest", "python -m http.server 8000", "python3 < x.py", "cat x.py | python3",
"node server.js", "node -e 'console.log(1)'", "node --version", "deno run main.ts", "bun x.ts", "ruby -e 'puts 1'", "ruby app.rb", "perl -ne 'print' f",
"man ls", "less README.md", "git diff | less", "tmux send-keys -t work 'ls' Enter", "tmux ls", "screen -ls",
"ssh host uptime", "ssh -N -L 8080:localhost:80 host", "sftp -b batch.txt host",
"docker ps", "docker exec web ls", "docker run --rm img echo hi", "kubectl get pods", "kubectl exec pod -- ls",
"su -c 'whoami' root", "sudo ls", "sudo -u app make", "script -c 'make' log.txt",
"nix-shell --run make", "nix develop -c make", "gdb -batch -ex bt ./a.out", "emacs --batch -l x.el",
"sqlite3 app.db 'select 1'", "psql -c 'select 1'", "mysql -e 'select 1'", "redis-cli ping",
"echo 'bash -i'", "grep python3 file", "# bash -i",
])("allows %s", (command) => {
expect(opensInteractiveSession(command)).toBeNull();
});
});

describe("codexCallOpensSession and the guard", () => {
it("judges only a canonical Bash call on PreToolUse", () => {
expect(codexCallOpensSession("PreToolUse", "Bash", { command: "bash -i" })).not.toBeNull();
expect(codexCallOpensSession("PostToolUse", "Bash", { command: "bash -i" })).toBeNull();
expect(codexCallOpensSession("PreToolUse", "Edit", { command: "bash -i" })).toBeNull();
expect(codexCallOpensSession("PreToolUse", "Bash", {})).toBeNull();
});

it("denies and tells the agent what to do instead", () => {
const ctx = { eventType: "PreToolUse", payload: {}, toolName: "Bash", toolInput: {} } as PolicyContext;
const result = codexSessionGuardFor("an interactive bash shell")(ctx);
expect(result.decision).toBe("deny");
expect(result.reason).toContain("an interactive bash shell");
expect(result.reason).toContain("Run each command on its own");
});
});
Loading