Skip to content

feat(detectors): add Infisical service token detector - #5445

Merged
dustin-decker merged 4 commits into
trufflesecurity:mainfrom
Varshith-Kali:feat/infisical-detector-5444
Oct 24, 2026
Merged

dustin-decker merged 4 commits into
trufflesecurity:mainfrom
Varshith-Kali:feat/infisical-detector-5444

Conversation

@Varshith-Kali

@Varshith-Kali Varshith-Kali commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a new detector for Infisical service tokens (st.<id>.<secret>), the bearer credentials Infisical issues for programmatic access to secrets. TruffleHog previously had no coverage for this format, so leaked Infisical tokens were silently missed.

Infisical is a widely adopted open-source secrets management platform (a popular HashiCorp Vault alternative), and service tokens are its current widely-used auth method for CI/CD pipelines and services. A leaked token grants read/write access to the secrets in its scoped environments and paths, which makes this a high-impact blind spot: these tokens live in env files and CI configs, exactly the places TruffleHog scans.

Fixes #5444.

Root cause

There was no infisical scanner and no DetectorType for it. The distinctive st.<uuid>.<32 hex> shape matched nothing in the existing detector set.

Evidence for the format

From Infisical's own docs (https://infisical.com/docs/documentation/platform/token):

A service token is a bearer token of the form st.<id>.<secret>.

Confirmed in Infisical's source (Infisical/infisical, backend/src/services/service-token/service-token-service.ts):

const secret = crypto.randomBytes(16).toString("hex");   // 32 lowercase hex chars
const token = `st.${serviceToken.id.toString()}.${secret}`;

The token ID is a UUID (migration 20231225072545_service-token.ts: t.string("id", 36).primary().defaultTo(knex.fn.uuid())).

The dashboard appends a fourth segment of 32 lowercase hex characters before showing the token (frontend/src/hooks/api/serviceTokens/queries.tsx), and the official CLI rejects tokens without it. The backend authenticates with only the first three segments.

Detection pattern: \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, keyword st.. The full three-part or four-part token as found is kept in Raw and SecretParts["key"]. Identical tokens in a chunk are reported and verified once.

Verification

GET /api/v2/service-token with Authorization: Bearer st.<id>.<secret> (only the first three segments are sent). This route returns only the token's metadata; the official CLI calls it to read token details. The earlier /api/v3/secrets/raw route is not used because, for a token with one exact scope, it returns plaintext secret values and records a secret read in the audit log.

Requests go to https://app.infisical.com and https://eu.infisical.com plus any configured endpoints (for self-hosted instances). URLs found in scanned data are never used. From Infisical's auth code (fnValidateServiceToken in the same service file, invoked by the global injectIdentity hook):

  • 200 marks the token verified;
  • 401 (wrong secret) and 404 (unknown token ID) are definite misses;
  • any other status (including 400, 403, 429 and 5xx) and transport errors are indeterminate and recorded with SetVerificationError. An error from one endpoint is kept when a later endpoint returns a clean miss.

I could not exercise verification against a live token (no Infisical account in this environment), so the test asserts that a synthetic correctly-shaped token is found but not marked verified.

Test results

  • go test ./pkg/detectors/infisical/: PASS (pattern tests for three-part and four-part tokens and invalid shapes, the status matrix, region fallback, error retention across endpoints, and duplicate-token deduplication; all against local test servers with synthetic tokens).
  • go test ./pkg/engine/defaults/: PASS (includes TestAllDetectorTypesAreInDefaultList).
  • go test ./pkg/config/: PASS.
  • go build on the touched packages and go vet on the new detector: clean. gofmt: clean.

Known limits

  • Only the st. service token format is covered. Infisical's newer machine-identity auth (universal auth client ID/secret) is a separate credential shape and is out of scope here.
  • Verification relies on Infisical's current status codes for /api/v2/service-token (200 valid, 401/404 invalid). That route is marked deprecated, so future removal or status-code changes would require updating the verifier.
  • The generated detector_type.pb.go was regenerated with make protos after merging main (which added Fireworks = 1076).

Checklist

  • New DetectorType (Infisical = 1075) added to proto/detector_type.proto and the generated code.
  • Scanner registered in pkg/engine/defaults/defaults.go, feature-flagged (InfisicalDetectorEnabled, enabled in main.go).
  • SecretParts populated on every result.
  • Tests added; no real credentials used (synthetic token only).

Note

Medium Risk
Verification sends discovered bearer tokens to Infisical (or custom) hosts over the network; behavior is additive but touches high-value secrets-management credentials.

