Skip to content

Detect Linear API keys - #84

Closed
akgupta2002D wants to merge 3 commits into
omerbek:mainfrom
akgupta2002D:fix/linear-api-key
Closed

akgupta2002D wants to merge 3 commits into
omerbek:mainfrom
akgupta2002D:fix/linear-api-key

Conversation

@akgupta2002D

Copy link
Copy Markdown

Fixes #63

What this changes and why

RepoDx didn't report Linear personal API keys (lin_api_...). There were two gaps, and this PR fixes both:

  • No pattern. Adds ("Linear API key", r"\blin_api_[A-Za-z0-9]{40}\b") to SECRET_PATTERNS, next to Replicate.
  • No candidate literal. Adds "lin_api_" to CANDIDATE_LITERALS. Without it, check_file_contents drops the line at the has_candidate checks (lines 789 and 797) before it reaches the scanner. So the regex alone passes the issue's line-level test but still misses the key in a real file scan.

Tests:

  • The issue's entry in test_detects_provider_keys, built with fake(...).
  • test_detects_linear_api_key_in_a_file: one critical "Linear API key" finding at src/config.js:2. This test fails if only the regex is added.
  • test_linear_api_key_needs_forty_characters: 39 characters isn't reported. It passes before and after, so it's a false-alarm guard, not proof of the fix.

Not changed: severities, looks_fake, FIXES, the README provider lists, versions, and the CHANGELOG. I followed how #43, #47 and #60 were shaped.

On length: Linear doesn't document it. I matched exactly 40, as the issue suggests. That's also gitleaks' default rule (lin_api_(?i)[a-z0-9]{40}). One third-party page shows a 32-character example, which this pattern won't catch. If you'd rather accept a range, it's a one-character change, and I'm happy to make it.

Before and after

Fake keys built at runtime. The full scan is of a folder whose config.js reads process.env.FOO and holds a 40-character key.

Before (main e845025):

lin_api_ (40 chars) has_candidate: False scan_line: []
npm_ (control)      scan_line: [('secret', 'critical', 'npm access token')]
full scan:          Found: 0 critical, 3 warnings, 1 info

After (this branch):

lin_api_ (40 chars) has_candidate: True scan_line: [('secret', 'critical', 'Linear API key')]
npm_ (control)      scan_line: [('secret', 'critical', 'npm access token')]
full scan:          Found: 1 critical, 3 warnings, 1 info
                    [CRITICAL] Linear API key - config.js:2  (lin_ap...nC)

With repodx.py reverted to main, the new tests fail (FAILED (failures=2)). With only the regex added, the file-level test fails (FAILED (failures=1)).

Checks

  • python3 -m unittest discover: Ran 117 tests ... OK on Python 3.13.2 and 3.9.6
  • python3 repodx.py .: 100/100 (A), 0 critical, 0 warnings, 0 info
  • False alarms: main and this branch give identical scores and finding counts on four other local repositories, with 0 Linear findings.

AI use

I used Claude Code (Anthropic) throughout. It helped me:

  • read check_file_contents and spot the CANDIDATE_LITERALS gap
  • look up the gitleaks rule and how earlier provider PRs were shaped
  • run the reproduction and the before/after checks

I chose the length and the scope, checked every output above myself, and reviewed the diff line by line.

akgupta2002D and others added 3 commits November 22, 2026 23:10
Reproduces omerbek#63: scan_line_for_secrets returns [] for a lin_api_ key
because there is no Linear pattern in SECRET_PATTERNS yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The file-level test fails unless lin_api_ is also in CANDIDATE_LITERALS,
since check_file_contents skips lines that has_candidate() rejects. The
39-character case guards against false alarms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a Linear API key pattern to SECRET_PATTERNS (lin_api_ followed by
40 letters or digits, as in the issue and gitleaks' default rule) and
add lin_api_ to CANDIDATE_LITERALS so file scans reach the line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
omerbek added a commit that referenced this pull request Nov 23, 2026
omerbek added a commit that referenced this pull request Nov 23, 2026
@omerbek omerbek mentioned this pull request Nov 23, 2026
@omerbek omerbek closed this in #85 Nov 23, 2026
@akgupta2002D

Copy link
Copy Markdown
Author

Thanks for landing this in #85 and for resolving the conflict with the Sentry detector in #83. I appreciate you keeping the file-level test; it's the one that catches a regex-only fix.

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.

Detect Linear API keys (lin_api_...)

1 participant