Repository navigation
fix(skill): stop substituting the scan path into code and commands - #4762
danikdanik wants to merge 2 commits into
Conversation
The skill told the agent to paste the user path literally into Python
source (e.g. detect(Path('INPUT_PATH'))) and into an unquoted watch
command line. A path containing a single quote breaks out of the
string literal and runs as code; a crafted directory name from a
cloned repo is enough.
The path now never enters code or shell text at all. Step 1 (and each
independent entry-point flow: add, --update, --watch) instructs the
agent to write the resolved absolute path to .graphify_input_path with
its file-writing tool - exact bytes, untouched by quoting or parsing.
Python blocks read it back via
SCAN_ROOT = Path('.graphify_input_path').read_text().rstrip('\n'),
and the watch command takes "$(cat .graphify_input_path)". This also
drops the cross-block shell-env dependency, so the flow works on
runtimes without persistent shells.
The INPUT_PATH placeholder is gone entirely.
|
Thanks for the pull request, @danikdanik. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Code graph out of date: Health delta baseline: last indexed commit 92741d1 (diverged from this PR's base — delta is approximate). Impact and hotspot numbers below may be wrong.
No verdict: the code graph is out of date. Static checks found no blocking issues, but they compared against an outdated graph. The next push after the repository re-indexes gets a full review.
Not checked: tests were not run; no formal proof of the changed code.
Graphify review — findings
Replaces the INPUT_PATH placeholder substitution in the graphify skill with a .graphify_input_path file that Step 1 writes and later steps read, so quoting can no longer break the scan path. Detection, graph build, community labeling, --update, --cluster-only, --add and --watch all load the path from that file via SCAN_ROOT or $(cat ...), and --update, --cluster-only, --add and --watch each write it first. Both graphify/skill.md and skills/graphify/skill.md get the same edits, and the file is read with Path.read_text(), so non-ASCII paths depend on the locale encoding.
No blocking issues surfaced. 9 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 60 functions depend on the 60 functions this change touches.
Health — grade A; no new coupling hotspots.
Verification — 60 functions in the blast radius were not formally verified this run (proofs are advisory here).
Health delta baseline: last indexed commit 92741d1 (diverged from this PR's base — delta is approximate).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 60 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
23 of 23 test file(s) selected (100%) via static blast radius.
Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.
tests/test_analyze.py— full-run-safetytests/test_benchmark.py— full-run-safetytests/test_build.py— full-run-safetytests/test_cache.py— full-run-safetytests/test_claude_md.py— full-run-safetytests/test_cluster.py— full-run-safetytests/test_confidence.py— full-run-safetytests/test_detect.py— full-run-safetytests/test_export.py— full-run-safetytests/test_extract.py— full-run-safetytests/test_hooks.py— full-run-safetytests/test_hypergraph.py— full-run-safetytests/test_ingest.py— full-run-safetytests/test_languages.py— full-run-safetytests/test_multilang.py— full-run-safetytests/test_pipeline.py— full-run-safetytests/test_report.py— full-run-safetytests/test_security.py— full-run-safetytests/test_semantic_similarity.py— full-run-safetytests/test_serve.py— full-run-safetytests/test_validate.py— full-run-safetytests/test_watch.py— full-run-safetytests/test_wiki.py— full-run-safety
non-code file(s) changed (
graphify/skill.md,skills/graphify/skill.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)
changed code file(s) with no mapped test (
graphify/skill.md,skills/graphify/skill.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
- Guard every .graphify_input_path read: an empty or non-directory
value now dies loudly instead of silently scanning the CWD
(Path('') resolves to cwd). Watch gets a [ -d ... ] preflight
before the watcher starts.
- Read the file with encoding='utf-8' at all four sites.
- Remove .graphify_input_path in Step 9 cleanup and ignore it in
.gitignore - it can embed a local username and every flow writes
it first anyway. Step 1 notes the file is machine-local.
- cluster-only: only Step 5 reads the file, not Steps 5-9.
- Step 1 wording: the path is never pasted into code and reaches a
command line only as quoted data (watch expands it from the file),
not "never touches a command line".
|
Addressed an external review pass in
|
…tute it (#4762) The generated /graphify runbook substituted the agent-supplied scan path straight into Python string literals across every code block: detect(Path('INPUT_PATH')), extract(cache_root=Path('INPUT_PATH'), root=Path('INPUT_PATH')), the semantic cache check/save, build_from_json/generate/diagnose, the manifest write, and the --update detect_incremental + merge. A scan root whose NAME carried a single quote or a $(...) / backtick broke out of the literal and ran as arbitrary code the moment the block ran (e.g. a cloned repo with a subdirectory named $(...) ). The shell transport was already hardened (#3642/#3844 write the path to graphify-out/.graphify_root through a quoted heredoc); this extends the same trust boundary to the Python blocks. Each block now reads the resolved root from graphify-out/.graphify_root (the file Step 1 writes) into an INPUT_PATH variable and passes the value, so the path is always inert data, never code. The prose no longer tells the agent to substitute a path. Applied to the assembled hosts (core.md, references/shared/update.md) and to the Aider and Devin monoliths; a new _is_input_path_sidecar_fix_line sanctions the monolith diff and --monolith-roundtrip / --check / --audit-coverage stay green. A fast regression guard asserts no generated skill body carries a quoted 'INPUT_PATH' code literal. SPEC_PATH (the skill's own extraction-spec install path, not attacker-controlled) is left substituted and tracked as a follow-up. Reported and first proposed by @danikdanik in #4762. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…k reads The scan-path injection fix reads graphify-out/.graphify_root once per Python block, so the lean claude core grew from ~795 to 807 lines. Raise the ceiling to 820 — still far under the ~1156-line pre-split monolith the guard exists to catch. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Thanks for catching this and proposing the fix, @danikdanik — it's a real RCE: a scan root whose name carried a quote or |
Upstream Graphify-Labs#4762 already reads the scan root from .graphify_root into an INPUT_PATH variable in every block, so this branch adopts that and drops its own read_scan_root() rewrites of the skill scripts. What stays here: Step 5 labels read from JSON, the spec path read from a file, the quoted interpreter path, and the Step 1 line-break refusal. The placeholder guard now matches only the quoted 'INPUT_PATH' literal, and the Graphify-Labs#4777 force test writes the labels file instead of pasting LABELS_DICT.
…ge step #4680 was authored before the #4762 injection hardening, so its B3.5 Python block passed a quoted `Path('INPUT_PATH')` literal to drop_unreported_chunk_sources. That is the exact substitution pattern #4762 removed: a scan root whose name holds a quote or `$()` could break out and run as code. Use the `INPUT_PATH` variable the block already reads from the trusted graphify-out/.graphify_root sidecar, and regenerate the skill artifacts. Caught by test_skillgen_input_path_injection. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…itute them The query, path and explain runbooks pasted free-text values into quoted shell arguments and Python string literals — --answer "ANSWER", question = 'QUESTION', a_term = 'NODE_A' — so any question, answer or node name containing a quote, $() or backtick executed as code instead of data. Same injection class as the INPUT_PATH fix (Graphify-Labs#4762), but it fires on ordinary use: answers and labels routinely carry those characters. Every value now travels through a graphify-out/ sidecar the agent writes first (.graphify_question, .graphify_answer, .graphify_nodes, .graphify_expanded, .graphify_node_a/b, .graphify_node_name, .graphify_correction), the answer goes through save-result --answer-file, and the cited-node list through a while-read array. MODE and BUDGET stay literals: fixed enum and number. Adds a fence test that bans the placeholder tokens across all generated bodies and proves a hostile question file reaches argv verbatim.
…ever substitute it Step B0/B3 told the agent to paste the spec path into prompt_file='SPEC_PATH' — the same paste-into-code vector Graphify-Labs#4762 removed for INPUT_PATH. A path containing a quote would break out of the string literal the moment the block runs. The path now travels by file like the scan root: Step 1 captures it as the second line of the existing quoted heredoc (a matching here-string on Windows) into graphify-out/.graphify_spec, chained with && so a bad scan root still fails loudly, and both cache calls read it back. Also fences the new contract: the prompt_file test now pins prompt_file=SPEC_PATH plus the .graphify_spec read, and the exec-driven tests simulate Step 1's file writes instead of substituting literals.
…ever substitute it Step B0/B3 told the agent to paste the spec path into prompt_file='SPEC_PATH' — the same paste-into-code vector Graphify-Labs#4762 removed for INPUT_PATH. A path containing a quote would break out of the string literal the moment the block runs. The path now travels by file like the scan root: Step 1 captures it as the second line of the existing quoted heredoc (a matching here-string on Windows) into graphify-out/.graphify_spec, chained with && so a bad scan root still fails loudly, and both cache calls read it back. Also fences the new contract: the prompt_file test now pins prompt_file=SPEC_PATH plus the .graphify_spec read, and the exec-driven tests simulate Step 1's file writes instead of substituting literals.
…ever substitute it Step B0/B3 told the agent to paste the spec path into prompt_file='SPEC_PATH' — the same paste-into-code vector Graphify-Labs#4762 removed for INPUT_PATH. A path containing a quote would break out of the string literal the moment the block runs. The path now travels by file like the scan root: Step 1 captures it as the second line of the existing quoted heredoc (a matching here-string on Windows) into graphify-out/.graphify_spec, chained with && so a bad scan root still fails loudly, and both cache calls read it back. Also fences the new contract: the prompt_file test now pins prompt_file=SPEC_PATH plus the .graphify_spec read, and the exec-driven tests simulate Step 1's file writes instead of substituting literals.
…ever substitute it Step B0/B3 told the agent to paste the spec path into prompt_file='SPEC_PATH' — the same paste-into-code vector Graphify-Labs#4762 removed for INPUT_PATH. A path containing a quote would break out of the string literal the moment the block runs. The path now travels by file like the scan root: Step 1 captures it as the second line of the existing quoted heredoc (a matching here-string on Windows) into graphify-out/.graphify_spec, chained with && so a bad scan root still fails loudly, and both cache calls read it back. Also fences the new contract: the prompt_file test now pins prompt_file=SPEC_PATH plus the .graphify_spec read, and the exec-driven tests simulate Step 1's file writes instead of substituting literals.
…itute them The query, path and explain runbooks pasted free-text values into quoted shell arguments and Python string literals — --answer "ANSWER", question = 'QUESTION', a_term = 'NODE_A' — so any question, answer or node name containing a quote, $() or backtick executed as code instead of data. Same injection class as the INPUT_PATH fix (Graphify-Labs#4762), but it fires on ordinary use: answers and labels routinely carry those characters. Every value now travels through a graphify-out/ sidecar the agent writes first (.graphify_question, .graphify_answer, .graphify_nodes, .graphify_expanded, .graphify_node_a/b, .graphify_node_name, .graphify_correction), the answer goes through save-result --answer-file, and the cited-node list through a while-read array. MODE and BUDGET stay literals: fixed enum and number. Adds a fence test that bans the placeholder tokens across all generated bodies and proves a hostile question file reaches argv verbatim.
…itute them The query, path and explain runbooks pasted free-text values into quoted shell arguments and Python string literals — --answer "ANSWER", question = 'QUESTION', a_term = 'NODE_A' — so any question, answer or node name containing a quote, $() or backtick executed as code instead of data. Same injection class as the INPUT_PATH fix (Graphify-Labs#4762), but it fires on ordinary use: answers and labels routinely carry those characters. Every value now travels through a graphify-out/ sidecar the agent writes first (.graphify_question, .graphify_answer, .graphify_nodes, .graphify_expanded, .graphify_node_a/b, .graphify_node_name, .graphify_correction), the answer goes through save-result --answer-file, and the cited-node list through a while-read array. MODE and BUDGET stay literals: fixed enum and number. Adds a fence test that bans the placeholder tokens across all generated bodies and proves a hostile question file reaches argv verbatim.
…itute them The query, path and explain runbooks pasted free-text values into quoted shell arguments and Python string literals — --answer "ANSWER", question = 'QUESTION', a_term = 'NODE_A' — so any question, answer or node name containing a quote, $() or backtick executed as code instead of data. Same injection class as the INPUT_PATH fix (Graphify-Labs#4762), but it fires on ordinary use: answers and labels routinely carry those characters. Every value now travels through a graphify-out/ sidecar the agent writes first (.graphify_question, .graphify_answer, .graphify_nodes, .graphify_expanded, .graphify_node_a/b, .graphify_node_name, .graphify_correction), the answer goes through save-result --answer-file, and the cited-node list through a while-read array. MODE and BUDGET stay literals: fixed enum and number. Adds a fence test that bans the placeholder tokens across all generated bodies and proves a hostile question file reaches argv verbatim.
…r files Three runbooks still pasted free-text values into executable source after the INPUT_PATH fix (Graphify-Labs#4762): - labels = LABELS_DICT: Step 5 pasted the agent-built community-name dict into Python source; a label containing a quote or brace broke the literal and ran as code. - ingest('URL', ..., author='AUTHOR', contributor='CONTRIBUTOR'): the /graphify add URL and user names went into Python string literals. - graphify clone <url> and export obsidian --dir <path>: URLs and paths were pasted unquoted into shell lines, where &, ; or $() executes. All now travel through graphify-out/ sidecars the agent writes first: .graphify_labels.json (Step 5 reads it back), .graphify_add_url plus optional .graphify_add_author/.graphify_add_contributor (missing file maps to None), .graphify_clone_url/.graphify_clone_branch and .graphify_obsidian_dir. The PowerShell translator gains a $(cat FILE) -> Get-Content -Raw rule so the same sidecars work in the windows render. Adds a fence test banning the paste-the-value tokens across all generated bodies.
…itute them The query, path and explain runbooks pasted free-text values into quoted shell arguments and Python string literals — --answer "ANSWER", question = 'QUESTION', a_term = 'NODE_A' — so any question, answer or node name containing a quote, $() or backtick executed as code instead of data. Same injection class as the INPUT_PATH fix (Graphify-Labs#4762), but it fires on ordinary use: answers and labels routinely carry those characters. Every value now travels through a graphify-out/ sidecar the agent writes first (.graphify_question, .graphify_answer, .graphify_nodes, .graphify_expanded, .graphify_node_a/b, .graphify_node_name, .graphify_correction), the answer goes through save-result --answer-file, and the cited-node list through a while-read array. MODE and BUDGET stay literals: fixed enum and number. Adds a fence test that bans the placeholder tokens across all generated bodies and proves a hostile question file reaches argv verbatim.
…r files Three runbooks still pasted free-text values into executable source after the INPUT_PATH fix (Graphify-Labs#4762): - labels = LABELS_DICT: Step 5 pasted the agent-built community-name dict into Python source; a label containing a quote or brace broke the literal and ran as code. - ingest('URL', ..., author='AUTHOR', contributor='CONTRIBUTOR'): the /graphify add URL and user names went into Python string literals. - graphify clone <url> and export obsidian --dir <path>: URLs and paths were pasted unquoted into shell lines, where &, ; or $() executes. All now travel through graphify-out/ sidecars the agent writes first: .graphify_labels.json (Step 5 reads it back), .graphify_add_url plus optional .graphify_add_author/.graphify_add_contributor (missing file maps to None), .graphify_clone_url/.graphify_clone_branch and .graphify_obsidian_dir. The PowerShell translator gains a $(cat FILE) -> Get-Content -Raw rule so the same sidecars work in the windows render. Adds a fence test banning the paste-the-value tokens across all generated bodies.
Summary
The skill instructs the agent to substitute
INPUT_PATHliterally into Pythonsource code, e.g.:
A scan path containing a single quote breaks out of the string literal. A
directory named
x');__import__('os').system('...')#- plausible via a clonedrepo - turns the pasted code into arbitrary Python execution on the user's
machine. The same applies to every other block that pastes
INPUT_PATH(
generate(...),detect_incremental(...)) and to the--watchcommand line,where an unquoted
INPUT_PATHwould be interpreted by the shell.Fix
The path now never enters code or shell text at all.
Step 1 (and each independent entry-point flow -
add,--update,--watch,--cluster-only) instructs the agent to write the resolved absolute path to afile named
.graphify_input_pathusing its file-writing tool. The agent writesthe exact bytes; no quoting, escaping, or parsing ever touches the value, so
delimiter collisions and quoting bugs are impossible by construction.
Every Python block then reads it back:
and the
--watchcommand takes it as a quoted substitution from the file:python3 -m graphify.watch "$(cat .graphify_input_path)" --debounce 3Why a file rather than an environment variable: an env var exported in Step 1
is invisible to blocks running in separate shells, breaks on runtimes without
persistent shell state, and silently expands to an empty argument in the watch
command. A file at the working root survives across shells and sessions, and
each entry-point flow writes its own target path (
addwrites./rawresolved to absolute before running
--update;--update,--watch, and--cluster-onlyinstructions say to write their target first).The
INPUT_PATHplaceholder is gone entirely - there is nothing left tosubstitute anywhere.
Files changed
graphify/skill.md- Step 1 instruction added; Steps 2, 4, 5 and the--updateblock read.graphify_input_path;--watchreads it viacat;add,--update,--watch, and--cluster-onlysections tell the agentto write their target path first
skills/graphify/skill.md- identical changes (the two copies carry thesame blocks)
Docs-only change; no package code touched.
Test
Docs-only, but the mechanism was exercised end to end:
x');__import__('os').system('touch /tmp/pwn')#writtento
.graphify_input_pathis read back intact,Path()resolves itcorrectly, and no payload executes.
trip - the case that would defeat any pasted-into-shell transport.
$(cat .graphify_input_path)passes the path to argv as a single quotedargument.
cross-block environment dependency.