Skip to content

Commit

Permalink
add Redacting function to protect api_token from being printed to log
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahdi Gheidi committed Jun 15, 2023
1 parent 4126fa6 commit 87797b6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"mime/multipart"
"net/http"
"net/url"
"regexp"
"strings"
"time"
)
Expand Down Expand Up @@ -426,6 +427,13 @@ func (bot *BotAPI) GetWebhookInfo() (WebhookInfo, error) {
return info, err
}

func RedactLoggingURL(err error) (redactedError error) {
matcher := regexp.MustCompile(`bot\d{10}:[a-zA-Z0-9_.-]{35}`)

redacted := matcher.ReplaceAllString(err.Error(), "bot**********")
return errors.New(redacted)
}

// GetUpdatesChan starts and returns a channel for getting updates.
func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) UpdatesChannel {
ch := make(chan Update, bot.Buffer)
Expand Down

0 comments on commit 87797b6

Please sign in to comment.