fix(secrets): add standalone Telegram bot token detection rule#656
Draft
fix(secrets): add standalone Telegram bot token detection rule#656
Conversation
The existing gitleaks telegram-bot-api-token rule requires contextual
keywords ("telegr") and an assignment operator before the token value.
This means bare tokens like 8797664862:AAF...v4 are not redacted when
pasted or typed without surrounding config-style context.
Add a new telegram-bot-token-standalone rule in additional_rules.toml
that matches Telegram bot tokens purely by their distinctive format
([0-9]{5,16}:A[A-Za-z0-9_-]{34}) with no keyword pre-filter, so they
are detected regardless of surrounding text.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes secret redaction for Telegram bot tokens (e.g.
8797664862:AAF...v4) that are pasted or typed without surrounding config-style context.Problem
The existing
telegram-bot-api-tokenrule from gitleaks requires:telegrbefore the token=,:,=>, etc.) between the keyword and the valueThis means bare tokens are not redacted when:
TELEGRAM_TOKEN=...The
generic-api-keyrule also cannot help because the:separator in Telegram tokens is not matched by\win its capture group, so it splits at the colon.Why "sometimes works"
The gitleaks rule keywords include generic terms like
bot,token,key. When any of those appear elsewhere in the input, the keyword pre-filter passes, but the regex itself still demands(?:telegr)in the prefix — so it only fires when the user writes something liketelegram_token = <value>.Solution
Added a new
telegram-bot-token-standalonerule inadditional_rules.tomlthat matches Telegram bot tokens purely by their distinctive format::+A+ 34 base64url chars) without requiring any surrounding contextkeywords = []: Disables the keyword pre-filter so the rule runs against all input — acceptable because the regex is highly specific to Telegram's token formattelegram-bot-api-tokenrule is preserved for config-style detection; overlapping matches are deduplicated by the existing logic inredact_secrets()Test plan
Added 5 test cases across 3 tests:
test_telegram_bot_token_standalone_detectionAprefixtest_telegram_bot_token_redaction_baretest_telegram_bot_token_redaction_in_contextTELEGRAM_BOT_TOKEN=prefix still detectedFiles changed
libs/shared/src/secrets/additional_rules.tomltelegram-bot-token-standalonerulelibs/shared/src/secrets/gitleaks.rsdetect_secrets()layerlibs/shared/src/secrets/mod.rsredact_secrets()pipeline