-
Notifications
You must be signed in to change notification settings - Fork 523
Add Discord Bot token detector #614
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d66a988
Add Discord Bot token detector
syn-4ck ecd92a1
Add failed unit tests
syn-4ck 3b2bcd5
Revert pre-commit config
syn-4ck 8e03ae6
Add Discord failed tokens test
syn-4ck 0ac69f6
Add Discord failed tokens test
syn-4ck b8d6d0e
Add Discord failed tokens test
syn-4ck 5b4073c
Committing my own changes to merge this PR
lorenzodb1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 Discord Bot Token | ||
""" | ||
import re | ||
|
||
from .base import RegexBasedDetector | ||
|
||
|
||
class DiscordBotTokenDetector(RegexBasedDetector): | ||
"""Scans for Discord Bot token.""" | ||
secret_type = 'Discord Bot Token' | ||
|
||
denylist = [ | ||
# Discord Bot Token (MXXXXXXXXXXXXXXXXXXXXXXX.XXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXX) | ||
# Reference: https://discord.com/developers/docs/reference#authentication | ||
re.compile(r'[MN][a-zA-Z\d_-]{23}\.[a-zA-Z\d_-]{6}\.[a-zA-Z\d_-]{27}'), | ||
] |
This file contains hidden or 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,43 @@ | ||
import pytest | ||
|
||
from detect_secrets.plugins.discord import DiscordBotTokenDetector | ||
|
||
|
||
class TestDiscordBotTokenDetector: | ||
|
||
@pytest.mark.parametrize( | ||
'payload, should_flag', | ||
[ | ||
# From https://discord.com/developers/docs/reference#authentication | ||
( | ||
'MTk4NjIyNDgzNDcxOTI1MjQ4.Cl2FMQ.ZnCjm1XVW7vRze4b7Cq4se7kKWs', | ||
True, | ||
), | ||
( | ||
'Nzk5MjgxNDk0NDc2NDU1OTg3.YABS5g.2lmzECVlZv3vv6miVnUaKPQi2wI', | ||
True, | ||
), | ||
# From https://docs.gitguardian.com/secrets-detection/detectors/specifics/discord_bot_token#examples # noqa: E501 | ||
( | ||
'MZ1yGvKTjE0rY0cV8i47CjAa.uRHQPq.Xb1Mk2nEhe-4iUcrGOuegj57zMC', | ||
True, | ||
), | ||
# Random values to fail | ||
( | ||
'MZ1yGvKTj0rY0cV8i47CjAa.uHQPq.Xb1Mk2nEhe-4icrGOuegj57zMC', | ||
False, | ||
), | ||
( | ||
'SZ1yGvKTj0rY0cV8i47CjAa.uHQPq.Xb1Mk2nEhe-4icrGOuegj57zMC', | ||
False, | ||
), | ||
( | ||
'MZ1yGvKTj0rY0cV8i47CjAa.uHQPq.Xb1Mk2nEhe-4icrGOuegj57zM', | ||
False, | ||
), | ||
], | ||
) | ||
def test_analyze(self, payload, should_flag): | ||
logic = DiscordBotTokenDetector() | ||
output = logic.analyze_line(filename='mock_filename', line=payload) | ||
assert len(output) == (1 if should_flag else 0) | ||
syn-4ck marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.