summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMohamed Hegazy <8000722+mhegazy@users.noreply.github.com>2026-11-05 14:15:22 -0800
committerGitHub <noreply@github.com>2026-11-05 14:15:22 -0800
commit88cc978a56e28d54180fda4e423bfddde1e7f532 (patch)
tree9193248d0833fa94c103575e1f96adc28ac82e39 /plugins
parent848b86720e4871c0148b4c4113162cb6fe42a68e (diff)
parent0610eb807de91eb829f4bf9354cfd4bcb45bdcc6 (diff)
Merge pull request #7002 from anthropics/mhegazy/sg-git-log-signature-off
security-guidance: read git log output without signature checks
Diffstat (limited to 'plugins')
-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 7ab40403..75d08298 100644
--- a/plugins/security-guidance/hooks/gitutil.py
+++ b/plugins/security-guidance/hooks/gitutil.py
@@ -93,6 +93,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
@@ -105,6 +109,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()