Skip to content

fix(sip): keep ; inside quoted parameter values - #259

Merged
yeoleobun merged 1 commit into
restsend:mainfrom
andreinknv:fix/quoted-params-semicolons
Nov 18, 2026
Merged

yeoleobun merged 1 commit into
restsend:mainfrom
andreinknv:fix/quoted-params-semicolons

Conversation

@andreinknv

Copy link
Copy Markdown
Contributor

Problem

parse_params (src/sip/uri.rs) splits at every ;, including inside a quoted-string value. RFC 3261 §25.1 allows a quoted-string as a parameter value (generic-param = token [ EQUAL gen-value ], gen-value = token / host / quoted-string), and a quoted-string may contain ;.

This breaks registration over TCP and TLS against Kamailio when the registrar stores the observed flow (common behind NAT). Its REGISTER 200 OK returns the received address as a quoted URI with its own transport parameter:

Contact: <sip:1002@192.0.2.10:47522;transport=TLS>;q=1;expires=600;received="sip:192.0.2.10:47522;transport=tls";+sip.instance="<urn:uuid:…>";reg-id=1

The value is split into received="sip:192.0.2.10:47522 and transport=tls". The second part fails with unknown transport: tls", the whole response is refused, and the stream connection closes, so the UA never registers. Over UDP the received value carries no ;transport=, so only TCP and TLS are affected.

Fix

  • parse_params splits only outside quoted strings and honours quoted-pairs (\"), consistent with the quoted-pair support added in 0.8.6.
  • A quoted value that never closes is refused (unterminated quoted parameter) instead of being split or accepted, in line with 0.8.6's grammar checks.
  • Unquoted input splits exactly as before.

Tests

  • New quoted_contact_params_may_contain_semicolons parses a complete REGISTER 200 OK like the one above. It checks that there is one Contact with expires=600, the quoted received value intact, and reg-id=1. It also checks that an unterminated quote is refused and that the header prints back to an equal header. On current main it fails with the same unknown transport error.
  • cargo test: 786 passed, 0 failed. cargo fmt --all -- --check is clean, and cargo clippy --all-targets reports no new warnings.

#135 (closed by its author) addressed the same split. This version also handles quoted-pairs and unterminated quotes and adds an end-to-end response test.

AI assistance: I used an AI coding assistant to help find this in testing, write the patch and draft this text; I reviewed and tested the change.

🤖 Generated with Claude Code

RFC 3261 lets a parameter value be a quoted-string (gen-value), and a
quoted-string may contain `;`. parse_params split at every `;`, so a
Kamailio registrar that stores the observed flow answers a REGISTER over
TCP or TLS with a Contact carrying
`;received="sip:192.0.2.10:47522;transport=tls"`, which was split into
`received="sip:192.0.2.10:47522` and `transport=tls"`. The second part
failed as "unknown transport: tls\"", the whole response was refused and
the stream connection closed, so the client never registered. UDP answers
carry no `;transport=` in that value and were not affected.

Split only outside quoted strings, honouring quoted-pairs, and refuse a
quoted value that never closes. Add a regression test with a complete
200 OK.
@yeoleobun
yeoleobun merged commit 021e308 into restsend:main Nov 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants