prevent crash when no Contact header in 200 OK response to REGISTER (#60)

* prevent crash when no Contact header in 200 OK response to REGISTER request

* fixed jslint

---------

Co-authored-by: Andre Heber <a.heber@cognigy.com>
This commit is contained in:
André Heber
2024-05-29 21:38:12 +02:00
committed by GitHub
parent d24e4f0fdd
commit 49e1ae2843

View File

@@ -109,17 +109,29 @@ class Regbot {
this.timer = setTimeout(this.register.bind(this, srf), 30 * 1000);
}
else {
// the code parses the SIP headers to get the expires value
// if there is a Contact header, it will use the expires value from there
// otherwise, it will use the Expires header, acording to the SIP RFC 3261, section 10.2.4 Refreshing Bindings
this.status = 'registered';
let expires = DEFAULT_EXPIRES;
const contact = res.getParsedHeader('Contact');
if (contact.length > 0 && contact[0].params && contact[0].params.expires) {
if (contact[0].params.expires) expires = parseInt(contact[0].params.expires);
}
else if (res.has('Expires')) {
if (res.has('Expires')) {
expires = parseInt(res.get('Expires'));
}
if (res.has('Contact')) {
const contact = res.getParsedHeader('Contact');
if (contact.length > 0 && contact[0].params && contact[0].params.expires) {
expires = parseInt(contact[0].params.expires);
}
} else {
this.logger.info({ aor: this.aor, ipv4: this.ipv4, port: this.port },
'no Contact header in 200 OK');
}
if (isNaN(expires) || expires < MIN_EXPIRES) {
this.logger.info({aor: this.aor, ipv4: this.ipv4, port: this.port},
this.logger.info({ aor: this.aor, ipv4: this.ipv4, port: this.port },
`got expires of ${expires} in 200 OK, too small so setting to ${MIN_EXPIRES}`);
expires = MIN_EXPIRES;
}