diff --git a/engine/rules/ruledefine/gitlab_pat.go b/engine/rules/ruledefine/gitlab_pat.go index 9ce78729..0e0122c8 100644 --- a/engine/rules/ruledefine/gitlab_pat.go +++ b/engine/rules/ruledefine/gitlab_pat.go @@ -4,16 +4,25 @@ import ( "regexp" ) -var gitlabPatRegex = regexp.MustCompile(`glpat-[\w-]{20}`).String() +var gitlabPatRegex = regexp.MustCompile(`glpat-[\w-]{20}[\w-]*`).String() + +var gitlabPatLongerTokenRegex = regexp.MustCompile(`^glpat-[\w-]{21}`).String() func GitlabPat() *Rule { return &Rule{ - RuleID: "d641ed7c-e79f-4ce6-bbce-c5de97df7752", - RuleName: "Gitlab-Pat", - Description: "Identified a GitLab Personal Access Token, risking unauthorized access to GitLab repositories and codebase exposure.", - Regex: gitlabPatRegex, - Entropy: 3, - Keywords: []string{"glpat-"}, + RuleID: "d641ed7c-e79f-4ce6-bbce-c5de97df7752", + RuleName: "Gitlab-Pat", + Description: "Identified a GitLab Personal Access Token, risking unauthorized access to GitLab repositories and codebase exposure.", + Regex: gitlabPatRegex, + Entropy: 3, + Keywords: []string{"glpat-"}, + AllowLists: []*AllowList{ + { + Description: "Not a legacy PAT: longer than 20 chars after the prefix", + RegexTarget: "match", + Regexes: []string{gitlabPatLongerTokenRegex}, + }, + }, Severity: "High", Tags: []string{TagAccessToken}, Category: CategorySourceCodeManagement, diff --git a/engine/rules/ruledefine/gitlab_pat_test.go b/engine/rules/ruledefine/gitlab_pat_test.go index 00b5032a..93db0eb8 100644 --- a/engine/rules/ruledefine/gitlab_pat_test.go +++ b/engine/rules/ruledefine/gitlab_pat_test.go @@ -45,6 +45,10 @@ func TestGitlabPat(t *testing.T) { }, falsePositives: []string{ "glpat-XXXXXXXXXXX-XXXXXXXX", + // longer than 20 chars after the prefix: not a legacy PAT (routable tokens are covered by Gitlab-Pat-Routable) + "glpat-0thvkg8tnsqpnek96k0pa3latn9.01.0t0thvkg8", + "glpat-D0agd3p5LcvzA5U_Udl-abcdefg.01.0t0thvkg8", + "glpat-D0agd3p5LcvzA5U_Udl-abcdefg", }, }, }