Skip to content
Changes

Reference

gitlab · Oct 1, 2026

What this change means

How responses are judged changed. Changes how the detector verifies or what it treats as the credential.

Field changes
FieldBeforeAfter
Expected statusesBefore: 200 (StatusOK) → verified; 403 (StatusForbidden) → verified; 401 (StatusUnauthorized) → not verified; other (default) → error or unknown
After: 200 (StatusOK) → verified; 403 (StatusForbidden) → error or unknown; 401 (StatusUnauthorized) → not verified; other (default) → error or unk… show all
200 (StatusOK) → verified; 403 (StatusForbidden) → error or unknown; 401 (StatusUnauthorized) → not verified; other (default) → error or unknown
pkg/detectors/gitlab/v1/gitlab.go+29−9View file
@@ -37,8 +37,16 @@ var (
3737 keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"gitlab"}) + `\b([a-zA-Z0-9][a-zA-Z0-9\-=_]{19,21})\b`)
3838
3939 BlockedUserMessage = "403 Forbidden - Your account has been blocked"
40added:
41added: // GitLab's forbidden! helper formats every reasoned 403 as "403 Forbidden - <reason>".
42added: forbiddenWithReasonPrefix = "403 Forbidden - "
4043)
4144
45added: type gitlabErrorResponse struct {
46added: Message string `json:"message"`
47added: Error string `json:"error"`
48added: }
49added:
4250func (s Scanner) getClient() *http.Client {
4351 if s.client != nil {
4452 return s.client
@@ -140,22 +148,34 @@ func VerifyGitlab(ctx context.Context, client *http.Client, baseEndpoint, resMat
140148 }
141149
142150 // 200 means good key and has `read_user` scope
143removed: // 403 means good key but not the right scope
151added: // 403 from GitLab means good key, but either the scope or the account state denies access
144152 // 401 is bad key
145153 switch res.StatusCode {
146154 case http.StatusOK:
147155 return json.Valid(bodyBytes), nil, nil
148156 case http.StatusForbidden:
149removed: // check if the user account is blocked or not
150removed: stringBody := string(bodyBytes)
151removed: if strings.Contains(stringBody, BlockedUserMessage) {
152removed: return true, map[string]string{
153removed: "blocked": "True",
154removed: }, nil
157added: var errResp gitlabErrorResponse
158added: if err := json.Unmarshal(bodyBytes, &errResp); err != nil {
159added: return false, nil, fmt.Errorf("unexpected 403 response, unable to verify token")
160added: }
161added:
162added: switch {
163added: // GitLab only rejects an account (blocked, deactivated, password expired, unconfirmed
164added: // email, etc.) after the token has resolved to a user.
165added: case strings.HasPrefix(errResp.Message, forbiddenWithReasonPrefix):
166added: extraData := map[string]string{
167added: "access_denied_reason": strings.TrimPrefix(errResp.Message, forbiddenWithReasonPrefix),
168added: }
169added: if strings.HasPrefix(errResp.Message, BlockedUserMessage) {
170added: extraData["blocked"] = "True"
171added: }
172added: return true, extraData, nil
173added: case errResp.Error == "insufficient_scope", errResp.Error == "insufficient_granular_scope":
174added: // Good key but not the right scope
175added: return true, nil, nil
155176 }
156177
157removed: // Good key but not the right scope
158removed: return true, nil, nil
178added: return false, nil, fmt.Errorf("unexpected 403 response, unable to verify token")
159179 case http.StatusUnauthorized:
160180 // Nothing to do; zero values are the ones we want
161181 return false, nil, nil
pkg/detectors/gitlab/v2/gitlab_v2.go+4−0View file
@@ -61,6 +61,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6161 for _, match := range matches {
6262 resMatch := strings.TrimSpace(match[1])
6363
64added: if detectors.StringShannonEntropy(resMatch) < 3.6 {
65added: continue
66added: }
67added:
6468 for _, endpoint := range s.Endpoints() {
6569 s1 := detectors.Result{
6670 DetectorType: detector_typepb.DetectorType_Gitlab,
pkg/detectors/gitlab/v3/gitlab_v3.go+4−0View file
@@ -62,6 +62,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6262 for _, match := range matches {
6363 resMatch := strings.TrimSpace(match[1])
6464
65added: if detectors.StringShannonEntropy(resMatch) < 3.6 {
66added: continue
67added: }
68added:
6569 for _, endpoint := range s.Endpoints() {
6670 s1 := detectors.Result{
6771 DetectorType: detector_typepb.DetectorType_Gitlab,