Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ AWSKeyDetector
AzureStorageKeyDetector
BasicAuthDetector
CloudantDetector
DiscordBotTokenDetector
GitHubTokenDetector
Base64HighEntropyString
HexHighEntropyString
IbmCloudIamDetector
Expand All @@ -105,8 +107,10 @@ KeywordDetector
MailchimpDetector
NpmDetector
PrivateKeyDetector
SendGridDetector
SlackDetector
SoftlayerDetector
SquareOAuthDetector
StripeDetector
TwilioKeyDetector
```
Expand Down
17 changes: 17 additions & 0 deletions detect_secrets/plugins/discord.py
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 ([M|N]XXXXXXXXXXXXXXXXXXXXXXX.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}'),
]
43 changes: 43 additions & 0 deletions tests/plugins/discord_test.py
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)