Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions engine/rules/ruledefine/gitlab_pat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions engine/rules/ruledefine/gitlab_pat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}
Expand Down
Loading