Skip to content

Git hooks execute an interpreter path read from graphify-out/.graphify_python, a directory the README recommends committing #3265

Closed

Description

@AlexBloch-IA

Summary

The post-commit / post-checkout hooks written by graphify hook install resolve their
Python interpreter through a chain of probes. The second probe reads a path from a file
inside the working tree
— graphify-out/.graphify_python — and then executes that path.

The README ("Team setup") says
graphify-out/ "is meant to be committed to git so everyone on the team starts with a map",
and the recommended .gitignore block excludes only cost.json (and optionally cache/).
.graphify_python is therefore a file the documentation actively encourages committing.

Put together: cloning a repository that followed that advice, and running graphify hook install
in it, means the repository's own contents decide which executable your git hooks run on your
next commit. That is a decision that should belong to the machine, not to the checkout.

Where

From a hook generated by 0.9.53 (.husky/post-commit, same block in post-checkout):

_PINNED='/…/uv/tools/graphifyy/bin/python'
if [ -n "$_PINNED" ] && [ -x "$_PINNED" ] && "$_PINNED" -c "$_GFY_PROBE" 2>/dev/null; then
    GRAPHIFY_PYTHON="$_PINNED"
fi
# Second probe: read graphify-out/.graphify_python …
if [ -z "$GRAPHIFY_PYTHON" ]; then
    _GFY_PYTHON_FILE="graphify-out/.graphify_python"
    …
            GRAPHIFY_PYTHON="$_FROM_FILE"

The existing guards raise the bar but do not close it: the character allowlist rejects shell
metacharacters, not paths; -x and the find_spec('graphify') probe constrain what the
target must look like, not where it may come from or who wrote it.

Why the probe looks redundant

hook install already embeds _PINNED at install time, and the README documents that as the
mechanism ("graphify hook install embeds the current interpreter path directly into the hook
scripts at install time… If you reinstall or upgrade graphify, re-run graphify hook install").
On a normal setup _PINNED answers first and the working-tree probe never runs — so its cost
today is the trust it extends, not the problem it solves.

Suggested directions

  1. Drop the working-tree probe from the hooks and let _PINNED → command -v graphify cover it.
    Re-running hook install after an upgrade is already the documented fix for a stale pin.
  2. If the file has to stay as a fallback, source it from outside the repository
    (~/.config/graphify/ or ~/.graphify/), which survives uv tool reinstalls just as well
    without being checkout-controlled.
  3. Failing both, add graphify-out/.graphify_python to the recommended .gitignore in
    "Team setup", so the documented workflow stops publishing it.

Happy to send a PR for (1) or (2) if you have a preference.

Environment

graphify 0.9.53, macOS 15 (Darwin 25.4.0), uv tool install, hooks via husky.
No impact observed locally: across 34 repositories here graphify-out/ is git-ignored in all 34
and no graphify-out/ file is tracked. Reporting it as a property of the documented team
workflow rather than as an incident.

Activity

  1. AlexBloch-IA commented on Sep 1, 2026

    @AlexBloch-IA
    Author

    Follow-up: the same hook has a second working-tree-controlled input, with less validation than
    the interpreter probe above.

    The embedded Python block reads graphify-out/.graphify_root and uses its contents as the root
    that graphify then walks and parses:

    _out = os.environ.get('GRAPHIFY_OUT', 'graphify-out')
    _saved = Path(_out) / '.graphify_root'
    if _saved.exists():
        _txt = _saved.read_text(encoding='utf-8-sig').strip()
        if _txt:
            _root = Path(_txt)
    _rebuild_code(_root, changed_paths=changed, force=_force)

    There is no check that the value is absolute, and none that it resolves inside the repository —
    not even the character allowlist the .graphify_python probe has. The same _root is also used
    to build the output path a few lines later ((_root / _out) / 'reflections' / 'LESSONS.md' via
    _reflect), so it steers a write as well as a read.

    Two things make this worse than the interpreter path rather than better:

    1. It does not need an executable. The interpreter probe at least requires a file that is
      -x and satisfies find_spec('graphify'). This one takes any string that Path() accepts.
    2. The output is designed to be committed. Per "Team setup", graphify-out/ is meant to go
      into git. A rebuild rooted somewhere else writes what it found into graphify-out/, and the
      next ordinary git commit in that repository carries it to the remote. That turns a
      configuration file into a path for content to leave a machine by the repository's own
      normal workflow.

    Same suggested direction as the interpreter path: read it from outside the working tree, or —
    if it stays where it is — require it to resolve inside the repository root before using it,
    which is the invariant the field appears to be for in the first place.

    Same environment as above: graphify 0.9.53, macOS, hooks via husky. Again no local impact
    observed (graphify-out/ git-ignored in all 34 repositories here, nothing tracked); reporting
    it as a property of the documented workflow.

  2. added a commit that references this issue on Sep 12, 2026
    9e734a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions