From 9f1e5bc1260b97da6e5c81077a0c089073459324 Mon Sep 17 00:00:00 2001 From: Norm Brandinger Date: Thu, 4 Jun 2026 18:14:31 -0400 Subject: [PATCH] stir_shaken: strip RFC 4904 user parameters from telephone numbers get_orig_tn_from_msg() and get_dest_tn_from_msg() take the originating and destination telephone numbers directly from parse_uri()'s .user field. When a From/To/PAI URI carries RFC 4904 parameters in the userinfo part (e.g. "+33123456789;tgrp=...;trunk-context=..."), parse_uri() folds the whole userinfo into .user, so the trailing parameters end up glued to the number and the E.164 check in check_passport_phonenum() fails -- forcing the script to pre-clean orig_tn/dest_tn before calling stir_shaken_verify(). Trim the number at the first ';' so any embedded parameters are dropped before validation. Based on the patch proposed by @StellaTeam in #3904. Closes #3904 --- modules/stir_shaken/stir_shaken.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/stir_shaken/stir_shaken.c b/modules/stir_shaken/stir_shaken.c index 21cbeb77bbd..cf7bbc60fbf 100644 --- a/modules/stir_shaken/stir_shaken.c +++ b/modules/stir_shaken/stir_shaken.c @@ -848,6 +848,20 @@ static int build_unsigned_pport(str *buf, time_t iat_ts, str *attest, return -1; } +/* RFC 4904 allows telephone-related parameters (tgrp, trunk-context, ...) to + * be carried as semicolon-separated fields inside the userinfo part of a + * SIP/TEL URI (before the '@'). parse_uri() returns the whole userinfo in the + * .user field, so a value such as "+33123456789;tgrp=...;trunk-context=..." + * would otherwise fail the E.164 check. Keep only the leading telephone + * number by trimming at the first ';'. */ +static inline void trim_tn_params(str *tn) +{ + char *semi = q_memchr(tn->s, ';', tn->len); + + if (semi) + tn->len = semi - tn->s; +} + static int get_orig_tn_from_msg(struct sip_msg *msg, str *orig_tn) { struct to_body *body; @@ -889,6 +903,7 @@ static int get_orig_tn_from_msg(struct sip_msg *msg, str *orig_tn) } *orig_tn = parsed_uri.user; + trim_tn_params(orig_tn); return 0; } @@ -920,6 +935,7 @@ static int get_dest_tn_from_msg(struct sip_msg *msg, str *dest_tn) } *dest_tn = parsed_uri.user; + trim_tn_params(dest_tn); return 0; }