From 2582f5cebda2d908f5fb45dfd388dd0c10e4c626 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:31:50 +0500 Subject: [PATCH] Merge commit from fork A REFER with no call behind it is published as a `CALL_SETUP_REQ` event whose `Request-Target` is `sofia//`, and `mod_conference` hands that string to `switch_ivr_originate()` for `rfc-4579` conferences. The URI was copied in unchanged, so a `,`, `|` or `:_:` in it split the dial string into extra peers or legs, each of which can start with its own `[...]` channel variables. Answer such a REFER with `400 Bad Refer-To` before anything is published. Both the serialized Refer-To and its user part are checked; the user part is published separately as `Request-Target-Extension`, which an `outcall-templ` expands. A Refer-To without these characters is handled as before. Also frees the subscription contact string an accepted REFER of this kind allocated and never released. --- src/mod/endpoints/mod_sofia/sofia.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 877d574d28..a6757ce22c 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1469,7 +1469,12 @@ static void sofia_handle_sip_r_refer(nua_t *nua, sofia_profile_t *profile, nua_h } } - +/* Whether s holds anything switch_ivr_originate() splits a dial string on: ',' between peers, + '|' between failover groups, ':_:' between enterprise legs. */ +static switch_bool_t sofia_has_dial_separator(const char *s) +{ + return !zstr(s) && (strpbrk(s, ",|") || strstr(s, SWITCH_ENT_ORIGINATE_DELIM)) ? SWITCH_TRUE : SWITCH_FALSE; +} //sofia_dispatch_event_t *de @@ -1922,6 +1927,16 @@ static void our_sofia_event_callback(nua_event_t event, } + /* The target and its user part are published below as a dial string and a part of one */ + if (sofia_has_dial_separator(refer_to) || sofia_has_dial_separator(ref_to_user)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Profile [%s] rejected a REFER whose Refer-To [%s] holds a dial string separator\n", profile->name, switch_str_nil(refer_to)); + nua_respond(nh, 400, "Bad Refer-To", NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END()); + switch_safe_free(method); + switch_safe_free(full_url); + break; + } + if (!method) { method = strdup("INVITE"); switch_assert(method); @@ -2041,6 +2056,7 @@ static void our_sofia_event_callback(nua_event_t event, sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); + switch_safe_free(contact_str); sip_to_tag(nua_handle_get_home(nh), sip->sip_to, to_tag); }