SIP.js icon indicating copy to clipboard operation
SIP.js copied to clipboard

Strict Contact URI comparison when using contactName

Open InnovateAsterisk opened this issue 1 year ago • 1 comments

Strict Contact URI comparison when using contactName If you are not using a specified contactName in the creation of the UserAgent, it defaults to a random string. I want to start using a more predictable system of contacts (so that if someone happens to duplicate the tab, this can be seen as a single contact to my proxy). I'll manage things from there.

The problem is that there is a contact miss match because my proxy is re-writing my contact (as it did before). Its pretty much assumed that the contact will be re-written as its not possible for the UA to know its own IP address at the time the User Agent is created. The difference is that sip.js is making a different comparison when compared to the auto-generated option.

See below extract from 0.20.0:

                    // If we are using a randomly generated user name (which is the default behavior)
                    if (this.userAgent.configuration.contactName === "") {
                        // compare the user portion of the URI under the assumption that it will be unique
                        if (contact.uri.user === this.userAgent.contact.uri.user) {
                            expires = Number(contact.getParam("expires"));
                            break;
                        }
                    }
                    else {
                        // otherwise use comparision rules in Section 19.1.4
                        if ((0,_core__WEBPACK_IMPORTED_MODULE_4__.equivalentURI)(contact.uri, this.userAgent.contact.uri)) {
                            expires = Number(contact.getParam("expires"));
                            break;
                        }
                    }

Only the contact user is compared when using the default behaviour: contact.uri.user === this.userAgent.contact.uri.user and when using the contactName (contact.uri, this.userAgent.contact.uri)

Expected behaviour The RFC says: "The UA compares each contact address to see if it created the contact address, using comparison rules in Section 19.1.4."

SIP.js typically makes a contact as sip:[email protected];transport=wss or sip:k603tkq3@invalid;transport=wss. The problem now is that any contact that sip.js creates typically would not match according to this statement in the RFC, as its expected that the proxy re-writes the contact based on the fact that the domain/ip would not be valid.

However, to get around this, SIP.js is only doing a uri.user comparison. I'm ok with this workaround, I just don't think the static method requires such a strict comparison.

InnovateAsterisk avatar Nov 03 '22 08:11 InnovateAsterisk

Related to #888

john-e-riordan avatar Nov 21 '22 16:11 john-e-riordan