Skip to content

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

2.5 KB
Raw Blame
id: git-hook-installed
version: 3
title: Git hook script installed or modified
description: >
  The agent modified a script under .git/hooks/ (pre-commit, post-checkout,
  pre-push, post-merge, prepare-commit-msg, etc.). Git hooks execute on the next
  matching git operation, outside any agent sandbox and with no further prompt, so
  planting one is durable code-execution persistence triggered by ordinary
  developer git activity.
severity: high
status: stable
posture: detect
taxonomy:
  beacon_category: source-control
  owasp_llm: LLM05
  mitre_atlas: AML.T0011

match: >
  e.event.action in ["file.modified", "file.created", "file.edited"] &&
  e.file.path.matches("(?i)(^|/)\\.git/hooks/(applypatch-msg|pre-applypatch|post-applypatch|pre-commit|pre-merge-commit|prepare-commit-msg|commit-msg|post-commit|pre-rebase|post-checkout|post-merge|pre-push|pre-receive|update|post-receive|post-update|push-to-checkout|pre-auto-gc|post-rewrite|fsmonitor-watchman|reference-transaction|post-index-change|sendemail-validate|proc-receive|p4-changelist|p4-prepare-changelist|p4-post-changelist|p4-pre-submit)$")

emit:
  reason: "Git hook script installed or modified — runs on the next matching git operation, durable code-execution persistence"

tests:
  - name: pre_commit_hook
    verdict: match
    events:
      - event: { action: file.modified }
        file: { path: ".git/hooks/pre-commit" }
        session: { id: s1 }
  - name: post_checkout_hook_nested
    verdict: match
    events:
      - event: { action: file.modified }
        file: { path: "/home/dev/repo/.git/hooks/post-checkout" }
        session: { id: s1 }
  - name: reference_transaction_hook
    verdict: match
    events:
      - event: { action: file.modified }
        file: { path: ".git/hooks/reference-transaction" }
        session: { id: s1 }
  - name: post_index_change_hook
    verdict: match
    events:
      - event: { action: file.modified }
        file: { path: "/home/dev/repo/.git/hooks/post-index-change" }
        session: { id: s1 }
  - name: sample_hook_not_active
    verdict: no_match
    events:
      - event: { action: file.modified }
        file: { path: ".git/hooks/pre-commit.sample" }
        session: { id: s1 }
  - name: ordinary_script_edit
    verdict: no_match
    events:
      - event: { action: file.modified }
        file: { path: "scripts/pre-commit" }
        session: { id: s1 }
  - name: pre_commit_hook_created
    verdict: match
    events:
      - event: { action: file.created }
        file: { path: ".git/hooks/pre-commit" }
        session: { id: s1 }