Skip to content
Changes

Reference

hubspot_apikey · Nov 21, 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; 401 (StatusUnauthorized) → not verified; 403 (StatusForbidden) → verified; other (default) → error or unknownAfter: 200 (StatusOK) → verified; 401 (StatusUnauthorized) → not verified; other (default) → error or unknown
pkg/detectors/hubspot_apikey/v1/apikey.go+8−3View file
@@ -2,6 +2,7 @@ package v1
22
33import (
44 "context"
5added: "encoding/json"
56 "fmt"
67 "io"
78 "net/http"
@@ -88,12 +89,16 @@ func verifyToken(ctx context.Context, client *http.Client, token string) (bool,
8889
8990 switch res.StatusCode {
9091 case http.StatusOK:
92added: body, err := io.ReadAll(res.Body)
93added: if err != nil {
94added: return false, err
95added: }
96added: if !json.Valid(body) {
97added: return false, fmt.Errorf("unexpected response body for HTTP 200")
98added: }
9199 return true, nil
92100 case http.StatusUnauthorized:
93101 return false, nil
94removed: case http.StatusForbidden:
95removed: // The token is valid but lacks permission for the endpoint.
96removed: return true, nil
97102 default:
98103 return false, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)
99104 }
pkg/detectors/hubspot_apikey/v2/apikey.go+18−1View file
@@ -2,6 +2,7 @@ package v2
22
33import (
44 "context"
5added: "encoding/json"
56 "fmt"
67 "io"
78 "net/http"
@@ -31,6 +32,10 @@ var (
3132 keyPat = regexp.MustCompile(`\b(pat-(?:eu|na)1-[A-Za-z0-9]{8}\-[A-Za-z0-9]{4}\-[A-Za-z0-9]{4}\-[A-Za-z0-9]{4}\-[A-Za-z0-9]{12})\b`)
3233)
3334
35added: type hubspotErrorResponse struct {
36added: Category string `json:"category"`
37added: }
38added:
3439// Keywords are used for efficiently pre-filtering chunks.
3540// Use identifiers in the secret preferably, or the provider name.
3641func (s Scanner) Keywords() []string {
@@ -87,11 +92,23 @@ func verifyToken(ctx context.Context, client *http.Client, token string) (bool,
8792
8893 switch res.StatusCode {
8994 case http.StatusOK:
95added: body, err := io.ReadAll(res.Body)
96added: if err != nil {
97added: return false, err
98added: }
99added: if !json.Valid(body) {
100added: return false, fmt.Errorf("unexpected response body for HTTP 200")
101added: }
90102 return true, nil
91103 case http.StatusUnauthorized:
92104 return false, nil
93105 case http.StatusForbidden:
94removed: // The token is valid but lacks permission for the endpoint.
106added: // Only HubSpot's own scope error proves the token authenticated; a 403 from anything
107added: // else (e.g. a proxy) says nothing about the token.
108added: var errResp hubspotErrorResponse
109added: if err := json.NewDecoder(res.Body).Decode(&errResp); err != nil || errResp.Category != "MISSING_SCOPES" {
110added: return false, fmt.Errorf("unexpected 403 response, unable to verify token")
111added: }
95112 return true, nil
96113 default:
97114 return false, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)