Skip to content
Changes

Reference

composio · Nov 2, 2026

What this change means

Atlas added composio to its detector catalog in this update.

pkg/detectors/composio/composio.go+269−0View file
@@ -0,0 +1,269 @@
1added: package composio
2added:
3added: import (
4added: "cmp"
5added: "context"
6added: "encoding/json"
7added: "fmt"
8added: "io"
9added: "net/http"
10added: "strings"
11added:
12added: regexp "github.com/wasilibs/go-re2"
13added:
14added: "github.com/trufflesecurity/trufflehog/v3/pkg/common"
15added: "github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
16added: "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
17added: )
18added:
19added: type Scanner struct {
20added: client *http.Client
21added: detectors.EndpointSetter
22added: }
23added:
24added: // Ensure the Scanner satisfies the interfaces at compile time.
25added: var _ detectors.Detector = (*Scanner)(nil)
26added: var _ detectors.EndpointCustomizer = (*Scanner)(nil)
27added: var _ detectors.CloudProvider = (*Scanner)(nil)
28added:
29added: func (Scanner) CloudEndpoint() string { return "https://backend.composio.dev" }
30added:
31added: var defaultClient = common.SaneHttpClient()
32added:
33added: // getClient returns the client verification requests go through. The
34added: // VerificationClient wrap is what attaches the operator's access token when
35added: // --verifier points at an auth-protected endpoint; without it those requests
36added: // go out unauthenticated and every key comes back looking dead.
37added: func (s Scanner) getClient() *http.Client {
38added: return s.VerificationClient(cmp.Or(s.client, defaultClient))
39added: }
40added:
41added: const rotationGuide = "https://docs.composio.dev/reference/api-reference/api-keys/postApiKeyRevocation"
42added:
43added: // maxErrorBodyBytes bounds how much of an error response is read. Composio's
44added: // error envelope is a few hundred bytes; anything larger is not one.
45added: const maxErrorBodyBytes = 64 * 1024
46added:
47added: // Composio issues three key types, all a fixed prefix followed by URL-safe
48added: // nanoid characters. oak_ and uak_ contain "ak_", so every pattern requires a
49added: // non-alphabet character (or start of input) before the prefix. The trailing
50added: // boundary is checked in code rather than in the pattern: a consuming trailing
51added: // group would swallow the single delimiter between two adjacent keys and drop
52added: // the second one.
53added: //
54added: // Each key type authenticates through its own header and its own routes. A key
55added: // sent under another type's header is answered with the same 401 as no header
56added: // at all, so verification cannot share one endpoint across types: every type
57added: // carries the cheapest read-only route it can authenticate.
58added: type keyPattern struct {
59added: keyType string
60added: re *regexp.Regexp
61added: verifyPath string
62added: header string
63added: }
64added:
65added: var keyPatterns = []keyPattern{
66added: {
67added: keyType: "project",
68added: re: regexp.MustCompile(`(?:^|[^A-Za-z0-9_-])(ak_[A-Za-z0-9_-]{20})`),
69added: verifyPath: "/api/v3/toolkits/categories",
70added: header: "x-api-key",
71added: },
72added: {
73added: keyType: "org",
74added: re: regexp.MustCompile(`(?:^|[^A-Za-z0-9_-])(oak_[A-Za-z0-9_-]{20})`),
75added: verifyPath: "/api/v3/org/owner/project/list",
76added: header: "x-org-api-key",
77added: },
78added: {
79added: keyType: "user",
80added: re: regexp.MustCompile(`(?:^|[^A-Za-z0-9_-])(uak_[A-Za-z0-9_-]{43})`),
81added: verifyPath: "/api/v3/org/list?limit=1",
82added: header: "x-user-api-key",
83added: },
84added: }
85added:
86added: // isKeyAlphabet reports whether b can appear inside a Composio key.
87added: func isKeyAlphabet(b byte) bool {
88added: return (b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') || (b >= '0' && b <= '9') || b == '_' || b == '-'
89added: }
90added:
91added: // endsAtBoundary reports whether the key ending at end is followed by end of
92added: // input or a character that cannot be part of a key.
93added: func endsAtBoundary(data string, end int) bool {
94added: return end >= len(data) || !isKeyAlphabet(data[end])
95added: }
96added:
97added: // Keywords are used for efficiently pre-filtering chunks. "ak_" is a substring
98added: // of all three prefixes.
99added: func (s Scanner) Keywords() []string {
100added: return []string{"ak_"}
101added: }
102added:
103added: // FromData finds Composio API keys in a given set of bytes and, when asked,
104added: // verifies each one against the Composio API.
105added: func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
106added: dataStr := string(data)
107added:
108added: seen := make(map[string]struct{})
109added: for _, pattern := range keyPatterns {
110added: for _, loc := range pattern.re.FindAllStringSubmatchIndex(dataStr, -1) {
111added: start, end := loc[2], loc[3]
112added: if !endsAtBoundary(dataStr, end) {
113added: continue
114added: }
115added: token := dataStr[start:end]
116added: if _, dup := seen[token]; dup {
117added: continue
118added: }
119added: seen[token] = struct{}{}
120added:
121added: r := detectors.Result{
122added: DetectorType: detector_typepb.DetectorType_Composio,
123added: Raw: []byte(token),
124added: SecretParts: map[string]string{"key": token},
125added: ExtraData: map[string]string{
126added: "key_type": pattern.keyType,
127added: "rotation_guide": rotationGuide,
128added: },
129added: }
130added:
131added: if verify {
132added: client := s.getClient()
133added:
134added: // Only the cloud endpoint and operator-configured endpoints are
135added: // used; URLs found in scanned data are never called. Only
136added: // non-nil errors overwrite lastErr so a clean 401 from one
137added: // endpoint does not erase a transient failure from another.
138added: var lastErr error
139added: for _, baseURL := range s.Endpoints() {
140added: verified, extra, vErr := verifyMatch(ctx, client, baseURL, pattern, token)
141added: r.Verified = verified
142added: if vErr != nil {
143added: lastErr = vErr
144added: }
145added: if verified {
146added: lastErr = nil
147added: r.ExtraData["endpoint"] = baseURL
148added: for k, v := range extra {
149added: r.ExtraData[k] = v
150added: }
151added: break
152added: }
153added: }
154added: r.SetVerificationError(lastErr, token)
155added: }
156added:
157added: results = append(results, r)
158added: }
159added: }
160added:
161added: return results, nil
162added: }
163added:
164added: // apiError is the envelope every Composio API error carries. The slug is
165added: // stable across releases; the message is human copy.
166added: type apiError struct {
167added: Error struct {
168added: Message string `json:"message"`
169added: Slug string `json:"slug"`
170added: Code int `json:"code"`
171added: } `json:"error"`
172added: }
173added:
174added: // verifyMatch sends the key on the route its type can authenticate and maps
175added: // the answer to verified, dead, or undecided. Composio deliberately answers
176added: // several unrelated conditions with 401, so the verdict comes from the error
177added: // slug in the body, never from the status code alone:
178added: //
179added: // - 200: live.
180added: // - 401 APIKey_InvalidAPIKey, APIKey_APIKeyExpired, UserApiKey_Unauthorized,
181added: // and HTTP_Unauthorized "Invalid x-org-api-key": the hash matched no live
182added: // row. Dead, no error.
183added: // - 401 Auth_Unauthorized naming the key's IP allowlist: the key exists and
184added: // works from allowlisted addresses. Live, reported with the restriction.
185added: // - 403 carrying the envelope: Composio only refuses with 403 after the
186added: // credential resolved (a scoped key without the route's permission, an
187added: // org-level restriction). Live, reported with the restriction.
188added: // - Anything else (a banned scanner address answers "Access denied", a
189added: // stripped header answers Auth_NoAuthProvided, a WAF page has no
190added: // envelope, 429, 5xx): undecided, surfaced as a verification error.
191added: //
192added: // The org key's dead slug HTTP_Unauthorized is shared with the banned-address
193added: // answer, so that one branch also reads the message; a copy change there
194added: // degrades to an undecided error, never to a wrong verdict.
195added: func verifyMatch(
196added: ctx context.Context,
197added: client *http.Client,
198added: baseURL string,
199added: pattern keyPattern,
200added: token string,
201added: ) (bool, map[string]string, error) {
202added: req, err := http.NewRequestWithContext(ctx, http.MethodGet, strings.TrimRight(baseURL, "/")+pattern.verifyPath, nil)
203added: if err != nil {
204added: return false, nil, err
205added: }
206added: req.Header.Set(pattern.header, token)
207added: req.Header.Set("Accept", "application/json")
208added:
209added: res, err := client.Do(req)
210added: if err != nil {
211added: return false, nil, err
212added: }
213added: defer func() {
214added: _, _ = io.Copy(io.Discard, res.Body)
215added: _ = res.Body.Close()
216added: }()
217added:
218added: switch res.StatusCode {
219added: case http.StatusOK:
220added: return true, nil, nil
221added:
222added: case http.StatusUnauthorized, http.StatusForbidden:
223added: var body apiError
224added: dec := json.NewDecoder(io.LimitReader(res.Body, maxErrorBodyBytes))
225added: if err := dec.Decode(&body); err != nil || body.Error.Slug == "" {
226added: return false, nil, fmt.Errorf("HTTP %d without a Composio error envelope", res.StatusCode)
227added: }
228added: return classifyRejection(res.StatusCode, body)
229added:
230added: default:
231added: return false, nil, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)
232added: }
233added: }
234added:
235added: func classifyRejection(status int, body apiError) (bool, map[string]string, error) {
236added: slug, message := body.Error.Slug, body.Error.Message
237added:
238added: switch {
239added: case status == http.StatusUnauthorized && (slug == "APIKey_InvalidAPIKey" ||
240added: slug == "APIKey_APIKeyExpired" || slug == "UserApiKey_Unauthorized"):
241added: return false, nil, nil
242added:
243added: case status == http.StatusUnauthorized && slug == "HTTP_Unauthorized" &&
244added: strings.HasPrefix(message, "Invalid x-org-api-key"):
245added: return false, nil, nil
246added:
247added: case status == http.StatusUnauthorized && slug == "Auth_Unauthorized" && strings.Contains(message, "IP allowlist"):
248added: return true, map[string]string{"restriction": "ip_allowlist"}, nil
249added:
250added: case status == http.StatusForbidden && slug == "APIKey_InsufficientPermissions":
251added: return true, map[string]string{"restriction": "insufficient_permissions"}, nil
252added:
253added: case status == http.StatusForbidden:
254added: return true, map[string]string{"restriction": slug}, nil
255added:
256added: default:
257added: return false, nil, fmt.Errorf("HTTP %d %s did not judge the key: %s", status, slug, message)
258added: }
259added: }
260added:
261added: func (s Scanner) Type() detector_typepb.DetectorType {
262added: return detector_typepb.DetectorType_Composio
263added: }
264added:
265added: func (s Scanner) Description() string {
266added: return "Composio is an integration platform for AI agents. Composio API " +
267added: "keys authenticate calls that execute tools, read connected accounts " +
268added: "and manage triggers for a project, an organization or a user."
269added: }