Skip to content
Changes

Reference

infisical · Oct 24, 2026

What this change means

Atlas added infisical to its detector catalog in this update.

pkg/detectors/infisical/infisical.go+170−0View file
@@ -0,0 +1,170 @@
1added: package infisical
2added:
3added: import (
4added: "cmp"
5added: "context"
6added: "fmt"
7added: "io"
8added: "net/http"
9added: "net/url"
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: detectors.EndpointSetter
21added: }
22added:
23added: // Ensure the Scanner satisfies the interfaces at compile time.
24added: var _ detectors.Detector = (*Scanner)(nil)
25added: var _ detectors.EndpointCustomizer = (*Scanner)(nil)
26added: var _ detectors.CloudProvider = (*Scanner)(nil)
27added:
28added: // CloudEndpoint returns the primary Infisical Cloud region (US).
29added: func (Scanner) CloudEndpoint() string { return "https://app.infisical.com" }
30added:
31added: // additionalCloudEndpoints lists the remaining Infisical Cloud regions.
32added: // Cloud regions are isolated: a token issued in one region is unknown on
33added: // the other host, so every region must be tried during verification.
34added: // Self-hosted instances are not listed here. They are verified only when
35added: // an operator configures their URL as a custom verification endpoint.
36added: // https://infisical.com/docs/cli/usage
37added: var additionalCloudEndpoints = []string{
38added: "https://eu.infisical.com",
39added: }
40added:
41added: var (
42added: defaultClient = common.SaneHttpClient()
43added:
44added: // Infisical service tokens have the form st.<id>.<secret>, where <id> is a
45added: // UUID and <secret> is 32 lowercase hex characters (crypto.randomBytes(16)).
46added: // See Infisical/infisical backend/src/services/service-token/service-token-service.ts.
47added: // The dashboard appends a fourth segment of 32 lowercase hex characters
48added: // before showing the token (frontend/src/hooks/api/serviceTokens/queries.tsx),
49added: // and the official CLI rejects tokens without it. Group 1 is the full token
50added: // as found. Group 2 is the three-part form that authenticates to the API.
51added: keyPat = regexp.MustCompile(`\b((st\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.[0-9a-f]{32})(?:\.[0-9a-f]{32})?)\b`)
52added: )
53added:
54added: // Keywords are used for efficiently pre-filtering chunks.
55added: // Use identifiers in the secret preferably, or the provider name.
56added: func (s Scanner) Keywords() []string {
57added: return []string{"st."}
58added: }
59added:
60added: // FromData will find and optionally verify Infisical service tokens in a given set of bytes.
61added: func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
62added: dataStr := string(data)
63added:
64added: // Map each full token to the three-part form sent for verification.
65added: uniqueMatches := make(map[string]string)
66added: for _, match := range keyPat.FindAllStringSubmatch(dataStr, -1) {
67added: uniqueMatches[match[1]] = match[2]
68added: }
69added:
70added: for resMatch, authToken := range uniqueMatches {
71added: s1 := detectors.Result{
72added: DetectorType: detector_typepb.DetectorType_Infisical,
73added: Raw: []byte(resMatch),
74added: SecretParts: map[string]string{"key": resMatch},
75added: }
76added:
77added: if verify {
78added: client := s.VerificationClient(cmp.Or(s.client, defaultClient))
79added:
80added: // Verification targets the Infisical Cloud regions (US and EU)
81added: // plus any operator-configured endpoints, such as self-hosted
82added: // instances. URLs in the scanned data are never used.
83added: //
84added: // Only non-nil errors overwrite lastErr so that a clean 404 from
85added: // the wrong region doesn't erase a transient failure (429, 5xx,
86added: // timeout) from a region that might be authoritative.
87added: var lastErr error
88added: for _, baseURL := range s.Endpoints(additionalCloudEndpoints...) {
89added: isVerified, vErr := verifyServiceToken(ctx, client, baseURL, authToken)
90added: s1.Verified = isVerified
91added: if vErr != nil {
92added: lastErr = vErr
93added: }
94added: if isVerified {
95added: lastErr = nil
96added: s1.ExtraData = map[string]string{"endpoint": baseURL}
97added: break
98added: }
99added: }
100added: s1.SetVerificationError(lastErr, resMatch)
101added: }
102added:
103added: results = append(results, s1)
104added: }
105added:
106added: return results, nil
107added: }
108added:
109added: // verifyServiceToken checks a three-part service token against one Infisical
110added: // instance. It calls GET /api/v2/service-token, which returns only the
111added: // token's metadata. The official CLI calls the same route to read token
112added: // details. Do not switch to /api/v3/secrets/raw: for a token with one exact
113added: // scope, that route returns the plaintext secret values and writes a secret
114added: // read to the owner's audit log.
115added: //
116added: // The first return value reports whether the token verified. The error is
117added: // non-nil only when verification is indeterminate (the token's validity
118added: // could not be established from this response); the caller records it via
119added: // Result.SetVerificationError so an ambiguous result is not silently
120added: // dropped as a determinate miss.
121added: func verifyServiceToken(ctx context.Context, client *http.Client, baseURL, token string) (bool, error) {
122added: endpoint, err := url.JoinPath(baseURL, "/api/v2/service-token")
123added: if err != nil {
124added: return false, err
125added: }
126added:
127added: req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
128added: if err != nil {
129added: return false, err
130added: }
131added: req.Header.Set("Authorization", "Bearer "+token)
132added:
133added: res, err := client.Do(req)
134added: if err != nil {
135added: return false, err
136added: }
137added: defer func() {
138added: _, _ = io.Copy(io.Discard, res.Body)
139added: _ = res.Body.Close()
140added: }()
141added:
142added: switch {
143added: case res.StatusCode == http.StatusOK:
144added: return true, nil
145added: case res.StatusCode == http.StatusUnauthorized, res.StatusCode == http.StatusNotFound:
146added: // Determinately invalid: the instance does not recognize this token.
147added: return false, nil
148added: case res.StatusCode == http.StatusForbidden:
149added: // Ambiguous: Infisical returns 403 for an expired token, and a proxy
150added: // or WAF in front of the instance can reject requests for non-auth
151added: // reasons. Do not read this as "not a secret".
152added: return false, fmt.Errorf("forbidden response (HTTP 403): token validity could not be determined")
153added: case res.StatusCode == http.StatusTooManyRequests:
154added: // Transient rate limit; retrying later may verify the token.
155added: return false, fmt.Errorf("rate limited (HTTP 429): token validity could not be determined")
156added: case res.StatusCode >= 500:
157added: // Transient server failure; the token's validity is unknown.
158added: return false, fmt.Errorf("server error (HTTP %d): token validity could not be determined", res.StatusCode)
159added: default:
160added: return false, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)
161added: }
162added: }
163added:
164added: func (s Scanner) Type() detector_typepb.DetectorType {
165added: return detector_typepb.DetectorType_Infisical
166added: }
167added:
168added: func (s Scanner) Description() string {
169added: return "Infisical is an open-source secrets management platform. Service tokens can be used to read and write secrets within their scoped environments and paths."
170added: }