Skip to content

Commit

Permalink
Improve npm detection (#220)
Browse files Browse the repository at this point in the history
Co-authored-by: Matan Shati <>
  • Loading branch information
matansha authored Sep 9, 2024
1 parent 2f371f9 commit 3e5b098
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion detect_secrets/plugins/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ class NpmDetector(RegexBasedDetector):
denylist = [
# npmrc authToken
# ref. https://stackoverflow.com/questions/53099434/using-auth-tokens-in-npmrc
re.compile(r'\/\/.+\/:_authToken=\s*((npm_.+)|([A-Fa-f0-9-]{36})).*'),
re.compile(
r'(?:npm_[A-Za-z0-9-]{36})|' +
r'(?:(?:_authToken|NPM[ _-]?TOKEN)[\s\S]{0,5}?(?:NpmToken\.)?([a-z0-9-]{36}).*)',
),
]
11 changes: 6 additions & 5 deletions tests/plugins/npm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class TestNpmDetector:
('//registry.npmjs.org/:_authToken=743b294a-cd03-11ec-9d64-0242ac120002', True),
('//registry.npmjs.org/:_authToken=346a14f2-a672-4668-a892-956a462ab56e', True),
('//registry.npmjs.org/:_authToken= 743b294a-cd03-11ec-9d64-0242ac120002', True),
('//registry.npmjs.org/:_authToken=npm_xxxxxxxxxxx', True),
('//registry.npmjs.org:_authToken=743b294a-cd03-11ec-9d64-0242ac120002', False),
('registry.npmjs.org/:_authToken=743b294a-cd03-11ec-9d64-0242ac120002', False),
('///:_authToken=743b294a-cd03-11ec-9d64-0242ac120002', False),
('_authToken=743b294a-cd03-11ec-9d64-0242ac120002', False),
('//registry.npmjs.org/:_authToken=npm_xxxxxxxxxxx', False),
('//registry.npmjs.org:_authToken=743b294a-cd03-11ec-9d64-0242ac120002', True),
('registry.npmjs.org/:_authToken=743b294a-cd03-11ec-9d64-0242ac120002', True),
('///:_authToken=743b294a-cd03-11ec-9d64-0242ac120002', True),
('_authToken=743b294a-cd03-11ec-9d64-0242ac120002', True),
('"_authToken" = "743b294a-cd03-11ec-9d64-0242ac120002"', True),
('foo', False),
('//registry.npmjs.org/:_authToken=${NPM_TOKEN}', False),
],
Expand Down

0 comments on commit 3e5b098

Please sign in to comment.