Skip to content

Commit

Permalink
Add Discord Bot token detector
Browse files Browse the repository at this point in the history
  • Loading branch information
syn-4ck committed Sep 20, 2022
1 parent e61b9f9 commit d66a988
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
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 (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}'),
]
30 changes: 30 additions & 0 deletions tests/plugins/discord_test.py
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

0 comments on commit d66a988

Please sign in to comment.