Skip to content

Commit 9b4ec6d

Browse files
authored
Merge pull request #347 from ninoseki/add-npm-detector
Add npm detector
2 parents 2d300cb + f92bb41 commit 9b4ec6d

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

detect_secrets/plugins/npm.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
This plugin searches for NPM tokens
3+
"""
4+
import re
5+
6+
from detect_secrets.plugins.base import RegexBasedDetector
7+
8+
9+
class NpmDetector(RegexBasedDetector):
10+
"""Scans for NPM tokens."""
11+
secret_type = 'NPM tokens'
12+
13+
denylist = [
14+
# npmrc authToken
15+
# ref. https://stackoverflow.com/questions/53099434/using-auth-tokens-in-npmrc
16+
re.compile(r'\/\/.+\/:_authToken=.+'),
17+
]

tests/plugins/npm_test.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
3+
from detect_secrets.plugins.npm import NpmDetector
4+
5+
6+
class TestNpmDetector:
7+
8+
@pytest.mark.parametrize(
9+
'payload, should_flag',
10+
[
11+
('//registry.npmjs.org/:_authToken=xxxxxxxxxxxxxxxxxxxx', True),
12+
('//registry.npmjs.org:_authToken=xxxxxxxxxxxxxxxxxxxx', False),
13+
('registry.npmjs.org/:_authToken=xxxxxxxxxxxxxxxxxxxx', False),
14+
('///:_authToken=xxxxxxxxxxxxxxxxxxxx', False),
15+
('_authToken=xxxxxxxxxxxxxxxxxxxx', False),
16+
('foo', False),
17+
],
18+
)
19+
def test_analyze(self, payload, should_flag):
20+
logic = NpmDetector()
21+
output = logic.analyze_line(filename='mock_filename', line=payload)
22+
assert len(output) == int(should_flag)

0 commit comments

Comments
 (0)