Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

Inline-Python deny rules miss a program fed on stdin (heredoc or pipe); follow-up to #2475

Open gjaworski86 opened this issue 3 weeks ago • 1 comments

Version

LifeOS 8.761.0 · attestation: 30 system file(s) differ from danielmiessler/[email protected]:

  • hooks/SatisfactionCapture.hook.ts
  • hooks/README.md
  • skills/CreateCLI/SKILL.md
  • skills/CreateCLI/Intents/CreateCli.md
  • skills/Prompting/SKILL.md
  • skills/LifeOSHooks/hooks/lib/build.ts
  • skills/Herdr/Intents/Configure.md
  • skills/LifeOS/SKILL.md
  • skills/LifeOS/Intents/Setup.md
  • skills/Fabric/SKILL.md
  • LIFEOS/TOOLS/VideoMeaning/README.md
  • LIFEOS/TOOLS/models.ts
  • LIFEOS/TOOLS/model-pricing.json
  • LIFEOS/DOCUMENTATION/Tools/Tools.md
  • LIFEOS/DOCUMENTATION/Memory/MemorySystem.md
  • LIFEOS/DOCUMENTATION/Location/LocationSystem.md
  • LIFEOS/DOCUMENTATION/Pulse/TerminalTabs.md
  • LIFEOS/DOCUMENTATION/Pulse/PulseSystem.md
  • LIFEOS/DOCUMENTATION/Workflows/WorkflowsSystem.md
  • LIFEOS/DOCUMENTATION/LifeosSystemArchitecture.md
  • LIFEOS/DOCUMENTATION/ARCHITECTURE_SUMMARY.md
  • LIFEOS/DOCUMENTATION/Algorithm/AscentStates.md
  • LIFEOS/DOCUMENTATION/Testing/TestingDoctrine.md
  • LIFEOS/DOCUMENTATION/Hooks/HookSystem.md
  • LIFEOS/DOCUMENTATION/Work/WorkSystem.md
  • LIFEOS/DOCUMENTATION/Assay/AssaySystem.md
  • LIFEOS/DOCUMENTATION/Services/BackgroundServices.md
  • LIFEOS/DOCUMENTATION/Router/RouterSystem.md
  • LIFEOS/ALGORITHM/AlgorithmReference.md
  • LIFEOS/ERRATA/fixtures/LabelBrief.md

What is broken

Follow-up to #2475. The shipped deny rules for inline Python cover a program passed on the command line (python -c *, python3 -c *) and an explicit stdin dash (python - *, python3 - *), but not the same program fed to the interpreter on stdin without the dash: a heredoc (python3 <<'PY' ... PY) or a pipe (... | python3). Python reads a program from stdin when given no script argument, so these are the same inline authoring the system prompt's "TypeScript for everything" rule says the native deny rules refuse. #2475 changed the rules to flag-cluster globs in the next release; its description lists only flag forms, so it is not clear the stdin forms are covered there. Running an existing script (python3 tool.py) must stay allowed, and the suggested rules keep it allowed. The probe below models Claude Code's Bash rule matching (glob, checked per subcommand of a pipeline or chain) against the rules read from the shipped settings.system.json; it does not drive the harness itself.

Where (file:line)

settings.system.json:240-243

Repro on a clean tree

1. Run the captured probe command from the config root. `settings.system.json` is byte-identical to main@f6ab5e02. The probe reads every `Bash(...)` deny rule that mentions python and checks four commands against them with a glob model of Claude Code's matching.
2. Expected: `python3 -c ...` denied (control), `python3 tool.py ...` allowed (control), a heredoc program on stdin denied, a piped program on stdin denied.
3. Actual: both controls behave as expected; the heredoc and the piped program match no shipped rule.

Negative control

Probe: d=$(mktemp -d) && cat > "$d/python-stdin-deny.test.ts" <<'EOF' import { test, expect } from "bun:test"; import { join } from "node:path"; import { homedir } from "node:os"; // Model of Claude Code's Bash permission rule: Bash(<glob>) where * matches any run of characters, checked against each // subcommand of a pipeline or && / ; chain. A model, not the harness: the shipped rules are read from settings.system.json. const root = process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude"); const deny: string[] = (await Bun.file(join(root, "settings.system.json")).json()).permissions.deny; const globs = deny.filter((r) => r.startsWith("Bash(") && /python/.test(r)).map((r) => r.slice(5, -1)); const deniedOne = (cmd: string) => globs.some((g) => new RegExp("^" + g.split("*").map((s) => s.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*") + "$", "s").test(cmd)); const denied = (cmd: string) => cmd.split(/\s*(?:\|\||&&|\||;)\s*/).some((part) => deniedOne(part.trim())); test("shipped python deny rules", () => { expect(globs.length).toBeGreaterThan(0); console.log(globs.join(" | ")); }); test("control: inline -c is denied", () => { expect(denied(python3 -c "open('f','w').write('x')")).toBe(true); }); test("control: running an existing script file stays allowed", () => { expect(denied("python3 tool.py --input data.csv")).toBe(false); }); test("a heredoc program on stdin is denied like -c", () => { expect(denied(python3 <<'PY'\nopen('f','w').write('x')\nPY)).toBe(true); }); test("a piped program on stdin is denied like -c", () => { expect(denied(echo "open('f','w').write('x')" | python3)).toBe(true); }); EOF bun test "$d/python-stdin-deny.test.ts" · exit 1 · captured 2026-11-13T11:12:25.245Z

