From 691bb4cf30899f6f31f67f0fcb2a6029fa4307ff Mon Sep 17 00:00:00 2001 From: Alexis Hadjisotiriou Date: Mon, 19 Jan 2026 15:20:53 +0000 Subject: [PATCH] res_pjsip_messaging: Remove Contact header from out-of-dialog MESSAGE as per RFC3428 According to RFC 3428 (Section 5), a Contact header is not required in a MESSAGE request unless the sender wants to establish a session. This patch ensures that the Contact header is removed from out-of-dialog MESSAGE requests within res_pjsip_messaging.c. Fixes: #1356 --- res/res_pjsip_messaging.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c index f9ab8717c6..929779a0f1 100644 --- a/res/res_pjsip_messaging.c +++ b/res/res_pjsip_messaging.c @@ -912,6 +912,7 @@ static int msg_send(void *data) .body_text = ast_msg_get_body(mdata->msg) }; + pjsip_hdr *contact; pjsip_tx_data *tdata; RAII_VAR(char *, uri, NULL, ast_free); RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup); @@ -1023,7 +1024,11 @@ static int msg_send(void *data) * tdata. */ vars_to_headers(mdata->msg, tdata); - + /* Remove Contact header fields as per RFC 3428*/ + contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL); + if (contact) { + pj_list_erase(contact); + } ast_debug(1, "Sending message to '%s' (via endpoint %s) from '%s'\n", uri, ast_sorcery_object_get_id(endpoint), mdata->from);