summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohamed Hegazy <mhegazy@anthropic.com>2026-11-04 19:38:34 +0000
committerClaude <noreply@anthropic.com>2026-11-04 19:38:34 +0000
commit0610eb807de91eb829f4bf9354cfd4bcb45bdcc6 (patch)
tree59997536d7ff6585ed50a328358a62aa4a384cfb
parentfa4eb54397ee2faccb6940512a19c017cb1337f3 (diff)
security-guidance: read git log output without signature checksmhegazy/sg-git-log-signature-off
With log.showSignature set, git log and git show verify every signed commit, which adds lines to the output the hooks parse and starts gpg.program. Set it off for the hooks' git and for the commit reviewer's environment. Co-authored-by: mhegazy <mhegazy@anthropic.com>
-rw-r--r--plugins/security-guidance/hooks/gitutil.py5
-rw-r--r--plugins/security-guidance/tests/test_nested_repos.py48
2 files changed, 52 insertions, 1 deletions
diff --git a/plugins/security-guidance/hooks/gitutil.py b/plugins/security-guidance/hooks/gitutil.py
index ec51e3c6..1354a782 100644
--- a/plugins/security-guidance/hooks/gitutil.py
+++ b/plugins/security-guidance/hooks/gitutil.py
@@ -62,6 +62,10 @@ GIT_CMD = [
# _drop_gitlinks for the commands that take no such setting.
"-c", "diff.ignoreSubmodules=all",
"-c", "diff.submodule=short",
+ # `git log` and `git show` print commit metadata for the hooks to parse.
+ # With log.showSignature set they would also verify each signed commit,
+ # adding lines to the output and starting the program gpg.program names.
+ "-c", "log.showSignature=false",
]
# diff.ignoreSubmodules is a default that the repository's own settings for
@@ -74,6 +78,7 @@ SAFE_GIT_CONFIG = (
("core.hooksPath", "/dev/null"),
("diff.ignoreSubmodules", "all"),
("diff.submodule", "short"),
+ ("log.showSignature", "false"),
)
# The hook's git runs in the background beside the session's own git. Without
diff --git a/plugins/security-guidance/tests/test_nested_repos.py b/plugins/security-guidance/tests/test_nested_repos.py
index 3c93a580..8357abf1 100644
--- a/plugins/security-guidance/tests/test_nested_repos.py
+++ b/plugins/security-guidance/tests/test_nested_repos.py
@@ -6,7 +6,7 @@ import pytest
from conftest import (
GIT_ENV, STUB_VULN, VULN_PY, git, make_repo, metrics_of, run_hook,
- stop_payload, ups_payload,
+ stop_payload, ups_payload, write_cli,
)
import diffstate
@@ -425,3 +425,49 @@ def test_gitlink_found_in_every_index_format(outer, marker, git_env, monkeypatch
assert seen and "160000" not in copy and "later.py" in copy
assert baseline != git(outer, "rev-parse", "HEAD").strip()
assert not marker.exists()
+
+
+def _signed_head(repo, tmp_path, marker):
+ """Make HEAD a commit that carries a signature, with log.showSignature on
+ and gpg.program naming a stand-in that leaves a line in `marker`."""
+ program = write_cli(tmp_path, "signature-check", (
+ "import sys\n"
+ f"open({str(marker)!r}, 'a').write('ran\\n')\n"
+ "sys.exit(1)\n"))
+ head = git(repo, "rev-parse", "HEAD").strip()
+ tree = git(repo, "rev-parse", "HEAD^{tree}").strip()
+ who = "t <t@example.com> 1800000000 +0000"
+ commit = (
+ f"tree {tree}\nparent {head}\nauthor {who}\ncommitter {who}\n"
+ "gpgsig -----BEGIN PGP SIGNATURE-----\n \n xx\n"
+ " -----END PGP SIGNATURE-----\n\nsigned\n")
+ sha = subprocess.run(
+ ["git", "hash-object", "-t", "commit", "-w", "--stdin"], cwd=repo,
+ input=commit.encode(), capture_output=True, check=True,
+ ).stdout.decode().strip()
+ git(repo, "update-ref", "--create-reflog", "-m", "commit: signed", "HEAD", sha)
+ git(repo, "config", "log.showSignature", "true")
+ git(repo, "config", "gpg.program", str(program))
+ return sha
+
+
+def test_reading_the_reflog_does_not_check_signatures(outer, marker, tmp_path, git_env):
+ sha = _signed_head(outer, tmp_path, marker)
+ # The stand-in does run for a plain `git log` in this repository.
+ git(outer, "log", "-1")
+ assert marker.exists()
+ marker.unlink()
+
+ fresh, _stale = gitutil._git_reflog_recent_commits(str(outer), max_age_s=10**10)
+
+ assert sha in fresh
+ assert not marker.exists(), marker.read_text()
+
+
+def test_reviewer_environment_turns_signature_display_off(outer, marker, tmp_path, git_env):
+ _signed_head(outer, tmp_path, marker)
+
+ gitutil.apply_safe_git_env()
+ git(outer, "log", "-1")
+
+ assert not marker.exists(), marker.read_text()