-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from ninoseki/add-npm-detector
Add npm detector
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
""" | ||
This plugin searches for NPM tokens | ||
""" | ||
import re | ||
|
||
from detect_secrets.plugins.base import RegexBasedDetector | ||
|
||
|
||
class NpmDetector(RegexBasedDetector): | ||
"""Scans for NPM tokens.""" | ||
secret_type = 'NPM tokens' | ||
|
||
denylist = [ | ||
# npmrc authToken | ||
# ref. https://stackoverflow.com/questions/53099434/using-auth-tokens-in-npmrc | ||
re.compile(r'\/\/.+\/:_authToken=.+'), | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
|
||
from detect_secrets.plugins.npm import NpmDetector | ||
|
||
|
||
class TestNpmDetector: | ||
|
||
@pytest.mark.parametrize( | ||
'payload, should_flag', | ||
[ | ||
('//registry.npmjs.org/:_authToken=xxxxxxxxxxxxxxxxxxxx', True), | ||
('//registry.npmjs.org:_authToken=xxxxxxxxxxxxxxxxxxxx', False), | ||
('registry.npmjs.org/:_authToken=xxxxxxxxxxxxxxxxxxxx', False), | ||
('///:_authToken=xxxxxxxxxxxxxxxxxxxx', False), | ||
('_authToken=xxxxxxxxxxxxxxxxxxxx', False), | ||
('foo', False), | ||
], | ||
) | ||
def test_analyze(self, payload, should_flag): | ||
logic = NpmDetector() | ||
output = logic.analyze_line(filename='mock_filename', line=payload) | ||
assert len(output) == int(should_flag) |