forked from gitleaks/gitleaks
-
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.
Issue gitleaks#980: Add support for Telegram Bot API Token
- Loading branch information
Showing
3 changed files
with
53 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,43 @@ | ||
package rules | ||
|
||
import ( | ||
"math/rand" | ||
"regexp" | ||
"strconv" | ||
|
||
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" | ||
"github.com/zricethezav/gitleaks/v8/config" | ||
) | ||
|
||
func TelegramBotToken() *config.Rule { | ||
// define rule | ||
r := config.Rule{ | ||
Description: "Telegram Bot API Token", | ||
RuleID: "telegram-bot-api-token", | ||
SecretGroup: 1, | ||
Regex: regexp.MustCompile(`(?i)(?:^|[^0-9])([0-9]{5,16}:A[a-zA-Z0-9_\-]{34})(?:$|[^a-zA-Z0-9_\-])`), | ||
Keywords: []string{ | ||
"telegram", | ||
"api", | ||
"bot", | ||
"token", | ||
"url", | ||
}, | ||
} | ||
|
||
// validate | ||
token := secrets.NewSecret(numeric(strconv.Itoa(rand.Intn(11)+5)) + ":A" + alphaNumericExtendedShort("34")) | ||
tps := []string{ | ||
// variable assigment | ||
generateSampleSecret("telegram", token), | ||
// URL contaning token | ||
generateSampleSecret("url", "https://api.telegram.org/bot"+token+"/sendMessage"), | ||
// object constructor | ||
`const bot = new Telegraf("` + token + `")`, | ||
// .env | ||
`API_TOKEN = ` + token, | ||
// YAML | ||
`bot: ` + token, | ||
} | ||
return validate(r, tps, nil) | ||
} |
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