Red looks like: (fail) a heredoc program on stdin is denied like -c

bun test v1.4.4 (38afee6c8)
python -c * | python3 -c * | python - * | python3 - *

--- stderr ---

../../../private/var/folders/5h/hl0y9ht11z16rb3y13007sbc0000gn/T/tmp.0dJVqa5b8m/python-stdin-deny.test.ts:
10 | const denied = (cmd: string) => cmd.split(/\s*(?:\|\||&&|\||;)\s*/).some((part) => deniedOne(part.trim()));
11 | test("shipped python deny rules", () => { expect(globs.length).toBeGreaterThan(0); console.log(globs.join(" | ")); });
12 | test("control: inline -c is denied", () => { expect(denied(`python3 -c "open('f','w').write('x')"`)).toBe(true); });
13 | test("control: running an existing script file stays allowed", () => { expect(denied("python3 tool.py --input data.csv")).toBe(false); });
14 | test("a heredoc program on stdin is denied like -c", () => {
15 |   expect(denied(`python3 <<'PY'\nopen('f','w').write('x')\nPY`)).toBe(true);
                                                                      ^
error: expect(received).toBe(expected)

Expected: true
Received: false

      at <anonymous> (/private/var/folders/5h/hl0y9ht11z16rb3y13007sbc0000gn/T/tmp.0dJVqa5b8m/python-stdin-deny.test.ts:15:66)
(fail) a heredoc program on stdin is denied like -c [0.12ms]
13 | test("control: running an existing script file stays allowed", () => { expect(denied("python3 tool.py --input data.csv")).toBe(false); });
14 | test("a heredoc program on stdin is denied like -c", () => {
15 |   expect(denied(`python3 <<'PY'\nopen('f','w').write('x')\nPY`)).toBe(true);
16 | });
17 | test("a piped program on stdin is denied like -c", () => {
18 |   expect(denied(`echo "open('f','w').write('x')" | python3`)).toBe(true);
                                                                   ^
error: expect(received).toBe(expected)

Expected: true
Received: false

      at <anonymous> (/private/var/folders/5h/hl0y9ht11z16rb3y13007sbc0000gn/T/tmp.0dJVqa5b8m/python-stdin-deny.test.ts:18:63)
(fail) a piped program on stdin is denied like -c [0.04ms]

 3 pass
 2 fail
 5 expect() calls
Ran 5 tests across 1 file. [4.00ms]

Suggested fix

Add four deny rules beside the existing python ones: Bash(python <<*), Bash(python3 <<*), Bash(python) and Bash(python3). The last two match a bare interpreter, which in a pipeline is a subcommand reading its program from stdin; a script invocation carries an argument and does not match. With those four rules added to a copy of settings.system.json, the probe passes (5 pass, 0 fail), including the control that python3 tool.py --input data.csv stays allowed. If the flag-cluster rewrite from #2475 already covers these forms, please close this as a duplicate of it.

Environment

  • OS: macOS 27.2 (arm64)
  • Harness: claude-code
  • bun: 1.4.4 · git: 2.54.0
  • Doctor broken: none

gjaworski86 avatar Nov 13 '26 11:11 gjaworski86

[!NOTE] 🤖 Kai (AI assistant) responding on behalf of Daniel Miessler

Thanks @gjaworski86, you found that the inline-Python deny rules missed a program fed on stdin. There are now deny rows for python and python3 heredocs, a bare interpreter at the end of a pipe, and the - form, and Claude Code itself refuses python3 <<EOF and | python3 - in a live session. Running a Python file (python3 tool.py, python3 -m json.tool) is unaffected. Thanks also to @isihussain for PR #2803.

This fix lands in the next LifeOS release, so I'm closing this now.

danielmiessler avatar Nov 19 '26 05:11 danielmiessler