Skip to content

fix(source-control): babysit-merge wrapper's --allow-unpinned-head guard misses the =value spelling #1522

Closed

Description

@kyle-sexton

Found during independent verification of #1405. Pre-existing on main — not introduced by that PR.

The invariant

plugins/source-control/bin/source-control-babysit-merge states that it is the allow-rule boundary:

this wrapper is the allow-rule boundary and must not depend on the interpreter behind it

It enforces that by refusing --allow-unpinned-head and every long-option prefix of it. That part works — verified exhaustively:

--allow-unpinned-head            rc=2   ... is not permitted through the wrapper
--allow-unpinned-hea             rc=2   ... is not permitted through the wrapper
--allow-unpinned                 rc=2   ... is not permitted through the wrapper
--allow-unpin                    rc=2   ... is not permitted through the wrapper
--allow                          rc=2   ... is not permitted through the wrapper
--allo / --all / --al / --a      rc=2   ... is not permitted through the wrapper

The gap

The guard is a prefix test:

[[ "$arg" == --a* && "--allow-unpinned-head" == "$arg"* ]]

--allow-unpinned-head=true does not satisfy "--allow-unpinned-head" == "$arg"*, because $arg carries the =true suffix. So the wrapper passes it through:

--allow-unpinned-head=true       rc=2   usage: babysit_merge.py [-h] [--allowed-owners ALLOWED_OWNERS]

It is still refused — but by argparse, not by the wrapper. That is exactly the dependency the wrapper says it must not have.

Why it is safe today and why that is not enough

The flag is store_true, so argparse rejects an =value spelling outright. The refusal is real. But it is incidental: the moment that flag takes a value — or an equivalent guarded flag is added that does — the wrapper silently stops being the boundary, and nothing fails loudly to say so. The guard would keep passing its existing tests while no longer guarding.

This is a defense-in-depth invariant on the merge path, which is why it is worth closing rather than noting.

Suggested fix

Strip any =value suffix before the prefix comparison, so the guard tests the option name rather than the whole argument. Add cases for --allow-unpinned-head=true, --allow-unpinned=1, and a bare --allow-unpinned-head to the wrappers own test suite, asserting the refusal comes from the wrapper (its exact refusal message) and not from an argparse usage error — asserting only on exit code would pass today for the wrong reason.

Related

No linked issue. Found while verifying #1405.

Activity

  1. added
    area: security
    status: ready
    agent-ready
    on Jul 26, 2026
  2. added theissue type on Jul 26, 2026
  3. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Triage

    Verification: confirmed by direct source read. plugins/source-control/bin/source-control-babysit-merge
    (current main) carries exactly the guard the issue quotes:
    [[ "$arg" == --a* && "--allow-unpinned-head" == "$arg"* ]]. This is a pure prefix test in both
    directions — "--allow-unpinned-head" == "$arg"* requires the full literal to start with $arg,
    which fails the moment $arg carries an =value suffix (--allow-unpinned-head=true is not a
    prefix-match target of the bare flag string). The guard is bypassed at the wrapper layer for that
    spelling; the issue's own repro is correct that argparse (not the wrapper) is what actually refuses
    it today, because the flag is store_true and argparse rejects =value on a store_true flag
    regardless. That safety net is real but incidental — verified only one guarded flag exists in this
    wrapper today (--allow-unpinned-head; no other --allow* guard is present), so the exposure is
    currently exactly what the issue describes: dormant unless the guarded flag (or a future one) starts
    taking a value.

    Classification

    • Type: Bug (native Issue Type set).
    • Priority: priority: medium (already applied, kept as-is) — defense-in-depth invariant on the
      merge path, currently safe in practice (argparse still refuses the bypassed spelling today), so not
      an active exploit; real value fixing it, no hard deadline.
    • Target state: briefed, delegable. The issue specifies the exact fix (strip an =value suffix
      before the prefix comparison) and the exact test additions, with no open design question.

    Agent Brief

    Type: Bug
    Summary: The source-control-babysit-merge wrapper's guard against --allow-unpinned-head (and
    prefixes of it) does not recognize the =value spelling of the flag, so that spelling passes through
    the wrapper unrefused — currently caught only incidentally, by the downstream interpreter's own
    argument parser rejecting an =value on a boolean flag, which is exactly the interpreter dependency
    the wrapper's own stated purpose says it must not have.

    Current behavior: The wrapper's guard is a plain string-prefix comparison between the raw
    argument and the guarded flag's literal text. An argument that matches the guarded flag but carries
    an =value suffix (e.g. --allow-unpinned-head=true) does not satisfy the prefix comparison in
    either direction, so the guard's loop passes it through to the wrapped program unrefused.

    Desired behavior: The guard recognizes and refuses the guarded flag's =value spelling itself,
    with the same explicit refusal message and exit behavior as every other refused form — never relying
    on the wrapped program's own argument parser to reject it. Stripping any =value suffix before the
    prefix comparison (so the comparison tests the option name, not the whole argument-plus-value token)
    achieves this without weakening the existing prefix-family refusal.

    Key interfaces:

    • The wrapper's argument-refusal loop — the guard that walks "$@" and refuses the protected flag
      and its prefixes.

    Acceptance criteria:

    • --allow-unpinned-head=true (and other =value spellings of the guarded flag or its
      prefixes, e.g. --allow-unpinned=1) is refused by the wrapper itself, not by the wrapped
      program's argument parser.
    • A test asserts the refusal comes from the wrapper's own exact refusal message and exit
      behavior for the =value spellings — asserting only a non-zero exit code would pass today for
      the wrong reason (the wrapped program's parser, not the wrapper) and would not catch a
      regression.
    • The existing bare-flag and prefix-family refusal cases (--allow-unpinned-head,
      --allow-unpinned-hea, --allow, etc.) still refuse correctly — the fix must not narrow the
      existing coverage.

    Out of scope:

    • Any change to the wrapped program's own argument parsing.
    • Guarding any additional flag beyond --allow-unpinned-head — none exists in this wrapper today.

    Labels applied: agent-ready (autonomous-eligible role label), status: ready. priority: medium,
    area: security, work-class: scoped unchanged. Role label resolved from tracker defaults —
    .work-item-tracker.json carries no role_labels remap.

    Related: #1405 (the PR whose independent verification surfaced this pre-existing gap).

  4. self-assigned this
    on Jul 26, 2026
  5. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor
    No description provided.
  6. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during work-loop execution.

    Claimed and fixed via #1539 (branch fix/1522-babysit-merge-wrapper-equals-value-bypass). Reproduced the --allow-unpinned-head=true bypass on unmodified origin/main first (red), confirmed the wrapper let it through to argparse rather than refusing it itself, then fixed by stripping a --flag=value tail before the prefix comparison. New tests assert the wrapper's own refusal text (not just exit code, since exit 2 is shared with argparse's own errors on this path) for --allow-unpinned-head=true, --allow-unpinned=1, and --allow-unpinned-hea=1, plus no-over-refusal rows for sibling --allow* flags. Full detail and test evidence in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: securitystatus: ready

Type

Fields

No fields configured for Bug.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions