Module: kamailio Branch: master Commit: 14bff54f423ebb0dce7b81e31da73af70029abb0 URL: https://github.com/kamailio/kamailio/commit/14bff54f423ebb0dce7b81e31da73af70029abb0
Author: mt.ghafari <[email protected]> Committer: Henning Westerholt <[email protected]> Date: 2026-06-24T10:49:26+02:00 secfilter: added name identity extraction for Contact header - implemented helper to parse display name from Contact URI - ensures granular identity checks work correctly for all target headers - integrated new helper with existing validation logic --- Modified: src/modules/secfilter/secfilter.c Modified: src/modules/secfilter/secfilter.h Modified: src/modules/secfilter/secfilter_hdr.c --- Diff: https://github.com/kamailio/kamailio/commit/14bff54f423ebb0dce7b81e31da73af70029abb0.diff Patch: https://github.com/kamailio/kamailio/commit/14bff54f423ebb0dce7b81e31da73af70029abb0.patch --- diff --git a/src/modules/secfilter/secfilter.c b/src/modules/secfilter/secfilter.c index be9dcf3477b..01483ce2d84 100644 --- a/src/modules/secfilter/secfilter.c +++ b/src/modules/secfilter/secfilter.c @@ -602,7 +602,7 @@ static int check_generic( res = secf_get_to(msg, &name, &user, &domain); break; case SECF_CONTACT_HEADER: - res = secf_get_contact(msg, &user, &domain); + res = secf_get_contact_with_name(msg, &name, &user, &domain); break; default: return -1; diff --git a/src/modules/secfilter/secfilter.h b/src/modules/secfilter/secfilter.h index 12ca1f66540..a31bfbc4178 100644 --- a/src/modules/secfilter/secfilter.h +++ b/src/modules/secfilter/secfilter.h @@ -71,6 +71,8 @@ int secf_get_ua(struct sip_msg *msg, str *ua); int secf_get_from(struct sip_msg *msg, str *name, str *user, str *domain); int secf_get_to(struct sip_msg *msg, str *name, str *user, str *domain); int secf_get_contact(struct sip_msg *msg, str *user, str *domain); +int secf_get_contact_with_name( + struct sip_msg *msg, str *name, str *user, str *domain); /* Database functions */ int secf_init_db(void); diff --git a/src/modules/secfilter/secfilter_hdr.c b/src/modules/secfilter/secfilter_hdr.c index fe470bd67d4..a3b52c75b90 100644 --- a/src/modules/secfilter/secfilter_hdr.c +++ b/src/modules/secfilter/secfilter_hdr.c @@ -22,7 +22,7 @@ */ #include <string.h> - +#include "../../core/ut.h" #include "../../core/dprint.h" #include "../../core/mem/mem.h" #include "../../core/parser/parse_uri.h" @@ -164,6 +164,107 @@ int secf_get_to(struct sip_msg *msg, str *name, str *user, str *domain) } +void secf_trim_quotes(str *input) +{ + if(!input || input->len < 2 || input->s == NULL) { + return; + } + + if(input->s[0] == '"' && input->s[input->len - 1] == '"') { + input->s++; + input->len -= 2; + } +} + +int parse_name(char *_s, int _len, str *name) +{ + if(_s == NULL || _len <= 0) { + if(name) { + name->s = NULL; + name->len = 0; + } + LM_DBG("no name data found in contact header (empty)\n"); + return 0; + } + + name->s = _s; + name->len = _len; + + char *begin; + int len; + + trim_len(len, begin, *name); + name->s = begin; + name->len = len; + + secf_trim_quotes(name); + + trim_len(len, begin, *name); + name->s = begin; + name->len = len; + + LM_DBG("parsed and trimmed name: %.*s\n", name->len, name->s); + + return 0; +} + +/* get 'contact' header with name*/ +int secf_get_contact_with_name( + struct sip_msg *msg, str *name, str *user, str *domain) +{ + struct sip_uri uri; + contact_t *contact; + + if(msg == NULL) { + LM_DBG("SIP msg is empty\n"); + return -1; + } + + LM_DBG("starting to parse Contact header from SIP message\n"); + + if((parse_headers(msg, HDR_CONTACT_F, 0) == -1) || !msg->contact) { + LM_DBG("cannot get the Contact header from the SIP message\n"); + return 1; + } + + if(!msg->contact->parsed && parse_contact(msg->contact) < 0) { + LM_DBG("cannot parse the Contact header\n"); + return 1; + } + + contact = ((contact_body_t *)msg->contact->parsed)->contacts; + if(!contact) { + LM_DBG("no contacts found in the parsed header\n"); + return 1; + } + + if(parse_name(contact->name.s, contact->name.len, name) < 0) { + LM_DBG("proceeding without Display Name\n"); + return 1; + } + + if(parse_uri(contact->uri.s, contact->uri.len, &uri) < 0) { + LM_DBG("cannot parse the Contact URI\n"); + return 1; + } + + if(uri.user.s == NULL) { + LM_DBG("cannot parse the Contact User\n"); + return 1; + } + user->s = uri.user.s; + user->len = uri.user.len; + + if(uri.host.s == NULL) { + LM_DBG("cannot parse the Contact Domain\n"); + return 1; + } + domain->s = uri.host.s; + domain->len = uri.host.len; + + return 0; +} + /* get 'contact' header */ int secf_get_contact(struct sip_msg *msg, str *user, str *domain) { _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
