Skip to content

scripts/shape_materialize.py and scripts/repo_shape.py: SonarCloud's two agentic-argument-injection findings (S8705, S8707) are false positives on main #119

Closed

Description

@brettheap

Lane: openreposhape-2 (openRepoShape-2)

What is wrong. Two OPEN SonarCloud SECURITY findings on main (cd57c4b),
both from the "agentic workflow" taint-rule family that treats a parsed CLI
argument as attacker-controllable input:

curl -s 'https://sonarcloud.io/api/issues/search?componentKeys=opensoft_openRepoShape&statuses=OPEN&impactSoftwareQualities=SECURITY&ps=10'
  1. pythonsecurity:S8705 "Agentic workflows should not be vulnerable to
    argument injection attacks" (cwe:20, cwe:88), issue key
    AaBnVm-FuRHRvnLUK9DV, sink scripts/shape_materialize.py:375-376.
  2. pythonsecurity:S8707 "Agentic workflows should not be vulnerable to path
    injection attacks" (cwe:20, cwe:22), issue key AaBkX77ohhjEdvdJLHrY,
    sink scripts/repo_shape.py:504.

I traced each sink back to its source (the flow SonarCloud's own JSON carries)
and read every line of validation sitting between. Both are false
positives
on this codebase, for two different reasons. Full trace below;
recommended SonarCloud disposition for each at the end of its section.


1. pythonsecurity:S8705 — command argument injection (scripts/shape_materialize.py:375)

The sink. scripts/shape_materialize.py:373-376:

def run(args: list[str], cwd: Path | None = None, capture: bool = True) -> str:
    check_program(args)
    proc = subprocess.run(args, cwd=str(cwd) if cwd else None,
                          capture_output=capture, text=True, check=False)

SonarCloud's flow, read from the issue JSON (flows[0].locations, source
to sink): update-shape.py:1387 args = build_parser().parse_args(argv) →
update-shape.py:1397 return cmd_apply(args) → update-shape.py:1121
def cmd_apply(args) -> int: → update-shape.py:1260
run(["git", "push", "-q", "-u", "origin", args.branch], cwd=root) →
shape_materialize.py:373 (run's own args parameter) → the sink at 375.
In words: --branch on update-shape.py apply is parsed, threaded through
cmd_apply, and lands as the trailing positional of a git push. If its
value began with - — --force, --upload-pack=… — git push would read
it as ITS OWN option, not as a refspec: CWE-88, argument injection, exactly
the shape SonarCloud is warning about.

Why it does not reach the sink unsanitized. update-shape.py:1260's
args.branch is not used raw. It is threaded through
commit_on_branch(root, args.branch, …) first (update-shape.py:1255-1257,
called before the run(["git", "push", …]) line SonarCloud flags), and
commit_on_branch's FIRST statement, unconditionally, on every call, is:

# update-shape.py:1070
checked_value("--branch", branch)

checked_value is defined in scripts/repo_shape.py:1330-1359 (one of this
task's two assigned files) and is this codebase's existing, deliberate,
CWE-88 guard:

def checked_value(what: str, value, pattern: re.Pattern = SAFE_ARG_RE) -> str:
    """Validate one caller-supplied value BEFORE it becomes a command argument.

    ARGUMENT INJECTION IS THE THREAT, not shell injection: every command here
    is a list with `shell=False`, so there is no shell to inject into — but
    `git` reads its own arguments, and a `--tracking-branch` of
    `--upload-pack=…` is a command, not a branch. A value that begins with `-`
    is therefore refused outright, and the rest must be spellable as a branch
    name, a path, a repository name or a commit.

    The values that reach here come from a command line, from `project.yaml`
    and — in `adopt-project.py` — from an adoption plan that an AI assistant
    may have written. The last of those is exactly why this is a check in the
    code rather than a note in the README.
    """
    text = str(value)
    if text.startswith("-") or not text.strip() or not pattern.fullmatch(text):
        raise Refusal("unsafe-value", …)
    return text

commit_on_branch calls it before doing anything else with branch (line
1070), then only afterwards does its own tracking/current_branch/
branch_exists bookkeeping (1071-1094) and the caller-side push (1260) — so
args.branch cannot reach run(["git", "push", …, args.branch]) without
first surviving checked_value, on every path through the function; there is
no branch of this code that skips it.

This is exactly the kind of guard the task brief points at as the hallmark of
a REAL, worth-hardening fix ("an argument that should be validated at the
argparse boundary") — it already exists here, and it is not a one-off:
checked_value is applied to essentially every value this codebase puts on a
git/gh command line — --upstream, --at, --branch in update-shape.py;
--project, --tracking-branch, --spec-path, --code-path, --org,
--pin-owner, --id, plan-file values in adopt-project.py;
--tracking-branch, --id in scaffold-project.py; --leg, --to, the
leg's own recorded branch/repository in bump-leg.py; --family, --org,
--tracking-branch, --id, --member, --at in family.py (grep
checked_value( across the repo for the full list). SonarCloud's generic
taint engine does not recognise this bespoke, in-house validator as a
sanitizer — it has no annotation or built-in rule saying "a call to
checked_value neutralises everything after it" — so it keeps reporting the
flow through to the sink even though the value is provably safe by the time
it gets there.

Existing test coverage of the exact payload SonarCloud is worried about.
tests/test_windows_paths.py::test_a_path_that_is_not_one_is_still_refused
is already parametrized with the canonical argument-injection payload:

@pytest.mark.parametrize("value", [
    "-" + WINDOWS_REMOTE,           # git would read it as its own option
    "--upload-pack=touch pwned",
    …
])
def test_a_path_that_is_not_one_is_still_refused(value):
    with pytest.raises(Refusal) as raised:
        checked_value("--local-remote-dir", value, SAFE_PATH_RE)
    assert raised.value.code == "unsafe-value"

Ran on this lane's worktree today: python3 -m pytest tests/test_windows_paths.py -q
→ 38 passed in 2.99s, this case included.

Empirical confirmation, in a scratch repo, of the SPECIFIC path SonarCloud's
flow names — update-shape.py's own checkout -b step, which runs before the
flagged push, on a value SonarCloud's flow implies could be --force:

$ git checkout -q -b --force
fatal: '--force' is not a valid branch name

git itself refuses to create a ref that looks like an option — a rule
git-check-ref-format(1) states outright ("They cannot begin with a hyphen
-"). So even setting checked_value aside, a value shaped like --force
never survives to become the CURRENT branch in the first place, and
update-shape.py's push always names either that just-created branch or
(when --branch names the branch already checked out) current_branch(root)
— itself always a pre-existing, therefore already-valid, ref name. There is
no path from a parsed --branch to the flagged subprocess.run call that
skips both gates.

Disposition recommendation: False Positive. Comment for the transition:
"args.branch is validated by checked_value("--branch", branch)
(scripts/repo_shape.py:1330, called unconditionally at the top of
update-shape.py's commit_on_branch, before the flagged git push at
update-shape.py:1260) and, redundantly, by git's own ref-name rules at the
checkout -b this tool always runs first. A value shaped like --force or
--upload-pack=… is refused (Refusal: unsafe-value) long before it can
reach subprocess.run. Existing regression coverage:
tests/test_windows_paths.py::test_a_path_that_is_not_one_is_still_refused."

No PR opened for this finding; no code touched.


2. pythonsecurity:S8707 — path injection (scripts/repo_shape.py:504)

The sink. scripts/repo_shape.py:502-504:

def load_yaml(path: Path) -> Any:
    try:
        text = Path(path).read_text(encoding="utf-8")

SonarCloud's flow carries three independent paths to this one sink, all
with the same shape — a --project/--policy CLI argument, of type=Path,
read straight into load_yaml:

  • scripts/validate-repository-naming.py: --project (defined at line 275,
    type=Path, default=None, "read the leg names… from a project.yaml
    manifest") → main()'s _targets_from_project(policy, args.project, …)
    (line 340-341) → load_yaml(path) (line 228).
  • templates/family-root/scripts/validate-family.py: --policy (line 399,
    type=Path, default=None) → policy_path = args.policy or (root / "contracts" / "repository-naming.yaml") (lines 437-438) →
    NamingPolicy.load(policy_path) (line 439) → load_yaml (repo_shape.py:952).
  • templates/assembly-root/scripts/validate-manifest.py: --policy (line
    406), identical shape (lines 423-424).

Why this is not path traversal. In every one of the three flows, the
"tainted" value is a configuration-style CLI argument whose entire, stated
purpose is letting the operator point a LOCAL, single-operator validator CLI
at an arbitrary file on their OWN filesystem — a project.yaml to validate,
or an alternate naming-policy file to validate against (its docstring:
--project, "read the leg names, their roles and the declared neutral-product
pins from a project.yaml manifest"; the --policy default of
root/contracts/repository-naming.yaml is itself just a convenience default,
not a boundary). There is no sandbox, no lesser-privileged execution context
and no server boundary here for a path to escape: these tools run with the
invoking operator's own OS permissions, reading a file that operator could
equally cat directly — a ../../../etc/passwd given to --policy reads
exactly what cat /etc/passwd run by the same user would, nothing more.
There is no "expected root" the naming-policy or project-manifest path is
supposed to be confined to; being pointed at any file the operator names is
the feature, in every one of AGENTS.md's own descriptions of this family of
command (update-shape.py check --root <path-to-the-project>,
validate-repository-naming.py --project <path>, and so on throughout).

This is confirmed by this codebase's own established practice: checked_value
(above) is the deliberate, in-house guard this codebase uses when a value
genuinely needs constraining before it reaches a command line, and it is
POINTEDLY not a path-confinement mechanism — its own docstring says so
("pattern is SAFE_PATH_RE for a value that is a FILESYSTEM PATH the
operator named: … refusing [a colon or backslash] would refuse the platform
rather than the threat"), and SAFE_PATH_RE
(scripts/repo_shape.py:102, ^(?:[A-Za-z]:)?[A-Za-z0-9._/@+~ \\-]{1,4096}$)
freely admits . and /, so a ../../.. path fullmatches it same as any
other. Where this codebase DOES apply checked_value to a path-shaped value
(e.g. --local-remote-dir in siblings.py), it still only refuses a leading
-, control characters and non-path shapes — never traversal. Nowhere in this
codebase does a --project/--policy/--root argument get confined to a
root, which is consistent design, not a gap: these are meant to roam free by
the same standard that lets checked_value leave path CONTENT unconstrained
everywhere else it is used.

Disposition recommendation: Won't Fix / Accept. Comment for the
transition: "--project/--policy (and the --root each validator resolves
against) are operator-chosen configuration paths for a local, single-operator
CLI tool, by design — the whole point of the flag is to let the operator name
an arbitrary file to validate. There is no privilege boundary or sandbox for a
path to escape (the tool already runs with the operator's own filesystem
access), and this codebase's own path-safety convention (checked_value /
SAFE_PATH_RE, scripts/repo_shape.py:102,1330) deliberately leaves path
CONTENT — including .. — unconstrained everywhere it is used, confirming
this is accepted, intentional behaviour rather than an oversight."

No PR opened for this finding either; no code touched.


Scope note. Both scripts/repo_shape.py and
scripts/validate-repository-naming.py are on the digest-pinned-copy list;
nothing in either was edited investigating this (read-only trace), so there is
no re-pin to owe. update-shape.py, shape-doctor.py and scripts/family.py
were read for the trace only, per this fan-out's instruction to leave them for
PR #112.

What would fix it. Nothing in this codebase. The action here is marking
both SonarCloud issues with the dispositions above (AaBnVm-FuRHRvnLUK9DV →
False Positive, AaBkX77ohhjEdvdJLHrY → Won't Fix / Accept), which is Brett
Heap's act in the SonarCloud UI — this lane only relays the trace and the
recommendation.

Activity

  1. brettheap commented on Sep 11, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-11T20:32Z) CLAIMED — session 3b1ab8cf, on Brett Heap's word 'go, fan out on all of it'. Branch fix/sonar-security-argument-and-path-taint, worktree ~/projects/openRepoShape--sonar-security on Eagle, from origin/main cd57c4b. Scope: trace SonarCloud pythonsecurity:S8705 (scripts/shape_materialize.py:375) and S8707 (scripts/repo_shape.py:504) to source and dispose of each honestly; both traced to false positives (checked_value already guards S8705's argv shape; S8707's paths are intentionally operator-chosen with no expected root), so no PR follows — this issue records the trace and the recommended SonarCloud disposition for Brett to apply.

  2. brettheap commented on Sep 11, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-11T20:35Z) ASSESSED, NO CODE CHANGE — both findings traced in the body above: S8705 (shape_materialize.py:375) is a False Positive because checked_value("--branch", …) refuses a leading - before the value reaches git push, and git's own ref rules refuse it at checkout -b first; S8707 (repo_shape.py:504) is Won't Fix / Accept because --project/--policy exist to point a single-operator local validator at any file the operator names. Marking the two SonarCloud issues (keys in the body) is Brett Heap's act in the SonarCloud UI. Claim RELEASED; issue left open only for that act.

  3. brettheap commented on Sep 11, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-11T21:27Z) MARKED IN SONARCLOUD on Brett Heap's word 'mark 119 in sonar' — AaBnVm-FuRHRvnLUK9DV (pythonsecurity:S8705, scripts/shape_materialize.py:375) → False Positive; AaBkX77ohhjEdvdJLHrY (pythonsecurity:S8707, scripts/repo_shape.py, now line 510 after #121) → Accepted. Set through the SonarQube MCP connector from this session; verified on the SonarCloud API afterwards: both read RESOLVED, open SECURITY findings on main now 0. Both are reversible with 'reopen'. The reasoning stays here, in the body above; SonarCloud holds only the status. Object complete.

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