Skip to content

[Fix] Line number issue for custom detector #3997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 59 commits into from
May 16, 2025

Conversation

kashifkhan0771
Copy link
Contributor

@kashifkhan0771 kashifkhan0771 commented Mar 27, 2025

Description:

This PR resolves the incorrect line number issue for custom detectors with multiple regex patterns. It introduces a new configuration field that allows selecting one pattern as the primary. Matches from this primary regex will be used to determine the line number.

This is also helpful for detectors that append multiple matches to the RAW field. To specify a primary secret for a detector, simply add:

s1.SetPrimarySecretValue(match)

The engine will then use this primary secret to determine the line number. If a primary secret is not set, the engine will fall back to using the RAW field to locate the line number, as it currently does.

Related Ticket: CSM-864 | OSS-139

Checklist:

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

@kashifkhan0771 kashifkhan0771 changed the title Fix/csm 864 [Fix] Line Number issue for custom detector Mar 27, 2025
@kashifkhan0771 kashifkhan0771 changed the title [Fix] Line Number issue for custom detector [Fix] Line number issue for custom detector Mar 27, 2025
@kashifkhan0771 kashifkhan0771 marked this pull request as ready for review April 4, 2025 10:10
@kashifkhan0771 kashifkhan0771 requested review from a team as code owners April 4, 2025 10:10
@kashifkhan0771 kashifkhan0771 self-assigned this Apr 7, 2025
@zricethezav
Copy link
Collaborator

@kashifkhan0771 do we have any examples of what this looks like in the output? Can we write some tests for this?

@kashifkhan0771
Copy link
Contributor Author

@kashifkhan0771 do we have any examples of what this looks like in the output? Can we write some tests for this?

Currently, I did not print those secrets in the output. Instead, I stored them in the result and use them to identify the exact line number. I can add some test cases for the custom detector where we use this approach for multi-pattern.

@kashifkhan0771 kashifkhan0771 requested a review from ahrav May 13, 2025 08:15
Copy link
Collaborator

@rosecodym rosecodym left a comment

Choose a reason for hiding this comment

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

approving the six lines of this that are owned by the scanning team

Copy link
Collaborator

@ahrav ahrav left a comment

Choose a reason for hiding this comment

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

Awesome job @kashifkhan0771 ! This looks great.

@zricethezav zricethezav merged commit 6cd30e1 into trufflesecurity:main May 16, 2025
13 checks passed
@kashifkhan0771 kashifkhan0771 deleted the fix/csm-864 branch May 19, 2025 04:54
abmussani added a commit to bunnyanon/trufflehog that referenced this pull request May 21, 2025
* main: (121 commits)
  Fixed Grafana detector (trufflesecurity#4166)
  Reduce verbosity of chunk trace logging (trufflesecurity#4161)
  Increase postman logging verbosity (trufflesecurity#4160)
  Change github file extension log message verbosity (trufflesecurity#4159)
  docs: fix typos (trufflesecurity#4158)
  fix(twitch): Update Twitch detector to handle new RawV2 field and adjust test expectations (trufflesecurity#4150)
  Add a bunch of Postman logging (trufflesecurity#4154)
  Added DataBricks Analyzer (trufflesecurity#4135)
  fixed shopify detector line number (trufflesecurity#4149)
  chore: run setup-go after checkout (trufflesecurity#4143)
  Add per-chunk detection logging (trufflesecurity#4152)
  [Feat] Added Dropbox API OAuth2 Token Analyzer (trufflesecurity#4080)
  Updated Github Source Validate method (trufflesecurity#4144)
  replace anthropic reference with groq (trufflesecurity#4147)
  [Fix] Line number issue for custom detector (trufflesecurity#3997)
  fix(postman): prevent infinite recursion in variable substitution (trufflesecurity#4145)
  Add metrics to the Postman source (trufflesecurity#4142)
  [Feat] Implementation of Posthog Analyzer (trufflesecurity#4103)
  [Feat] Added Mux API Analyzer (trufflesecurity#4128)
  fixed name of netlify analyzer in cli output (trufflesecurity#4140)
  ...

# Conflicts:
#	pkg/pb/detectorspb/detectors.pb.go
#	proto/detectors.proto
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.

4 participants