-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Slack token detector #122
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
""" | ||
This plugin searches for Slack tokens | ||
""" | ||
from __future__ import absolute_import | ||
|
||
import re | ||
|
||
from .base import RegexBasedDetector | ||
|
||
|
||
class SlackDetector(RegexBasedDetector): | ||
secret_type = 'Slack Token' | ||
blacklist = ( | ||
re.compile(r'xox(?:a|b|p|o|s|r)-(?:\d+-)+[a-z0-9]+', flags=re.IGNORECASE), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super nit: We could add length ranges but I couldn't find out how much they vary, e.g. the last field might not be more than 32 chars. I rather we lean towards false-positives and iterate though, i.e. ship as-is 👍 (not that I think there will be any false-positives, since cc @dxa4481, in case you want to compare with your truffleHogRegex |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
import pytest | ||
|
||
from detect_secrets.plugins.slack import SlackDetector | ||
from testing.mocks import mock_file_object | ||
|
||
|
||
class TestSlackDetector(object): | ||
|
||
@pytest.mark.parametrize( | ||
'file_content', | ||
[ | ||
( | ||
'xoxp-523423-234243-234233-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxo-523423-234243-234233-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxs-523423-234243-234233-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxa-511111111-31111111111-3111111111111-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxa-2-511111111-31111111111-3111111111111-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxr-523423-234243-234233-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxb-34532454-e039d02840a0b9379c' | ||
), | ||
], | ||
) | ||
def test_analyze(self, file_content): | ||
logic = SlackDetector() | ||
|
||
f = mock_file_object(file_content) | ||
output = logic.analyze(f, 'mock_filename') | ||
assert len(output) == 1 | ||
for potential_secret in output: | ||
assert 'mock_filename' == potential_secret.filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe
Disables scanning for Slack tokens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in the latest commit 2dd3ef8