fix(detectors): skip GitLab v1 candidates with no digits to reduce false positives#4996
Open
AlexanderSanin wants to merge 1 commit into
Conversation
…lse positives The v1 GitLab detector uses PrefixRegex which searches up to 40 chars ahead of a "gitlab" keyword, crossing newlines. In Dockerfiles like: ARG GITLAB_ACCESS_TOKEN_TYPE=Private-Token ARG GITLAB_ACCESS_TOKEN ARG MAVEN_SETTINGS_PROFILE=test "MAVEN_SETTINGS_PROFILE" (22 chars, all [a-zA-Z0-9_]) is within 40 characters of the second GITLAB keyword and passes the Shannon entropy check (~4.1 > 3.6) because its letters are varied. It is then reported as a GitLab secret — a false positive. Real GitLab personal access tokens are randomly generated and always contain at least one digit. Variable names like MAVEN_SETTINGS_PROFILE never do. Add a KeyIsRandom guard (already used elsewhere in the codebase) to discard digit-free candidates before verification. Closes trufflesecurity#4756 Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>
|
|
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a false positive in the GitLab v1 detector where Dockerfile
ARGvariable names (e.g.MAVEN_SETTINGS_PROFILE) are reported as GitLab secrets.Root cause:
PrefixRegexmatches up to 40 characters ahead of agitlabkeyword, including newlines. In a Dockerfile like:MAVEN_SETTINGS_PROFILE(22 chars, all[a-zA-Z0-9_]) falls within the 40-char window of the secondGITLABkeyword and clears the Shannon-entropy check (~4.1 > 3.6 threshold) because its letters are varied. It is then emitted as a finding.Fix: Add the
detectors.KeyIsRandomguard that already exists elsewhere in the codebase. Real GitLab personal access tokens are random and always contain at least one digit; environment-variable names likeMAVEN_SETTINGS_PROFILEnever do. Candidates with no digits are now skipped before the (potentially network-bound) verification step.Closes #4756
Test plan
no_false_positive_for_Dockerfile_ARG_variable_name_after_GITLAB_ACCESS_TOKENreproduces the exact Dockerfile from the issue and asserts zero resultsvalid pattern,valid pattern (with = before secret)) continue to pass — real tokens contain digits and are unaffectedgo test ./pkg/detectors/gitlab/v1/... -run TestGitLab_Pattern -v→ all PASSSigned-off-by: Oleksandr Sanin alexaaander.sanin@gmail.com
Note
Low Risk
Local heuristic filter on detector candidates only; legitimate tokens with digits are unchanged.
Overview
The GitLab v1 detector now drops candidate matches that fail
detectors.KeyIsRandom(no digit in the string), after the existing Shannon-entropy filter and before verification.This targets false positives where Dockerfile
ARGnames (e.g.MAVEN_SETTINGS_PROFILE) sit within thePrefixRegexwindow of agitlabkeyword across newlines and still pass entropy. Real v1 tokens are expected to include at least one digit.A pattern regression test covers the issue #4756 Dockerfile snippet and expects zero findings.
Reviewed by Cursor Bugbot for commit 52ba5e9. Bugbot is set up for automated code reviews on this repo. Configure here.