[INS-497] Add Pganalyze Read Key Detector - #4993
Conversation
Corpora Test ResultsScans a corpus of real-world public code against only the detectors changed in this PR, then compares unique match counts between the PR build and the main baseline to catch regex regressions. Verification is disabled — each detector's regex is measured independently. 1 new · 0 clean | Scoped to:
|
| Raw: []byte(token), | ||
| SecretParts: map[string]string{ | ||
| "key": token, | ||
| "access_type": "read", |
There was a problem hiding this comment.
I think it's worth adding this to the ExtraData as well.
There was a problem hiding this comment.
Since the detector name is PgAnalyzeReadKey, which already indicates that this is a read-only key, what additional value does access_type: read provide in the secret metadata?
Also, can this secret type have other permission levels (e.g. write or admin), or is it always read-only?
There was a problem hiding this comment.
The token only has read permissions. Also, I think we should keep access_type because if we decide to build an analyzer for this detector in the future, we'll likely want a single analyzer that can handle different types of pganalyze tokens. Since detector_type isn't available in the analyzer input, the analyzer wouldn't know which detector triggered it. Having access_type would provide the necessary context to determine how the token should be analyzed.
There was a problem hiding this comment.
Also ExtraData doesn't make sense here because it is clear from the detector that the found token is a read key.
Description
This PR adds the pganalyze Read API Key Detector for TruffleHog.
It scans for pganalyze Read API keys and optionally verifies them via the official pganalyze GraphQL API.
Regex:
The detector uses the contextual keyword
pgar_to reduce false positives.Verification
For verification, we use the pganalyze GraphQL API endpoint:
We send a
POSTrequest with the token in theAuthorizationheader using the format:A response code of:
200 OKmeans the API key is valid401 Unauthorizedmeans the API key is invalid.This API endpoint is part of the official pganalyze API surface and can be used safely for verification. The verification request performs a read-only GraphQL query and does not perform any destructive actions.
Checklist:
make test-community)?make lintthis requires golangci-lint)?Note
Low Risk
Additive detector following existing feature-flag and verification patterns; no changes to core scan or auth paths beyond optional outbound HTTP during verify.
Overview
Adds PgAnalyze Read Key detection for tokens matching
pgar_plus 27 alphanumeric characters, with thepgar_keyword for Aho-Corasick pre-filtering.When verification is enabled, keys are checked via a
POSTtohttps://app.pganalyze.com/graphqlusingAuthorization: Token <key>; 200 marks verified and 401 invalid.Wires the scanner into default detectors behind
PgAnalyzeReadKeyDetectorEnabled(enabled in OSSmain.go), registersDetectorType_PgAnalyzeReadKey = 1054in proto/generated code, and adds unit, pattern, and integration tests.Reviewed by Cursor Bugbot for commit 4bd646f. Bugbot is set up for automated code reviews on this repo. Configure here.