Skip to content

[INS-402] Add Jira Data Center PAT Detector#4872

Open
mustansir14 wants to merge 7 commits intomainfrom
INS-402-Support-custom-verification-endpoints-in-the-Jira-detector
Open

[INS-402] Add Jira Data Center PAT Detector#4872
mustansir14 wants to merge 7 commits intomainfrom
INS-402-Support-custom-verification-endpoints-in-the-Jira-detector

Conversation

@mustansir14
Copy link
Copy Markdown
Contributor

@mustansir14 mustansir14 commented Apr 7, 2026

Summary

Adds a new detector for Jira Data Center Personal Access Tokens (PATs).

Regex

PATs are base64-encoded strings of the form <12-digit-id>:<20-random-bytes> (33 bytes, 44 chars, no padding). Since the first byte is always an ASCII digit, the first base64 character is always M, N, or O. The trailing boundary (?:[^A-Za-z0-9+/=]|\z) is used instead of \b to correctly handle tokens ending in + or /, while still rejecting matches that are a prefix of a longer or padded base64 string.

(?i:jira|atlassian)(?:.|[\n\r]){0,40}?\b([MNO][A-Za-z0-9+/]{43})(?:[^A-Za-z0-9+/=]|\z)

Server URLs are captured using the same keyword prefix:

(?i:jira|atlassian)(?:.|[\n\r]){0,40}?(https?://[A-Za-z0-9][A-Za-z0-9.\-]*(?::\d{1,5})?)

Both patterns require a jira or atlassian keyword within 40 characters to reduce false positives. Extracted URLs are tried alongside any user-configured endpoints.

Verification

Verifies against GET /rest/api/2/myself using Authorization: Bearer <token>. Returns display_name and email_address as extra data on 200. Treats 401 as invalid and anything else as a verification error. Docs: https://developer.atlassian.com/server/jira/platform/rest/v10002/api-group-myself/#api-api-2-myself-get

Tests

Pattern tests cover valid tokens, URL detection near jira/atlassian keywords, and negative cases. Verification tests use gock to mock the /rest/api/2/myself endpoint, covering verified, unverified (401), unexpected status, timeout, and no-verify cases.

Integration tests against a live Jira Data Center instance were not possible because Jira Data Center requires a paid license — there is no free tier or open-source image that runs fully without one. Unlike detectors such as Redis or MongoDB where a fully functional Docker container can be spun up freely, the atlassian/jira-software Docker image requires a valid license key to operate. Atlassian's evaluation licenses are time-limited and account-bound, making them unsuitable for automated CI.

Corpora Test

The detector does not appear in the Corpora Test Results.
image
image

Checklist:

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

Note

Medium Risk
Adds a new secret detector with optional live HTTP verification against user-supplied Jira endpoints, which could affect scan behavior and introduce new outbound requests/timeouts.

Overview
Adds a new JiraDataCenterPAT detector that identifies Jira Data Center personal access tokens via a keyword-prefixed base64 pattern and optionally verifies them by calling GET /rest/api/2/myself with a Bearer token, returning basic user metadata as ExtraData on success.

Wires the detector into the default detector set and engine endpoint expectations, and extends the protobuf DetectorType enum to include JiraDataCenterPAT. Includes unit tests covering pattern matching (including URL association/edge cases) and verification outcomes (200/401/unexpected status/timeout/no-verify).

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

@mustansir14 mustansir14 requested a review from a team April 7, 2026 11:30
@mustansir14 mustansir14 requested review from a team as code owners April 7, 2026 11:30
Copy link
Copy Markdown

@cursor cursor bot left a comment

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 6d540d2. Configure here.

var tokens []string
for _, match := range patPat.FindAllStringSubmatch(dataStr, -1) {
tokens = append(tokens, match[1])
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tokens not deduplicated unlike comparable detectors

Low Severity

Matched tokens are collected into a plain []string slice without deduplication. Every comparable endpoint-based detector in the codebase (artifactory, artifactoryreferencetoken, jiratoken/v2) deduplicates tokens using a map[string]struct{}. When the same PAT appears near multiple jira/atlassian keywords in the input, this produces duplicate results and redundant verification HTTP requests for each repeated token–endpoint pair.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6d540d2. Configure here.


if verify {
isVerified, extraData, verificationErr := verifyPAT(ctx, s.getClient(), endpoint, token)
s1.Verified = isVerified
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.

Had a look at Jira Analyzer and it seems it does support custom domains. Can you verify if the analyzer works for this detector too? If yes, we should add AnalysisInfo

)

var (
defaultClient = common.SaneHttpClient()
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.

Worth switching from common.SaneHttpClient() to detectors.DetectorHttpClientWithNoLocalAddresses so RFC1918 addresses are blocked by default.
The other Jira detectors use it as well. What do you think?

// Ensure the Scanner satisfies the interfaces at compile time.
var (
_ detectors.Detector = (*Scanner)(nil)
_ detectors.EndpointCustomizer = (*Scanner)(nil)
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.

Do you think this detector might be a candidate for detectors.DefaultMultiPartCredentialProvider?

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.

3 participants