Skip to content

fix(rules): require sourcegraph context for bare 40-char hex tokens#2109

Open
obchain wants to merge 1 commit into
gitleaks:masterfrom
obchain:fix/sourcegraph-token-git-sha-fp
Open

fix(rules): require sourcegraph context for bare 40-char hex tokens#2109
obchain wants to merge 1 commit into
gitleaks:masterfrom
obchain:fix/sourcegraph-token-git-sha-fp

Conversation

@obchain
Copy link
Copy Markdown

@obchain obchain commented May 13, 2026

Summary

The sourcegraph-access-token rule has a legacy bare-40-char-hex shape that collides with git commit SHAs, producing false positives on commit/log content (#1898).

Split the regex via MergeRegexps:

  • sgp_-prefixed tokens stay unique enough to match standalone.
  • The bare 40-char hex shape now requires a sourcegraph identifier in proximity via GenerateSemiGenericRegex, mirroring how other ambiguous-shape rules handle this.

Added two git-SHA strings to the rule's FP list so the behavior is locked in by utils.Validate.

Test plan

  • go generate ./... regenerates config/gitleaks.toml cleanly (Validate passes)
  • go test ./... green
  • Smoke scan over a file containing 2 bare git SHAs, 1 sourcegraph_token = "<sha>" line, and 1 sgp_local_<hex> token: bare SHAs ignored, sourcegraph-context hex flagged, sgp_ token flagged

Closes #1898

The legacy bare 40-char hex shape collides with git commit SHAs, which
caused false positives on commit/log content (gitleaks#1898). Split the rule:

* sgp_-prefixed tokens stay unique enough to match on their own.
* The bare 40-char hex shape now requires a "sourcegraph" identifier
  in proximity via GenerateSemiGenericRegex.

Adds two git-SHA strings to the rule's FP list to lock the behavior in.

Closes gitleaks#1898
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive - sourcegraph-access-token matches Git SHA

1 participant