return error if dtmf create results in invalid characters

This commit is contained in:
Joel Wetzell
2026-01-17 18:39:54 -06:00
parent 8318645eef
commit 17dcffc09b

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"regexp"
"text/template"
"github.com/jwetzell/showbridge-go/internal/config"
@@ -14,6 +15,7 @@ type SipResponseDTMFCreate struct {
PreWait int
PostWait int
Digits *template.Template
validDTMF *regexp.Regexp
}
type SipDTMFResponse struct {
@@ -33,6 +35,10 @@ func (scc *SipResponseDTMFCreate) Process(ctx context.Context, payload any) (any
digitsString := digitsBuffer.String()
if !scc.validDTMF.MatchString(digitsString) {
return nil, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
}
return SipDTMFResponse{
PreWait: scc.PreWait,
PostWait: scc.PostWait,
@@ -91,7 +97,7 @@ func init() {
if err != nil {
return nil, err
}
return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum)}, nil
return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum), validDTMF: regexp.MustCompile(`^[0-9*#A-Da-d]+$`)}, nil
},
})
}