Skip to content

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

5.3 KB
Raw Blame
id: git-force-push-to-protected
version: 2
title: Force-push directed at a protected branch
description: >
  A git push with --force, --force-with-lease, -f, or a leading +
  refspec targets a protected branch (main, master, develop,
  release/*, production), either by name or as the destination of
  a src:dst refspec such as HEAD:main or x:refs/heads/main. Force-pushing a protected branch can
  rewrite the canonical project history, drop commits, or land
  unreviewed code into the production line. From an agent session
  this is almost always unauthorized and indicates either an
  attacker forcibly overwriting the protected history or a
  misconfigured agent bypassing the branch-protection gate. The
  rule requires BOTH a force flag (--force, --force-with-lease, -f,
  or + refspec) AND a target in the protected-branch list. A force
  push to a feature branch (which git itself permits and many teams
  allow) does not fire; nor does an ordinary push to main.
severity: high
status: experimental
posture: detect
taxonomy:
  beacon_category: source-control
  owasp_llm: LLM03

match: >
  e.event.action == "command.executed" && (
    e.command.command.matches("(?i)(^|[;&|]\\s*|\\bsudo\\s+)\\s*git\\b[^;&|]*\\bpush\\b[^;&|]*(\\s--force(-with-lease)?\\b|\\s-f\\b)[^;&|]*(?:^|\\s|:)(?:refs/heads/)?(main|master|develop|production|release/[^\\s;&|]+)(?:\\s|$)") ||
    e.command.command.matches("(?i)(^|[;&|]\\s*|\\bsudo\\s+)\\s*git\\b[^;&|]*\\bpush\\b[^;&|]*(?:^|\\s|:)(?:refs/heads/)?(main|master|develop|production|release/[^\\s;&|]+)(\\s[^;&|]*)?(\\s--force(-with-lease)?\\b|\\s-f\\b)") ||
    e.command.command.matches("(?i)(^|[;&|]\\s*|\\bsudo\\s+)\\s*git\\b[^;&|]*\\bpush\\b[^;&|]*\\+\\s*([^\\s;&|:]*:)?(?:refs/heads/)?(main|master|develop|production|release/[^\\s;&|]+)(?:\\s|$)")
  )

emit:
  reason: "Force-push directed at a protected branch (main / master / develop / production / release/*)"

tests:
  - name: force_push_to_main
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push --force origin main" }
        session: { id: s1 }
  - name: force_push_to_master_f
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push -f origin master" }
        session: { id: s1 }
  - name: force_push_force_with_lease_to_main
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push --force-with-lease origin main" }
        session: { id: s1 }
  - name: force_push_to_release_branch
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push --force origin release/v1.2" }
        session: { id: s1 }
  - name: plus_refspec_to_main
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push origin +main" }
        session: { id: s1 }
  - name: force_push_branch_then_force
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push origin main --force" }
        session: { id: s1 }
  - name: force_push_head_refspec_to_main
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push --force origin HEAD:main" }
        session: { id: s1 }
  - name: force_push_full_ref_to_master
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push -f origin my-fix:refs/heads/master" }
        session: { id: s1 }
  - name: plus_refspec_head_to_main
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "git push origin +HEAD:main" }
        session: { id: s1 }
  - name: force_push_main_to_feature
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git push --force origin main:feature/x" }
        session: { id: s1 }
  - name: force_push_main_to_feature_trailing_flag
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git push origin main:feature/x --force" }
        session: { id: s1 }
  - name: force_push_to_main_prefixed_branch_trailing_flag
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git push origin HEAD:main-backup --force" }
        session: { id: s1 }
  - name: force_push_to_feature_branch
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git push --force origin feature/x" }
        session: { id: s1 }
  - name: ordinary_push_to_main
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git push origin main" }
        session: { id: s1 }
  - name: force_push_mention
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "echo 'never git push -f main' > notes.md" }
        session: { id: s1 }
  - name: force_push_to_feature_main
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git push --force origin feature/main" }
        session: { id: s1 }
  - name: force_push_to_fix_main_bug
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git push --force origin fix/main-bug" }
        session: { id: s1 }