From 17dcffc09b112bf6b0474c2008d4626b0eac676f Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sat, 17 Jan 2026 18:39:54 -0600 Subject: [PATCH] return error if dtmf create results in invalid characters --- internal/processor/sip-response-dtmf-create.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/processor/sip-response-dtmf-create.go b/internal/processor/sip-response-dtmf-create.go index 55f3967..3fc1bb9 100644 --- a/internal/processor/sip-response-dtmf-create.go +++ b/internal/processor/sip-response-dtmf-create.go @@ -4,16 +4,18 @@ import ( "bytes" "context" "errors" + "regexp" "text/template" "github.com/jwetzell/showbridge-go/internal/config" ) type SipResponseDTMFCreate struct { - config config.ProcessorConfig - PreWait int - PostWait int - Digits *template.Template + config config.ProcessorConfig + 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 }, }) }