Skip to content

fix(detectors/ngrok): match API keys that do not start with 2 - #5152

Open
mattbrady-1 wants to merge 1 commit into
mainfrom
fix/ngrok-detector-api-key-pattern
Open

fix(detectors/ngrok): match API keys that do not start with 2#5152
mattbrady-1 wants to merge 1 commit into
mainfrom
fix/ngrok-detector-api-key-pattern

Conversation

@mattbrady-1

Copy link
Copy Markdown
Contributor

Summary

  • Broaden the ngrok detector regex from 2[a-zA-Z0-9]{26}_... to [a-zA-Z0-9]{27}_... so valid bearer tokens are detected regardless of first character.
  • Add tests for API keys not starting with 2 and for ak_ resource IDs, which are not secrets.

Test plan

  • go test ./pkg/detectors/ngrok/ -run TestNgrok_Pattern
  • Scan fixture containing a valid ngrok API bearer token and confirm verified detection

Made with Cursor

The ngrok bearer token pattern is 27 alphanumerics, an underscore, and 21
alphanumerics. Requiring a leading 2 missed valid API keys and ak_ resource
IDs were never secrets.

Co-authored-by: Cursor <cursoragent@cursor.com>
@mattbrady-1
mattbrady-1 requested a review from a team July 23, 2026 16:15
@mattbrady-1
mattbrady-1 requested a review from a team as a code owner July 23, 2026 16:15

@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

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7aa6716. Configure here.

keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"ngrok"}) + `\b(2[a-zA-Z0-9]{26}_\d[a-zA-Z0-9]{20})\b`)
// ngrok API keys and authtokens are {prefix}_{suffix} with a digit-leading suffix.
// API keys are 27+21 chars; authtokens vary but share the same charset constraints.
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"ngrok"}) + `\b([a-zA-Z0-9]{27}_[a-zA-Z0-9]{21})\b`)

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.

Regex accidentally drops digit-leading suffix constraint

Medium Severity

The comment on line 41 describes "a digit-leading suffix" but the new regex uses [a-zA-Z0-9]{21} for the suffix, which allows it to start with any alphanumeric character. The old regex enforced \d[a-zA-Z0-9]{20} for the suffix portion. The PR intended only to broaden the prefix (removing the 2 requirement), but the suffix constraint was also accidentally dropped, which could increase false positive detections.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7aa6716. Configure here.

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.

The bugbot comment looks correct.

One caveat on the suffix: I created four authtokens, and one came back 20 chars with a non-digit leading char (verified real via agent_ingresses : ERR_NGROK_206). So v2 can't assume 21 chars or a digit-leading suffix, it needs to allow {20,21} and letter-or-digit start.

@github-actions

Copy link
Copy Markdown

Corpora Test Results

Scans 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.

0 new · 1 clean  |  Scoped to: ngrok

Status Detector Unique matches (main) Unique matches (PR) New Removed
ngrok 0 0 0 0
  • 🔴 regression: >5 new, >20% increase over main, or any removed
  • ⚠️ warning: 1–5 new and ≤20% increase over main
  • ✅ clean
  • 🆕 new detector (no baseline)

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.

2 participants