fix(detectors/gitlab-v1): restrict keyword-to-secret gap to same line to stop Dockerfile false positives - #5136
Open
sergioperezcheco wants to merge 1 commit into
Conversation
… to stop Dockerfile false positives
The GitLab v1 detector used the shared detectors.PrefixRegex(), whose
gap of (?:.|[\n\r]){0,40}? lets the keyword and the captured candidate
secret sit on different physical lines. In a Dockerfile such as
ARG GITLAB_ACCESS_TOKEN
ARG MAVEN_SETTINGS_PROFILE=test_profile_value
the keyword on the first line and MAVEN_SETTINGS_PROFILE (21 chars, above
the entropy gate) on the next line matched together, producing a false
positive finding on an unrelated Docker ARG value.
Replace the prefix with an inline (?i:gitlab)[^\n\r]{0,40}? so the keyword
and the candidate must be on the same physical line. Real single-line
matches (e.g. GITLAB_TOKEN=<secret>) are unaffected; v2 and v3 use the
literal glpat- prefix and are not affected.
Added a regression test reproducing the Dockerfile FP from trufflesecurity#4756; verified
the new test fails on the old pattern and passes after the fix.
Fixes trufflesecurity#4756
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.
The GitLab v1 detector flagged a false positive on
MAVEN_SETTINGS_PROFILEwhenever a Dockerfile had aGITLAB_ACCESS_TOKENARGfollowed by an unrelatedARG MAVEN_SETTINGS_PROFILE=...line. Scans of such Dockerfiles (common in Java projects) produced findings on a value that is not a GitLab token at all.Root cause: the detector built its pattern with the shared
detectors.PrefixRegex(["gitlab"]), whose keyword-to-secret gap is(?:.|[\n\r]){0,40}?. That gap spans newlines, so thegitlabkeyword on one line and a 20–22 character alnum/hyphen/equals/underscore candidate on a later line were matched together.MAVEN_SETTINGS_PROFILEis 21 characters and clears the 3.6 Shannon-entropy gate, so it was reported as a (unverified) GitLab token.Fix: replace the shared prefix with an inline
(?i:gitlab)[^\n\r]{0,40}?so the keyword and the captured candidate must sit on the same physical line. Single-line real matches such asGITLAB_TOKEN=<secret>are unchanged. The v2 and v3 GitLab detectors use the literalglpat-prefix and are not affected.Added a regression test that reproduces the Dockerfile from the report: it fails on the old pattern (the candidate is matched across lines) and passes with the fix.
Fixes #4756
Note
Low Risk
Narrow regex tightening for false-positive reduction; v2/v3 detectors unchanged and verification logic is untouched.
Overview
GitLab v1 token detection no longer ties a
gitlabkeyword on one line to a token-like string on a later line.The detector replaces shared
PrefixRegex(gap could cross newlines) with(?i:gitlab)[^\n\r]{0,40}?so keyword and candidate stay on the same physical line. That stops Dockerfile-style false positives (e.g.GITLAB_ACCESS_TOKENARGfollowed byMAVEN_SETTINGS_PROFILEon the next line). Single-line matches likeGITLAB_TOKEN=<secret>are unchanged.A regression test covers the multi-line Dockerfile case and expects zero findings.
Reviewed by Cursor Bugbot for commit 29f01c5. Bugbot is set up for automated code reviews on this repo. Configure here.