Skip to content

Commit

Permalink
Merge pull request Yelp#878 from jfagoagas/fix_telegram_bot_token
Browse files Browse the repository at this point in the history
fix(telegram_bot_token): Regex must match just bot tokens
  • Loading branch information
lorenzodb1 authored Oct 7, 2024
2 parents 7b162a7 + fe73707 commit 4627207
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion detect_secrets/plugins/telegram_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TelegramBotTokenDetector(RegexBasedDetector):

denylist = [
# refs https://core.telegram.org/bots/api#authorizing-your-bot
re.compile(r'\d{8,10}:[0-9A-Za-z_-]{35}'),
re.compile(r'^\d{8,10}:[0-9A-Za-z_-]{35}$'),
]

def verify(self, secret: str) -> VerifiedResult: # pragma: no cover
Expand Down
3 changes: 2 additions & 1 deletion tests/plugins/telegram_token_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ class TestTelegramTokenDetector:
@pytest.mark.parametrize(
'payload, should_flag',
[
('bot110201543:AAHdqTcvCH1vGWJxfSe1ofSAs0K5PALDsaw', True),
('bot110201543:AAHdqTcvCH1vGWJxfSe1ofSAs0K5PALDsaw', False),
('110201543:AAHdqTcvCH1vGWJxfSe1ofSAs0K5PALDsaw', True),
('7213808860:AAH1bjqpKKW3maRSPAxzIU-0v6xNuq2-NjM', True),
('foo:AAH1bjqpKKW3maRSPAxzIU-0v6xNuq2-NjM', False),
('foo', False),
('arn:aws:sns:aaa:111122223333:aaaaaaaaaaaaaaaaaaassssssddddddddddddd', False),
],
)
def test_analyze(self, payload, should_flag):
Expand Down

0 comments on commit 4627207

Please sign in to comment.