(new): rich message support
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
This commit is contained in:
+24
-3
@@ -152,6 +152,9 @@ func (bot *Bot[T]) RunWebhookWithContext(ctx context.Context, opts *BotWebhookOp
|
||||
if opts.MaxConnections > 100 || opts.MaxConnections <= 0 {
|
||||
return ErrBotWebhookOptsMaxConnectionsRange
|
||||
}
|
||||
if err := validateWebhookSecretToken(opts.SecretToken); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateWebhookPath(opts.Path, opts.UseStatusPath); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -165,7 +168,7 @@ func (bot *Bot[T]) RunWebhookWithContext(ctx context.Context, opts *BotWebhookOp
|
||||
|
||||
return bot.runWebhookRuntime(ctx, func(runCtx context.Context) error {
|
||||
if autoSecret != "" {
|
||||
bot.webhookLogger.Warnln("Using webhook without secret is very dangerous. Using random 32 bytes token:", autoSecret)
|
||||
bot.webhookLogger.Warnln("No webhook secret was configured; generated a random secret token")
|
||||
}
|
||||
i, err := bot.api.GetWebhookInfoWithContext(runCtx)
|
||||
if err != nil {
|
||||
@@ -381,8 +384,11 @@ func (bot *Bot[T]) newWebhookMux(ctx context.Context, opts *BotWebhookOpts) *htt
|
||||
}
|
||||
func (bot *Bot[T]) baseRunWebhook(ctx context.Context, opts *BotWebhookOpts, runFunc func(*http.Server, chan error)) error {
|
||||
srv := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", opts.LocalPort),
|
||||
Handler: bot.newWebhookMux(ctx, opts),
|
||||
Addr: fmt.Sprintf(":%d", opts.LocalPort),
|
||||
Handler: bot.newWebhookMux(ctx, opts),
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
}
|
||||
errCh := make(chan error, 1)
|
||||
|
||||
@@ -442,6 +448,21 @@ func validateWebhookPath(path string, useStatusPath bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateWebhookSecretToken(token string) error {
|
||||
if len(token) < 1 || len(token) > 256 {
|
||||
return ErrBotWebhookOptsSecretTokenInvalid
|
||||
}
|
||||
for _, r := range token {
|
||||
if (r < 'A' || r > 'Z') &&
|
||||
(r < 'a' || r > 'z') &&
|
||||
(r < '0' || r > '9') &&
|
||||
r != '_' && r != '-' {
|
||||
return ErrBotWebhookOptsSecretTokenInvalid
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateWebhookTLSFiles(tlsFiles []string) error {
|
||||
switch len(tlsFiles) {
|
||||
case 0, 2:
|
||||
|
||||
Reference in New Issue
Block a user