drachtio-srf icon indicating copy to clipboard operation
drachtio-srf copied to clipboard

app restarts when processing invalid sip message

Open davehorton opened this issue 3 years ago • 0 comments

This message caused the app to restart

2021-09-14 16:35:56.407594 recv 572 bytes from tls/[52.229.57.255]:63534 at 16:35:56.407532:
REGISTER sips:54.74.169.84;transport=Tls SIP/2.0^M
To: <sip:[email protected]>^M
From: <sip:[email protected]>;tag=b9035e162^M
Via: SIP/2.0/TLS 10.1.0.4:63534;branch=z9hG4bK-d87543-213921418-1--d87543-;rport^M
Call-ID: b60d05581c3fd47d2^M
CSeq: 2 REGISTER^M
Contact: <sip:[email protected]:63534;transport=TLS>^M
Expires: 3600^M
Max-Forwards: 70^M
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO^M
User-Agent: Voip^M
Digest username="90",realm="",nonce="",uri="sip:54.74.169.84",response="cc9f1ccfba8b0d18a227a92cc4034ae7",algorithm=MD5^M
Content-Length: 0^M

The line starting with Digest is not a valid sip header.

The constructor in the last line below can throw an error, which should be handled

    const obj = this.mapServer.get(socket) ;
    const pos = msg.indexOf(CR) ;
    const leader = -1 === pos ? msg : msg.slice(0, pos) ;
    const token = leader.split('|') ;
    let res, sr, rawMsg ;

    switch (token[1]) {
      case 'sip':
        if (!obj) {
          debug('socket not found, message discarding');
          return ;
        }
        rawMsg = msg.slice(pos + 2) ;
        const sipMsg = new SipMessage(rawMsg) ;

davehorton avatar Sep 14 '21 16:09 davehorton