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.
- Loading branch information
Showing
3 changed files
with
51 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
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,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 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,30 @@ | ||
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, | ||
), | ||
], | ||
) | ||
def test_analyze(self, payload, should_flag): | ||
logic = DiscordBotTokenDetector() | ||
output = logic.analyze_line(filename='mock_filename', line=payload) | ||
assert output |