Skip to content

fix(skill): stop substituting the scan path into code and commands - #4762

Closed
danikdanik wants to merge 2 commits into
Graphify-Labs:mainfrom
danikdanik:fix/skill-path-transport-env
Closed

danikdanik wants to merge 2 commits into
Graphify-Labs:mainfrom
danikdanik:fix/skill-path-transport-env

Conversation

@danikdanik

Copy link
Copy Markdown

Summary

The skill instructs the agent to substitute INPUT_PATH literally into Python
source code, e.g.:

result = detect(Path('INPUT_PATH'))

A scan path containing a single quote breaks out of the string literal. A
directory named x');__import__('os').system('...')# - plausible via a cloned
repo - 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 --watch command line,
where an unquoted INPUT_PATH would 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 a
file named .graphify_input_path using its file-writing tool. The agent writes
the 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:

SCAN_ROOT = Path('.graphify_input_path').read_text().rstrip('\n')
result = detect(Path(SCAN_ROOT))

and the --watch command takes it as a quoted substitution from the file:

python3 -m graphify.watch "$(cat .graphify_input_path)" --debounce 3

Why 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 (add writes ./raw
resolved to absolute before running --update; --update, --watch, and
--cluster-only instructions say to write their target first).

The INPUT_PATH placeholder is gone entirely - there is nothing left to
substitute anywhere.

Files changed

  • graphify/skill.md - Step 1 instruction added; Steps 2, 4, 5 and the
    --update block read .graphify_input_path; --watch reads it via cat;
    add, --update, --watch, and --cluster-only sections tell the agent
    to write their target path first
  • skills/graphify/skill.md - identical changes (the two copies carry the
    same blocks)

Docs-only change; no package code touched.

Test

Docs-only, but the mechanism was exercised end to end:

  • A directory named x');__import__('os').system('touch /tmp/pwn')# written
    to .graphify_input_path is read back intact, Path() resolves it
    correctly, and no payload executes.
  • A directory whose name contains an interior newline survives the same round
    trip - the case that would defeat any pasted-into-shell transport.
  • $(cat .graphify_input_path) passes the path to argv as a single quoted
    argument.
  • A block reading the file in a fresh shell works, confirming there is no
    cross-block environment dependency.

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.
@github-actions

Copy link
Copy Markdown

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.

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_build.py — full-run-safety
  • tests/test_cache.py — full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cluster.py — full-run-safety
  • tests/test_confidence.py — full-run-safety
  • tests/test_detect.py — full-run-safety
  • tests/test_export.py — full-run-safety
  • tests/test_extract.py — full-run-safety
  • tests/test_hooks.py — full-run-safety
  • tests/test_hypergraph.py — full-run-safety
  • tests/test_ingest.py — full-run-safety
  • tests/test_languages.py — full-run-safety
  • tests/test_multilang.py — full-run-safety
  • tests/test_pipeline.py — full-run-safety
  • tests/test_report.py — full-run-safety
  • tests/test_security.py — full-run-safety
  • tests/test_semantic_similarity.py — full-run-safety
  • tests/test_serve.py — full-run-safety
  • tests/test_validate.py — full-run-safety
  • tests/test_watch.py — full-run-safety
  • tests/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".
@danikdanik

Copy link
Copy Markdown
Author

Addressed an external review pass in 40d957ff:

  • Empty .graphify_input_path no longer mis-scans CWD — all read sites now validate non-empty + is_dir() and fail loudly; the --watch command got a [ -d ... ] preflight guard.
  • Added .graphify_input_path to Step 9 cleanup and to .gitignore (it holds a machine-local absolute path).
  • Fixed the --cluster-only wording ("Step 5 reads it", not "Steps 5–9"), corrected the "never in a command line" overstatement (watch reads it via a quoted $(cat ...)), and added encoding='utf-8' to all read_text() calls on the file.

safishamsi added a commit that referenced this pull request Nov 8, 2026
…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]>
safishamsi added a commit that referenced this pull request Nov 8, 2026
…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]>
@safishamsi

Copy link
Copy Markdown
Member

Thanks for catching this and proposing the fix, @danikdanik — it's a real RCE: a scan root whose name carried a quote or $(...) broke out of the Path('INPUT_PATH') string literal in the runbook's Python blocks. Your branch was based on a pre-skillgen fork and edited the generated skill.md directly, so it couldn't land as-is (the skill files are generated from tools/skillgen/fragments/ and guarded by --check/--monolith-roundtrip). I re-implemented the same fix natively in the fragments: every Python block now reads the resolved scan root from the trusted graphify-out/.graphify_root sidecar instead of substituting the path, across the assembled hosts and the Aider/Devin monoliths. Shipped in 0.9.104 (now on PyPI), credited to you in the changelog. SPEC_PATH (the skill's own install path, not attacker-controlled) is tracked as a follow-up. Closing in favour of that landed fix.

@safishamsi safishamsi closed this Nov 8, 2026
Deepjyoti-Sarmah added a commit to Deepjyoti-Sarmah/graphify that referenced this pull request Nov 10, 2026
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.
safishamsi added a commit that referenced this pull request Nov 14, 2026
…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]>
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
danikdanik added a commit to danikdanik/graphify that referenced this pull request Nov 18, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants