Skip to content

feat: add OpenRouter detector - #4500

Merged
shahzadhaider1 merged 9 commits into
trufflesecurity:mainfrom
McPatate:feat/add_openrouter_detector
Jul 3, 2026
Merged

feat: add OpenRouter detector#4500
shahzadhaider1 merged 9 commits into
trufflesecurity:mainfrom
McPatate:feat/add_openrouter_detector

Conversation

@McPatate

@McPatate McPatate commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

closes #4499

Description:

Adds the OpenRouter detector as discussed in #4499.

Checklist:

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

Note: I ran make lint and I'm seeing quite the list of warnings, although none related to the changes I made afaict. Is this safe to ignore?

image

Note

Low Risk
Additive detector-only change following existing patterns; verification is a read-only external API call with no changes to auth or core scan pipeline.

Overview
Adds OpenRouter as a new secret detector so scans can find sk-or-v1- API keys and optionally confirm them against OpenRouter.

The new scanner matches keys with a strict hex pattern, deduplicates hits, redacts output, and when verification is on calls GET https://openrouter.ai/api/v1/key with a Bearer token. Valid keys get extra metadata (label, limits, usage, free tier). 401 is treated as invalid; other status codes surface as verification errors.

Wiring follows other gated detectors: new DetectorType_OpenRouter (1057) in proto and generated pb, OpenRouterDetectorEnabled in pkg/feature, registration in buildDetectorList() with feature-flag filtering, default on in main.go, and excludedFromDefaultList updated so the defaults test stays consistent. Unit tests cover regex/keyword behavior; integration tests (build tag detectors) cover live verify with GCP test secrets.

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

@McPatate
McPatate requested a review from a team October 15, 2025 13:01
@McPatate
McPatate requested a review from a team as a code owner October 15, 2025 13:01
Comment thread pkg/pb/detectorspb/detectors.pb.go
@McPatate
McPatate force-pushed the feat/add_openrouter_detector branch from f436f10 to 8cee242 Compare October 15, 2025 14:00
@McPatate
McPatate requested a review from a team October 15, 2025 14:00
@McPatate
McPatate force-pushed the feat/add_openrouter_detector branch from c192f0c to 8cee242 Compare October 16, 2025 13:03
@McPatate

Copy link
Copy Markdown
Contributor Author

Hey @shahzadhaider1, lmk if there's anything needed from me to move this PR forward!

@shahzadhaider1

Copy link
Copy Markdown
Contributor

Hey @shahzadhaider1, lmk if there's anything needed from me to move this PR forward!

Hey @McPatate, thank you for the contribution. It looks good, but we’re currently pausing the addition of new detectors. We’ll get this merged once we’ve refined our process for maintaining them.

@McPatate

Copy link
Copy Markdown
Contributor Author

Ok thanks for letting me know! Do you have an idea of the timeline wrt to:

We’ll get this merged once we’ve refined our process for maintaining them.

?

@camgunz

camgunz commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

Thanks for your patience @McPatate -- we're kicking around ideas for getting this merged in a stable fashion. I should have more for you soon; hopefully today.

@camgunz

camgunz commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

OK I've got something of a testing strategy defined; I'm hoping to find the time today or tomorrow (likely tomorrow) to set that up and run this through. Will keep you updated.

EDIT: I should say this involves running tons of specific data through this thing, so it's not the kind of test we can reasonably ask contributors to do, at least not yet.

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

OK this looks good! Again thanks for your patience.

Comment thread pkg/detectors/openrouter/openrouter.go Outdated
Comment thread pkg/detectors/openrouter/openrouter.go Outdated

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

Looks good. Thank you for the great work. We really appreciate it.

@McPatate

Copy link
Copy Markdown
Contributor Author

Happy to contribute 😄

@cristinaponcela

Copy link
Copy Markdown

@shahzadhaider1 any update on this? I would like to see this change land too :) lmk if I can help

@shahzadhaider1

Copy link
Copy Markdown
Contributor

@shahzadhaider1 any update on this? I would like to see this change land too :) lmk if I can help

There are currently some merge conflicts in the branch. We'll either wait for the author to resolve them or take a look ourselves and get the PR merged.

@McPatate
McPatate force-pushed the feat/add_openrouter_detector branch from e121ba8 to 11e5937 Compare June 23, 2026 09:57
@McPatate
McPatate requested a review from a team as a code owner June 23, 2026 09:57
@McPatate
McPatate requested a review from a team June 23, 2026 09:57
@McPatate

Copy link
Copy Markdown
Contributor Author

Fixed the conflicts, lmk if the PR is still the expected way to add a detector!

Comment thread pkg/detectors/openrouter/openrouter.go
@cristinaponcela

Copy link
Copy Markdown

@McPatate legend, thanks! (I am not part of trufflehog, just a user that needs the change you added :P)

@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

Reviewed by Cursor Bugbot for commit 623e121. Configure here.

Comment thread pkg/detectors/openrouter/openrouter.go Outdated
@McPatate

Copy link
Copy Markdown
Contributor Author

@shahzadhaider1 friendly ping :)

McPatate and others added 5 commits July 1, 2026 21:40
* refactor: remove unnecessary `AnalysisInfo` field
Signed-off-by: Luc Georges <luc.sydney.georges@gmail.com>
Signed-off-by: Luc Georges <luc.sydney.georges@gmail.com>
@shahzadhaider1
shahzadhaider1 force-pushed the feat/add_openrouter_detector branch from a3288ca to 9ad890b Compare July 2, 2026 11:06

@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. Just two non-blocking comments.

"github.com/trufflesecurity/trufflehog/v3/pkg/engine/ahocorasick"
)

func TestOpenRouter_Pattern(t *testing.T) {

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.

Can we add more test and follow the pattern similar to browserStack_test.go

var _ detectors.Detector = (*Scanner)(nil)

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.

Can we use dedupe client here. Inspiration can be taken from meraki detector.

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

🤠

@shahzadhaider1
shahzadhaider1 merged commit f2cd191 into trufflesecurity:main Jul 3, 2026
16 checks passed
@McPatate
McPatate deleted the feat/add_openrouter_detector branch July 8, 2026 12:15
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.

Add openrouter detector

6 participants