Skip to content
Changes

Reference

baseten · Nov 21, 2026

What this change means

Atlas added baseten to its detector catalog in this update.

pkg/detectors/baseten/v1/baseten.go+137−0View file
@@ -0,0 +1,137 @@
1added: package baseten
2added:
3added: import (
4added: "context"
5added: "encoding/json"
6added: "fmt"
7added: "io"
8added: "maps"
9added: "net/http"
10added:
11added: regexp "github.com/wasilibs/go-re2"
12added:
13added: "github.com/trufflesecurity/trufflehog/v3/pkg/common"
14added: "github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
15added: "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
16added: )
17added:
18added: type Scanner struct {
19added: client *http.Client
20added: }
21added:
22added: // Ensure the Scanner satisfies the interface at compile time.
23added: var _ detectors.Detector = (*Scanner)(nil)
24added: var _ detectors.Versioner = (*Scanner)(nil)
25added:
26added: var (
27added: defaultClient = common.SaneHttpClient()
28added: // Keys issued before the b10_ prefix: https://docs.baseten.co/organization/api-keys#api-key-format
29added: keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"baseten"}) + `\b([A-Za-z0-9]{8}\.[A-Za-z0-9]{32})\b`)
30added: )
31added:
32added: type userInfo struct {
33added: UserID string `json:"user_id"`
34added: Email string `json:"email"`
35added: Name string `json:"name"`
36added: WorkspaceName string `json:"workspace_name"`
37added: }
38added:
39added: func (s Scanner) Version() int {
40added: return 1
41added: }
42added:
43added: func (s Scanner) Keywords() []string {
44added: return []string{"baseten"}
45added: }
46added:
47added: // FromData will find and optionally verify Baseten secrets in a given set of bytes.
48added: func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
49added: dataStr := string(data)
50added:
51added: uniqueMatches := make(map[string]struct{})
52added: for _, match := range keyPat.FindAllStringSubmatch(dataStr, -1) {
53added: uniqueMatches[match[1]] = struct{}{}
54added: }
55added:
56added: for match := range uniqueMatches {
57added: s1 := detectors.Result{
58added: DetectorType: detector_typepb.DetectorType_Baseten,
59added: Raw: []byte(match),
60added: ExtraData: map[string]string{
61added: "rotation_guide": "https://docs.baseten.co/reference/management-api/api-keys/delete-an-api-key",
62added: "version": fmt.Sprintf("%d", s.Version()),
63added: },
64added: SecretParts: map[string]string{"key": match},
65added: }
66added:
67added: if verify {
68added: client := s.client
69added: if client == nil {
70added: client = defaultClient
71added: }
72added:
73added: isVerified, extraData, verificationErr := verifyMatch(ctx, client, match)
74added: s1.Verified = isVerified
75added: maps.Copy(s1.ExtraData, extraData)
76added: s1.SetVerificationError(verificationErr, match)
77added: }
78added:
79added: results = append(results, s1)
80added: }
81added:
82added: return
83added: }
84added:
85added: func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, map[string]string, error) {
86added: // Returns 401 for invalid or revoked keys and 403 for valid keys lacking permission (as of 2026-10-28).
87added: // https://docs.baseten.co/reference/management-api/overview
88added: req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.baseten.co/v1/users/me", nil)
89added: if err != nil {
90added: return false, nil, err
91added: }
92added: req.Header.Add("Authorization", "Bearer "+token)
93added:
94added: res, err := client.Do(req)
95added: if err != nil {
96added: return false, nil, err
97added: }
98added: defer func() {
99added: _, _ = io.Copy(io.Discard, res.Body)
100added: _ = res.Body.Close()
101added: }()
102added:
103added: switch res.StatusCode {
104added: case http.StatusOK:
105added: var user userInfo
106added: if err := json.NewDecoder(res.Body).Decode(&user); err != nil {
107added: return true, nil, nil
108added: }
109added: extraData := map[string]string{
110added: "user_id": user.UserID,
111added: "email": user.Email,
112added: "name": user.Name,
113added: "workspace_name": user.WorkspaceName,
114added: }
115added: for k, v := range extraData {
116added: if v == "" {
117added: delete(extraData, k)
118added: }
119added: }
120added: return true, extraData, nil
121added: case http.StatusForbidden:
122added: // Valid credentials lacking permission for this endpoint; the key is still live.
123added: return true, nil, nil
124added: case http.StatusUnauthorized:
125added: return false, nil, nil
126added: default:
127added: return false, nil, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)
128added: }
129added: }
130added:
131added: func (s Scanner) Type() detector_typepb.DetectorType {
132added: return detector_typepb.DetectorType_Baseten
133added: }
134added:
135added: func (s Scanner) Description() string {
136added: return "Baseten is a platform for deploying and serving machine learning models. Baseten API keys grant access to model inference and the management API for a user or workspace."
137added: }
pkg/detectors/baseten/v2/baseten.go+137−0View file
@@ -0,0 +1,137 @@
1added: package baseten
2added:
3added: import (
4added: "context"
5added: "encoding/json"
6added: "fmt"
7added: "io"
8added: "maps"
9added: "net/http"
10added:
11added: regexp "github.com/wasilibs/go-re2"
12added:
13added: "github.com/trufflesecurity/trufflehog/v3/pkg/common"
14added: "github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
15added: "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
16added: )
17added:
18added: type Scanner struct {
19added: client *http.Client
20added: }
21added:
22added: // Ensure the Scanner satisfies the interface at compile time.
23added: var _ detectors.Detector = (*Scanner)(nil)
24added: var _ detectors.Versioner = (*Scanner)(nil)
25added:
26added: var (
27added: defaultClient = common.SaneHttpClient()
28added: // Key format as of 2026-10-01: https://docs.baseten.co/organization/api-keys#api-key-format
29added: keyPat = regexp.MustCompile(`\b(b10_[A-Za-z0-9]{8}\.[A-Za-z0-9]{32})\b`)
30added: )
31added:
32added: type userInfo struct {
33added: UserID string `json:"user_id"`
34added: Email string `json:"email"`
35added: Name string `json:"name"`
36added: WorkspaceName string `json:"workspace_name"`
37added: }
38added:
39added: func (s Scanner) Version() int {
40added: return 2
41added: }
42added:
43added: func (s Scanner) Keywords() []string {
44added: return []string{"b10_"}
45added: }
46added:
47added: // FromData will find and optionally verify Baseten secrets in a given set of bytes.
48added: func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
49added: dataStr := string(data)
50added:
51added: uniqueMatches := make(map[string]struct{})
52added: for _, match := range keyPat.FindAllStringSubmatch(dataStr, -1) {
53added: uniqueMatches[match[1]] = struct{}{}
54added: }
55added:
56added: for match := range uniqueMatches {
57added: s1 := detectors.Result{
58added: DetectorType: detector_typepb.DetectorType_Baseten,
59added: Raw: []byte(match),
60added: ExtraData: map[string]string{
61added: "rotation_guide": "https://docs.baseten.co/reference/management-api/api-keys/delete-an-api-key",
62added: "version": fmt.Sprintf("%d", s.Version()),
63added: },
64added: SecretParts: map[string]string{"key": match},
65added: }
66added:
67added: if verify {
68added: client := s.client
69added: if client == nil {
70added: client = defaultClient
71added: }
72added:
73added: isVerified, extraData, verificationErr := verifyMatch(ctx, client, match)
74added: s1.Verified = isVerified
75added: maps.Copy(s1.ExtraData, extraData)
76added: s1.SetVerificationError(verificationErr, match)
77added: }
78added:
79added: results = append(results, s1)
80added: }
81added:
82added: return
83added: }
84added:
85added: func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, map[string]string, error) {
86added: // Returns 401 for invalid or revoked keys and 403 for valid keys lacking permission (as of 2026-10-28).
87added: // https://docs.baseten.co/reference/management-api/overview
88added: req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.baseten.co/v1/users/me", nil)
89added: if err != nil {
90added: return false, nil, err
91added: }
92added: req.Header.Add("Authorization", "Bearer "+token)
93added:
94added: res, err := client.Do(req)
95added: if err != nil {
96added: return false, nil, err
97added: }
98added: defer func() {
99added: _, _ = io.Copy(io.Discard, res.Body)
100added: _ = res.Body.Close()
101added: }()
102added:
103added: switch res.StatusCode {
104added: case http.StatusOK:
105added: var user userInfo
106added: if err := json.NewDecoder(res.Body).Decode(&user); err != nil {
107added: return true, nil, nil
108added: }
109added: extraData := map[string]string{
110added: "user_id": user.UserID,
111added: "email": user.Email,
112added: "name": user.Name,
113added: "workspace_name": user.WorkspaceName,
114added: }
115added: for k, v := range extraData {
116added: if v == "" {
117added: delete(extraData, k)
118added: }
119added: }
120added: return true, extraData, nil
121added: case http.StatusForbidden:
122added: // Valid credentials lacking permission for this endpoint; the key is still live.
123added: return true, nil, nil
124added: case http.StatusUnauthorized:
125added: return false, nil, nil
126added: default:
127added: return false, nil, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)
128added: }
129added: }
130added:
131added: func (s Scanner) Type() detector_typepb.DetectorType {
132added: return detector_typepb.DetectorType_Baseten
133added: }
134added:
135added: func (s Scanner) Description() string {
136added: return "Baseten is a platform for deploying and serving machine learning models. Baseten API keys grant access to model inference and the management API for a user or workspace."
137added: }