Skip to content

feat(detectors): add Gitea API token detector#5042

Open
0xDevNinja wants to merge 2 commits into
trufflesecurity:mainfrom
0xDevNinja:feat/gitea-detector
Open

feat(detectors): add Gitea API token detector#5042
0xDevNinja wants to merge 2 commits into
trufflesecurity:mainfrom
0xDevNinja:feat/gitea-detector

Conversation

@0xDevNinja

@0xDevNinja 0xDevNinja commented Jun 16, 2026

Copy link
Copy Markdown

Description:

Closes #4718.

Adds a new verifiable detector for Gitea API tokens.

  • Pattern: 40-character lowercase hexadecimal token, anchored on the gitea keyword to keep false positives low (a bare 40-hex string overlaps with SHA-1 hashes / commit IDs).
  • Verification: GET /api/v1/user with the Authorization: token <token> header.
    • 200 → verified
    • 401 / 403 → determinately unverified (no error)
    • any other status / transport error → indeterminate (verification error returned)
  • SecretParts: populated on every result ({"key": <token>}), per the detector guidelines.
  • Self-hosted instances: uses the standard EndpointSetter / CloudProvider pattern, defaulting to https://gitea.com while supporting user-supplied endpoints.
  • Added Gitea to the DetectorType enum, regenerated the protobuf bindings with make protos, and registered the scanner in pkg/engine/defaults/defaults.go.

Tests cover all five detector states (verified, determinately unverified, indeterminate via unexpected response, indeterminate via timeout, and not-found) using mock HTTP clients, plus a build-tagged integration test for live verification.

Verified locally end to end:

$ trufflehog filesystem ./testdir --no-verification
Found unverified result 🐷🔑❓
Detector Type: Gitea
Raw result: 9f3a7c1e0b6d48a25e1f7c93d04b8a6f2c5e9d10
Host: https://gitea.com

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

Note

Low Risk
Additive detector following existing Git-provider patterns; verification only issues read-only API calls when enabled, with no changes to core scan engine behavior.

Overview
Adds Gitea API token scanning and optional live verification to TruffleHog.

Detection matches 40-character lowercase hex tokens only when a gitea keyword is nearby (to avoid SHA-1 / commit-id collisions). Results include SecretParts and per-endpoint host metadata; self-hosted instances are supported via the usual cloud default (https://gitea.com) and configurable endpoints.

Verification calls GET /api/v1/user with Authorization: token …, treating 200 as verified, 401/403 as definitively invalid, and other responses or network failures as indeterminate verification errors. On success across multiple endpoints, it stops after the first verified hit.

Wiring adds DetectorType_Gitea (1053) in the proto/enum, registers gitea.Scanner in the default detector list, and ships unit tests (pattern, status codes, timeout) plus a build-tagged integration test against live secrets.

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

Add the Gitea entry to the DetectorType enum and regenerate the
protobuf bindings.

Refs trufflesecurity#4718
Detect Gitea API tokens (40-char lowercase hex, anchored on the
"gitea" keyword) and verify them against `GET /api/v1/user` using the
`Authorization: token <token>` header. Supports self-hosted instances
through the standard endpoint customization (defaults to gitea.com).

Populates SecretParts on every result and distinguishes determinate from
indeterminate verification failures. Registered in the default detector
set. Includes pattern tests, verification tests covering all five
detector states, and a build-tagged integration test.

Closes trufflesecurity#4718
@0xDevNinja 0xDevNinja requested a review from a team June 16, 2026 07:53
@0xDevNinja 0xDevNinja requested review from a team as code owners June 16, 2026 07:53

@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 and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit fb1d755. Configure here.

t.Fatalf("wantVerificationError = %v, verification error = %v", tt.wantVerificationErr, got[i].VerificationError())
}
}
ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "RawV2", "ExtraData", "verificationError")

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.

Integration test doesn't handle SecretParts field comparison

Medium Severity

The integration test's cmpopts.IgnoreFields list omits SecretParts, but FromData populates SecretParts: map[string]string{"key": token} on every result. The want structs don't set SecretParts, so cmp.Diff will report a mismatch and the test will fail when run under the detectors build tag. Every other detector that sets SecretParts either nulls it before comparison (like GitLab: got[i].SecretParts = nil) or includes "SecretParts" in the ignore list.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fb1d755. Configure here.

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.

Gitea API Token Detector

1 participant