Overview
Adds Infisical service token detection for credentials shaped like st.<uuid>.<32 hex>, including optional fourth segments as shown in the Infisical dashboard, with keyword prefilter st..

When verification is on, tokens are checked via GET /api/v2/service-token (metadata only, not secret values) against US/EU Infisical Cloud and any custom verifier endpoints, trying regions until one succeeds. HTTP handling treats 401/404 as invalid, 200 as verified, and 403/429/5xx (and other unexpected codes) as indeterminate with verification errors preserved across region attempts.

Wiring adds DetectorType_Infisical (1075), registers the scanner behind InfisicalDetectorEnabled (enabled in main.go), and includes broad unit tests for patterns, status codes, region fallback, and deduplication.

Reviewed by Cursor Bugbot for commit fdc4a39. Bugbot is set up for automated code reviews on this repo. Configure here.

@Varshith-Kali
Varshith-Kali requested a review from a team October 19, 2026 07:02
@Varshith-Kali
Varshith-Kali requested a review from a team as a code owner October 19, 2026 07:02

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit d1c8b96. Configure here.

Comment thread pkg/detectors/infisical/infisical.go Resolved
Comment thread pkg/detectors/infisical/infisical.go Resolved
Infisical is a widely used open-source secrets management platform, and
its service tokens (st.<id>.<secret>) are bearer credentials that grant
read/write access to secrets in their scoped environments. TruffleHog had
no detector for this format, so leaked Infisical tokens were silently
missed.

The token shape is confirmed by Infisical's docs and source:
st.<uuid>.<32 lowercase hex> (secret = crypto.randomBytes(16).hex()).

Adds DetectorType Infisical (1074), a new infisical scanner with keyword
st., and verification via GET /api/v3/secrets/raw (unknown token IDs
return 404, valid tokens pass auth and return 400 for the missing
workspaceId param).

Fixes trufflesecurity#5444

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
…egion-aware

Verification only treated 2xx and 400 as verified and every other status as a determinate miss, so rate limits (429), server errors (5xx) and 403 from a scoped-but-valid token silently read as "not a secret" and could be dropped by --only-verified. These statuses are now indeterminate: verification records a verification error via SetVerificationError instead of a silent miss, following the (bool, error) convention used by sibling detectors (datadogapikey, humioapitoken).

Verification also only targeted https://app.infisical.com (Cloud US). Cloud regions are isolated, so a valid EU token read as 404/invalid. The scanner now implements CloudProvider/EndpointCustomizer (humioapitoken pattern): the US host stays primary, https://eu.infisical.com is tried next, and the verifying endpoint is recorded in ExtraData. Self-hosted instances keep working via configured endpoints or URLs found in scanned data.

Tests: httptest-based coverage for the status matrix (2xx/400 verify; 401/404 determinate miss; 403/429/5xx/unexpected indeterminate with verification error), the US->EU region fallback, and the 400-from-missing-workspaceId behavior. Replaces the previous live-network verification test.
Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@Varshith-Kali
Varshith-Kali force-pushed the feat/infisical-detector-5444 branch from c1d1db8 to 84b1917 Compare October 22, 2026 10:15
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Checking in on the Infisical service token detector. The workflow runs are still parked at the first-time-contributor approval step; approving them would let CI run on the current head. The two Cursor Bugbot findings from the earlier review are fixed on this head. Happy to adjust anything else.

@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Hi team, friendly follow-up: the workflow runs on this PR (Smoke, Test, CodeQL, Lint, Scan for secrets, Performance Test) are still parked at action_required awaiting first-time-contributor approval. Approving them would let CI run on the current head. Thanks!

dustin-decker and others added 2 commits October 23, 2026 22:38
Verify with GET /api/v2/service-token instead of the deprecated raw
secrets route, which can return plaintext project secrets. Only HTTP 200
verifies; 401 and 404 are invalid; other statuses and transport errors
are indeterminate. Capture the optional fourth dashboard segment so the
full token is retained in Raw and SecretParts, send only the first three
components as the Bearer value, and deduplicate identical tokens per
chunk. Keep an earlier endpoint error when a later endpoint misses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the detector_type enum conflict with Fireworks (trufflesecurity#5447) by keeping
Infisical = 1075 and Fireworks = 1076, and regenerate detector_type.pb.go
with `make protos` (trufflesecurity/protos:1.22).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dustin-decker
dustin-decker merged commit 50bc667 into trufflesecurity:main Oct 24, 2026
15 checks passed
@dustin-decker

Copy link
Copy Markdown
Contributor

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Infisical service token detector (st.<uuid>.<secret>)

2 participants