Skip to content
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

added npm detector #841

Merged
merged 4 commits into from
Oct 13, 2022
Merged

added npm detector #841

merged 4 commits into from
Oct 13, 2022

Conversation

ankushgoel27
Copy link
Contributor

Added NPM detector. Only using regex for the old format. NPM introduced a new format which is NPM_[0-9a-zA-z]{36}. Not sure how to add both regexes to the same npmtoken.go file

@ankushgoel27 ankushgoel27 requested a review from a team as a code owner October 11, 2022 13:53
@ahrav
Copy link
Collaborator

ahrav commented Oct 11, 2022

@ankushgoel27 thanks for adding this detector, really appreciate it. As for the approach I would take in this case, I would probably include a second keyPat regex that covered the new format. Initially I was thinking maybe we could use a single regex leveraging maybe | if they were similar enough something similar to (

keyPat = regexp.MustCompile(`\b((?:dop|doo|dor)_v1_[a-f0-9]{64})\b`)
) (not quite the same). That might not be the best way because the regexes look rather different to me.

I'm also sure there is a way to write a regex to cover both cases, but at that point reading the regex might be more cumbersome that writing two.

@ankushgoel27
Copy link
Contributor Author

They are very dissimilar. I tried creating one regex for both but its more complicated. how do i include a second keypat? sorry, not so very well versed in golang. maybe you can help :)

the new format regex is npm_[0-9a-zA-Z]{36}

@ankushgoel27
Copy link
Contributor Author

ok, figured it out. Will send a pull request soon.

@ankushgoel27
Copy link
Contributor Author

Hi,

during my testing, i had a file with multiple valid old format tokens and new format tokens. But trufflehog was detecting only 1 of each. it should detect all tokens present in the file.

@ankushgoel27
Copy link
Contributor Author

Fixed naming convention and detection of multiple tokens. Ready to be merged

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.

LGTM. Thanks a lot for adding these.

@ahrav ahrav merged commit d29357c into trufflesecurity:main Oct 13, 2022
@AQAqoma AQAqoma mentioned this pull request Oct 24, 2022
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants