[INS-468] Add improved lob detector to defaults.go#4971
Open
mustansir14 wants to merge 4 commits into
Open
Conversation
Corpora Test ResultsScans 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. 1 new · 0 clean | Scoped to:
|
shahzadhaider1
approved these changes
May 20, 2026
d67397f to
5d7fa71
Compare
kashifkhan0771
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Lob detector existed in the codebase but was never registered in the default detector list in
defaults.go. This PR adds it to the defaults and, after discovering via corpora testing that the original regex was too loose and produced significant noise, refactors the detector to be more precise and follow current practices.Regex tightened to reduce noise (the core fix):
The original regex relied on a loose proximity-based prefix match against the word
"lob"and matched any 40-character alphanumeric string:Corpora testing showed this was extremely noisy. Lob API keys have a well-defined format — they always begin with
live_ortest_— so the new regex anchors on that structure:Keywords updated to match key prefix:
["lob"]["live_", "test_"]This makes pre-filtering align with the actual key format rather than relying on a nearby context word.
Additional improvements (following current detector practices):
Scannerstruct now accepts an injectable*http.Client(viagetClient()helper) to support test mocking without a global variable.clientrenamed todefaultClientto avoid shadowing.verify()method.GET /v1/addressestoPOST /v1/us_verifications. The old endpoint returns401 Unauthorizedboth for invalid keys and for active keys with no billing method on file, making it impossible to distinguish between the two cases. The new endpoint returns403 Forbiddenfor active keys with no billing method, allowing a correct verification signal. Status code handling:403 Forbidden→ verified (active key, no billing method on file)422 Unprocessable Entity→ verified (active key, request body is invalid — expected for an empty POST)401 Unauthorized→ not verifiedExtraDatafield added to expose the key environment (liveortest).Gating behind feature flag
Since this is considered a new detector addition, it is gated behind a feature flag. This is why the PR is based off of #4969 which contains some require plumbing for this.
Checklist:
make test-community)?make lintthis requires golangci-lint)?Note
Medium Risk
Medium risk because it changes default scanning behavior by enabling a new detector and updates its verification HTTP behavior, which could affect scan performance and result accuracy.
Overview
Adds the Lob detector to the default detector set (now included in
defaults.go) and introduces a newfeature.LobDetectorEnabledflag that is enabled by default inmain.goand used to gate the detector in the default list.Refactors the Lob detector to reduce noise and improve verification: updates the regex/keywords to match
live_/test_key formats, deduplicates matches, addsExtraData.environment, and replaces the old verification call with a newPOST /v1/us_verificationsstatus-code based verifier (with injectable HTTP client). Tests are updated to reflect the new patterns, metadata, and verification expectations.Reviewed by Cursor Bugbot for commit 01cd8bf. Bugbot is set up for automated code reviews on this repo. Configure here.