abhigyanpatwari/GitNexus · error · ValueError

clone contains unsafe or unbounded remote metadata

Error message

clone contains unsafe or unbounded remote metadata

What it means

`git remote` output is bounded (<=MAX_CLONE_REFS entries) and each name must match [A-Za-z0-9][A-Za-z0-9._/-]{0,255} with no '..'. The guard prevents argument injection into `git remote remove <name>` and bounds the deletion loop. Names failing the regex or exceeding the count abort.

Source

Thrown at eval/workflow_bench/oracle_assets.py:374

    refs_output = _git_checked(
        root,
        ["for-each-ref", f"--count={MAX_CLONE_REFS + 1}", "--format=%(refname)"],
        timeout=60,
    )
    refs = refs_output.splitlines() if refs_output else []
    if len(refs) > MAX_CLONE_REFS:
        raise ValueError(f"clone has more than {MAX_CLONE_REFS} references; refusing incomplete sanitization")
    if any(not ref.startswith("refs/") or any(character.isspace() for character in ref) for ref in refs):
        raise ValueError("clone contains an unsafe reference name")
    for ref in refs:
        _git_checked(root, ["update-ref", "--no-deref", "-d", ref], timeout=60)

    remote_output = _git_checked(root, ["remote"], timeout=60)
    remotes = remote_output.splitlines() if remote_output else []
    if len(remotes) > MAX_CLONE_REFS or any(
        re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9._/-]{0,255}", remote) is None or ".." in remote for remote in remotes
    ):
        raise ValueError("clone contains unsafe or unbounded remote metadata")
    for remote in remotes:
        _git_checked(root, ["remote", "remove", remote], timeout=60)

    _git_checked(
        root,
        ["reflog", "expire", "--expire=now", "--expire-unreachable=now", "--all"],
        timeout=60,
    )
    git_dir = root / ".git"
    for pseudo_ref in (
        "AUTO_MERGE",
        "BISECT_START",
        "CHERRY_PICK_HEAD",
        "FETCH_HEAD",
        "MERGE_HEAD",
        "ORIG_HEAD",
        "REBASE_HEAD",
        "REVERT_HEAD",

View on GitHub (pinned to d540b00184)

Solutions

  1. Inspect `git -C <clone> remote -v` and remove unneeded remotes: `git -C <clone> remote remove <name>`.
  2. Re-clone from a single trusted origin so only 'origin' is present.
  3. If a remote name is malformed, edit .git/config directly or re-clone.
Defensive patterns

Strategy: validation

Validate before calling

import re
from pathlib import Path
from eval.workflow_bench.oracle_assets import MAX_CLONE_REFS
from eval.workflow_bench.process_control import run_checked

_REMOTE = re.compile(r"[A-Za-z0-9][A-Za-z0-9._/-]{0,255}")
def remotes_are_safe(clone: Path) -> bool:
    out = run_checked(["git", "-C", str(clone), "remote"], timeout=60).stdout_tail.strip()
    names = out.splitlines()
    if len(names) > MAX_CLONE_REFS:
        return False
    for n in names:
        if _REMOTE.fullmatch(n) is None or ".." in n:
            return False
    return True

Type guard

def is_unsafe_remote(exc: BaseException) -> bool:
    return isinstance(exc, ValueError) and "unsafe or unbounded remote metadata" in str(exc)

Try / catch

try:
    oracle_assets.sanitize_clone_for_hidden_oracles(clone)
except ValueError as exc:
    quarantine(clone)
    raise AbortTask(str(exc)) from exc

Prevention

When it happens

Trigger: Triggered when the clone has more than 1024 remotes, or any remote name contains shell/argument-special characters, whitespace, leading dot, or '..'.

Common situations: A clone with many added remotes from a migration; a crafted clone whose .git/config defines a remote name with newlines or dashes positioned to break `git remote remove`.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/6c92ce94c48e0ab7. Report an issue: GitHub.