Skip to content

Commit

Permalink
feat(plugin-npm): support any length of npm token e.g. gitlab token
Browse files Browse the repository at this point in the history
  • Loading branch information
Dazix committed Mar 31, 2023
1 parent 5c9830a commit 1cbac9a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion detect_secrets/plugins/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ 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'\/\/.+\/:_authToken=\s*(?!\$\{[A-Z_]+\})((npm_.+)|\S+).*'),
]
2 changes: 2 additions & 0 deletions tests/plugins/npm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class TestNpmDetector:
('_authToken=743b294a-cd03-11ec-9d64-0242ac120002', False),
('foo', False),
('//registry.npmjs.org/:_authToken=${NPM_TOKEN}', False),
('//gitlab.com/api/v4/projects/1347/packages/npm/:_authToken=glpat-a8r3xUFrtP-isd1DLK_r', True),
('//gitlab.com/api/v4/projects/1347/packages/npm/:_authToken=${CI_JOB_TOKEN}', False),
],
)
def test_analyze(self, payload, should_flag):
Expand Down

0 comments on commit 1cbac9a

Please sign in to comment.