Module: kamailio Branch: master Commit: e43dfcc104f1f2e904cc87210d1ef73aa565affa URL: https://github.com/kamailio/kamailio/commit/e43dfcc104f1f2e904cc87210d1ef73aa565affa
Author: Xenofon Karamanos <[email protected]> Committer: GitHub <[email protected]> Date: 2026-05-11T21:30:32+02:00 sanity: Add more RFC3261 checks (#4704) * sanity: Add lr check for Route Headers * sanity: Remove FL_MSG_NOREPLY - Remove from via magic cookie check - Remove from Record-Route Headers * sanity: docs: Update RFC3261 check - Add Route header check for lr parameter --- Modified: src/modules/sanity/doc/sanity_admin.xml Modified: src/modules/sanity/sanity.c --- Diff: https://github.com/kamailio/kamailio/commit/e43dfcc104f1f2e904cc87210d1ef73aa565affa.diff Patch: https://github.com/kamailio/kamailio/commit/e43dfcc104f1f2e904cc87210d1ef73aa565affa.patch --- diff --git a/src/modules/sanity/doc/sanity_admin.xml b/src/modules/sanity/doc/sanity_admin.xml index e88884f8748..811c3fd5598 100644 --- a/src/modules/sanity/doc/sanity_admin.xml +++ b/src/modules/sanity/doc/sanity_admin.xml @@ -126,7 +126,7 @@ <para> RFC3261 compliance related checks (32768 [0x8000 / 2^15]) - checks if the branch parameter of the first Via header starts with magic cookie: 'z9hG4bK'. - Also checks that the lr parameter is present in Record-Route headers if they are present. + Also checks that the lr parameter is present in Record-Route and Route headers if they are present. </para> </listitem> <listitem> diff --git a/src/modules/sanity/sanity.c b/src/modules/sanity/sanity.c index b0f50297b1e..6402c102831 100644 --- a/src/modules/sanity/sanity.c +++ b/src/modules/sanity/sanity.c @@ -388,7 +388,7 @@ int check_via1_header(sip_msg_t *msg) /* check multiple conditions regarding RFC3261 1. via branch parameter starts with the magic cookie - 2. for Record-Route headers check that the lr parameter is present + 2. for Record-Route and Route headers check that the lr parameter is present */ int check_rfc3261_compliance(sip_msg_t *msg) { @@ -407,7 +407,6 @@ int check_rfc3261_compliance(sip_msg_t *msg) if(msg->via1->branch->value.len < 7 || memcmp(msg->via1->branch->value.s, "z9hG4bK", 7) != 0) { LM_WARN("Via1 branch parameter does not start with the magic cookie\n"); - msg->msg_flags |= FL_MSG_NOREPLY; return SANITY_CHECK_FAILED; } @@ -416,7 +415,6 @@ int check_rfc3261_compliance(sip_msg_t *msg) if(parse_record_route_headers(msg) != 0) { LM_WARN("failed to parse the Record-Route headers\n"); - msg->msg_flags |= FL_MSG_NOREPLY; return SANITY_CHECK_FAILED; } @@ -424,20 +422,45 @@ int check_rfc3261_compliance(sip_msg_t *msg) while(hf) { if(hf->parsed == NULL) { LM_WARN("failed to parse the Record-Route header body\n"); - msg->msg_flags |= FL_MSG_NOREPLY; return SANITY_CHECK_FAILED; } rr = hf->parsed; if(parse_uri(rr->nameaddr.uri.s, rr->nameaddr.uri.len, &parsed_uri) != 0) { LM_WARN("failed to parse the Record-Route URI\n"); - msg->msg_flags |= FL_MSG_NOREPLY; return SANITY_CHECK_FAILED; } if(parsed_uri.lr.len == 0 || parsed_uri.lr.s == NULL) { LM_WARN("missing lr parameter in Record-Route URI\n"); - msg->msg_flags |= FL_MSG_NOREPLY; + return SANITY_CHECK_FAILED; + } + hf = next_sibling_hdr(hf); + } + + /* Check lr parameter for Route */ + LM_DBG("check Route lr parameter for all Route headers\n"); + + if(parse_route_headers(msg) != 0) { + LM_WARN("failed to parse the Route headers\n"); + return SANITY_CHECK_FAILED; + } + + hf = msg->route; + while(hf) { + if(hf->parsed == NULL) { + LM_WARN("failed to parse the Route header body\n"); + return SANITY_CHECK_FAILED; + } + rr = hf->parsed; + if(parse_uri(rr->nameaddr.uri.s, rr->nameaddr.uri.len, &parsed_uri) + != 0) { + LM_WARN("failed to parse the Route URI\n"); + return SANITY_CHECK_FAILED; + } + + if(parsed_uri.lr.len == 0 || parsed_uri.lr.s == NULL) { + LM_WARN("missing lr parameter in Route URI\n"); return SANITY_CHECK_FAILED; } hf = next_sibling_hdr(hf); _______________________________________________ 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!
