Skip to content

Commit

Permalink
Validate outbound address and SIP user. (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc authored Nov 14, 2024
1 parent d1c09b3 commit 855c338
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/sip/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package sip

import (
"context"
"errors"
"fmt"
"log/slog"
"net/netip"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -138,6 +140,18 @@ func (c *Client) createSIPParticipant(ctx context.Context, req *rpc.InternalCrea
} else if req.RoomName == "" {
return nil, fmt.Errorf("room name must be set")
}
if strings.Contains(req.CallTo, "@") {
return nil, errors.New("call_to should be a phone number or SIP user, not a full SIP URI")
}
if strings.HasPrefix(req.Address, "sip:") || strings.HasPrefix(req.Address, "sips:") {
return nil, errors.New("address must be a hostname without 'sip:' prefix")
}
if strings.Contains(req.Address, "transport=") {
return nil, errors.New("address must not contain parameters; use transport field")
}
if strings.ContainsAny(req.Address, ";=") {
return nil, errors.New("address must not contain parameters")
}
log := c.log
if req.ProjectId != "" {
log = log.WithValues("projectID", req.ProjectId)
Expand Down

0 comments on commit 855c338

Please sign in to comment.