Skip to content

guardrails: alias_launch_dir misses a nested alias when show-prefix is empty under locating globals (live bypass on main) #1553

Closed

Description

@kyle-sexton

alias_launch_dir returns the caller's composed directory — not the repository top level — when rev-parse --show-prefix is empty and explicit locating globals are present. A nested alias is then looked up in the invoking directory, misses, and the guard allows, while real git resolves the alias in the located repository and performs a non-canonical commit.

Reproducer shape

Invoked from a non-repository directory, with locating globals supplied and a repeated --git-dir so last-wins applies, chaining to a persisted alias that expands to a non-canonical commit.

Ground truth: real git commits. The guard returns 0.

Why the current branch is reached

From block-noncanonical-commit.sh, main's own documentation of the four cases:

  • prefix EMPTY under explicit locating globals: git does not chdir, so the body runs in the caller's composed directory, returned LITERALLY for git to apply its own path semantics downstream.

The premise is correct about where the body runs. The gap is what the alias lookup needs: git config --get alias.<name> evaluated with those locating globals reads the located repository's config, not the invoking directory's. So returning the invoking directory literally is right for path semantics and wrong for alias resolution, and the nested lookup misses.

On this shape the invoking directory is not a work tree at all, so the miss is total and the chain is allowed without its terminal command ever being classified.

Constraints on the fix — please do not regress these

The current implementation is better than the earlier simpler one on three axes that must survive any change here:

  1. %q-encoded cache keys. Each argv word is printf '%q'-encoded before joining. A space-joined key collides --git-dir 'X --work-tree' with --git-dir X --work-tree, so the second segment receives the first's answer — a wrong repository, decided fail-open. Keep the encoding.
  2. Byte-exact rev-parse reads, one call per field. Only git's single trailing LF is stripped, so a path with an interior or trailing newline (or a legitimate trailing CR) is not corrupted, and an interior newline in one field cannot be read as the boundary into the next. Keep separate calls; do not combine --show-toplevel --show-prefix and split on a newline.
  3. The --show-prefix branch structure itself, which is what makes -C ., link/.., and a subdirectory all collapse to one identity so the shell-alias cycle key can detect a repeat instead of walking forever.

The narrow question is what the prefix-empty-with-locating-globals branch should return for alias-lookup purposes, which may need to be a different value from what it returns for path composition. Splitting those two consumers is likely the smallest correct change.

Provenance and confidence

Surfaced while evaluating whether #1085 still had anything to contribute after #1503 landed. It is the one row where #1085's simpler alias_launch_dir — which returned the top level unconditionally — blocked and the current implementation does not.

Verified against real git with commit-count ground truth rather than exit codes alone, and the code path was independently confirmed to match main's documented behavior for this case. Flagging explicitly that the current behavior is deliberate and documented, so this needs confirmation by someone who owns that design before it is treated as settled — the reproducer may also warrant a Linux run, since it was exercised on Git Bash.

Related: #1503 (the landed fix), #1501 (persisted-alias lookup drops locating globals — adjacent, also an alias-resolution-versus-location split), #1500, #1502, #1486.

Activity

  1. added
    needs-triage
    area: security
    on Jul 26, 2026
  2. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Triage: verified → briefed, human-gated

    Category: Bug (fail-open in a security-adjacent guard), guardrails.

    Verification — accepted from the reporter's recorded evidence, deliberately NOT re-reproduced.
    The reproducer is an exotic multi-step shape: invocation from a non-repository directory, explicit
    locating globals with a repeated --git-dir so last-wins applies, chaining to a persisted alias
    that expands to a non-canonical commit. The reporter verified it against real git using
    commit-count ground truth rather than exit codes alone, and independently confirmed the code
    path matches the guard's own documented behavior for the prefix-empty-under-locating-globals case.
    Re-running it here would mean constructing a repository and alias state to drive a real commit
    through a guard bypass; the recorded evidence is stronger than what an unattended re-run would add,
    so provenance is recorded as accepted rather than reproduced.

    The mechanism is coherent on inspection: alias_launch_dir returns the caller's composed directory
    for path-semantics reasons, but git config --get alias.<name> evaluated with those same locating
    globals reads the located repository's config. One return value is serving two consumers with
    different correct answers, and the alias lookup gets the wrong one.

    Redundancy check. Searched the guard for an existing split between path-composition and
    alias-lookup directory resolution: there is none — one function serves both. The adjacent prior
    findings the report names (the landed fix for this branch structure, and the persisted-alias lookup
    dropping locating globals) are distinct defects in the same resolution area, not duplicates of this
    one.

    Why human-gated — the reporter asks for it explicitly. The body states that the current
    behavior is deliberate and documented, and that this "needs confirmation by someone who owns
    that design before it is treated as settled." An autonomous agent cannot supply that confirmation:
    the question is whether the documented premise was intended to cover alias resolution, which is
    design intent, not a fact recoverable from the code.

    Constraints the fix must not regress — carried forward from the report, and binding on whoever
    takes it:

    1. %q-encoded cache keys — a space-joined key collides distinct argv shapes and hands one segment
      another's answer, deciding the wrong repository fail-open.
    2. Byte-exact rev-parse reads, one call per field, so a path containing a newline or trailing CR
      is neither corrupted nor misread as a field boundary. Do not combine the two queries and split.
    3. The --show-prefix branch structure itself, which collapses equivalent spellings to one identity
      so the shell-alias cycle key can detect a repeat instead of walking forever.

    The narrow question is what that branch should return for alias-lookup purposes, which may need
    to differ from what it returns for path composition; splitting the two consumers is the likely
    smallest correct change.

    Open, unverified: the reproducer was exercised on Git Bash only. The report flags that a Linux
    run may be warranted.

    Labels applied: priority: high (a live guard bypass on the default branch, and the guard is a
    security control — held below the top tier because exploitation requires an exotic invocation shape
    and the guard is defense-in-depth, not the sole control), needs-human; existing area: security
    retained; raw marker cleared.

  3. added
    needs-human
    and removed
    needs-triage
    on Jul 26, 2026
  4. added theissue type on Aug 13, 2026
  5. kyle-sexton commented on Aug 13, 2026

    @kyle-sexton
    MemberAuthor

    Frontier disposition (drain session)

    Ruling: Classified for drain orchestration.

    Human gate cleared for classification; implementation authority follows the ruling.

  6. kyle-sexton commented on Aug 13, 2026

    @kyle-sexton
    MemberAuthor

    Frontier consensus (binding) — drain bc-f3123271

    Paired with #1500. Same chokepoint design: locating context propagates across ! hops; prefix-empty path composition unchanged for cycle identity. IMPLEMENT_NOW with #1500.

  7. kyle-sexton commented on Aug 13, 2026

    @kyle-sexton
    MemberAuthor

    Fixed on #2562 (cursor/guardrails-alias-chokepoint-1500-d116, guardrails 0.28.21).

    The #1553 reproducer shape (persisted alias chain, repeated --git-dir last-wins, invoked outside any work tree) is now BLOCKED — alias lookup replays locating globals through repo_git_probe while alias_launch_dir continues returning the caller's composed directory for path composition only.

    Constraints preserved: %q cache keys, byte-exact per-field rev-parse, and the --show-prefix branch structure for cycle-key collapse.

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

    area: securityneeds-human

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions