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