forked from Yelp/detect-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a plugin for GitHub token detection
- Loading branch information
Showing
2 changed files
with
35 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,16 @@ | ||
""" | ||
This plugin searches for GitHub tokens | ||
""" | ||
import re | ||
|
||
from detect_secrets.plugins.base import RegexBasedDetector | ||
|
||
|
||
class GitHubTokenDetector(RegexBasedDetector): | ||
"""Scans for GitHub tokens.""" | ||
secret_type = 'GitHub token' | ||
|
||
denylist = [ | ||
# ref. https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/ | ||
re.compile(r'(ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9_]{36}'), | ||
] |
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,19 @@ | ||
import pytest | ||
|
||
from detect_secrets.plugins.github_token import GitHubTokenDetector | ||
|
||
|
||
class TestGitHubTokenDetector: | ||
|
||
@pytest.mark.parametrize( | ||
'payload, should_flag', | ||
[ | ||
('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', True), | ||
('foo_wWPw5k4aXcaT4fNP0UcnZwJUVFk6LO0pINUx', False), | ||
('foo', False), | ||
], | ||
) | ||
def test_analyze(self, payload, should_flag): | ||
logic = GitHubTokenDetector() | ||
output = logic.analyze_line(filename='mock_filename', line=payload) | ||
assert len(output) == int(should_flag) |