Skip to content

fix(detectors/harness): allow underscore in PAT account segment - #5153

Open
mattbrady-1 wants to merge 1 commit into
mainfrom
fix/harness-detector-underscore
Open

fix(detectors/harness): allow underscore in PAT account segment#5153
mattbrady-1 wants to merge 1 commit into
mainfrom
fix/harness-detector-underscore

Conversation

@mattbrady-1

Copy link
Copy Markdown
Contributor

Summary

  • Allow _ in the 22-character account segment of Harness pat.* API keys so tokens like pat.YDfcEm2LT_OUZrFZv1WVlg... are detected during scans.
  • Add a unit test covering underscore-bearing PATs.

Test plan

  • go test ./pkg/detectors/harness/ -run TestHarness_Pattern -v
  • CI

Made with Cursor

Harness PAT tokens can include underscores in the 22-character account
segment; widen the detector regex so live keys are found during scans.

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

@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 3d82dc3. Configure here.

defaultClient = common.SaneHttpClient()

keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"harness"}) + `\b(pat\.[A-Za-z0-9]{22}\.[0-9a-f]{24}\.[A-Za-z0-9]{20})\b`)
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"harness"}) + `\b(pat\.[A-Za-z0-9_]{22}\.[0-9a-f]{24}\.[A-Za-z0-9]{20})\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 missing hyphen for base64url account segment

Low Severity

The 22-character account segment appears to be base64url-encoded (22 chars = 128 bits, typical UUID), and base64url uses both _ (replacing /) and - (replacing +). The character class [A-Za-z0-9_]{22} adds _ but omits -, so PATs with a hyphen in the account segment remain undetected. Other detectors in the codebase (e.g., bitfinex, cloudflareapitoken, discordbottoken) use [A-Za-z0-9_-] for equivalent base64url segments.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3d82dc3. Configure here.

@MuneebUllahKhan222 MuneebUllahKhan222 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.

LGTM, Is there any relevant issue or article that points out this specific _ requirement?

@mattbrady-1

Copy link
Copy Markdown
Contributor Author

@MuneebUllahKhan222 yes, I'm stumbling across the out-of-date detectors because I am creating new secrets with better analyzer permissions and resources for our demo environment. Customers will have the '_' in their secrets.

@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: harness

Status Detector Unique matches (main) Unique matches (PR) New Removed
harness 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