Skip to content

Fix: don't split URI params inside quoted-string values#135

Open
nixfeo-root wants to merge 1 commit into
restsend:mainfrom
nixfeo-root:fix/quoted-uri-params
Open

Fix: don't split URI params inside quoted-string values#135
nixfeo-root wants to merge 1 commit into
restsend:mainfrom
nixfeo-root:fix/quoted-uri-params

Conversation

@nixfeo-root

Copy link
Copy Markdown

Problem

parse_params (src/sip/uri.rs) splits the param string on ; unconditionally, so an RFC 3261 quoted-string param value containing a semicolon is broken into two bogus params:

sip:alice@example.com;x-route="a;b"
  → Param::Other("x-route", Some("\"a"))   // wrong
  → Param::Other("b\"", None)              // wrong

The mis-parse is easy to miss because it is invisible in Display round-trips — the two broken halves re-join with ; separators and reconstruct the original text. It only shows up in param count/values, which is exactly what dialog/registrar logic reads.

Per RFC 3261 §25.1, generic-param = token [ EQUAL gen-value ] with gen-value = token / host / quoted-string, so semicolons inside quoted values are legal. Real-world traffic in this class includes Linphone's Contact ;+sip.instance="<urn:uuid:…>" (survives today only because it happens to contain no inner ;) and proprietary ITSP params.

Fix

A small quote-aware splitter used by parse_params:

  • no new allocation beyond the existing Vec, no regex/nom dependency;
  • unquoted input splits exactly as before (all existing sip::uri tests pass unchanged);
  • a dangling unbalanced quote degrades to the previous behavior (split disabled only inside balanced quotes) instead of erroring.

Tests

4 new tests in sip::uri::tests:

  • quoted value with an inner ; stays one param with the value intact;
  • real-world Linphone +sip.instance shape;
  • unquoted multi-param splitting unchanged;
  • dangling-quote graceful degradation.

cargo test --lib sip::uri: 30 passed. (The dialog::tests::test_client_dialog failures I see locally are present on pristine main in my environment too — unrelated to this change.)

Context: we're adopting rsipstack as the SIP stack for a production Rust CPaaS (replacing a vendored rsip fork that carried a nom-based version of this same fix) — happy to adjust style/scope as you prefer.

parse_params currently splits on ';' unconditionally, so RFC 3261
quoted-string param values containing a semicolon (gen-value = token /
host / quoted-string, e.g. ;x-route="a;b") are broken into two invalid
params. The mis-parse is invisible in Display round-trips (the broken
halves re-join with ';' separators and reconstruct the original text) —
it only shows up in param count/values, which is what dialog and
registrar logic reads.

This adds a small quote-aware splitter (no new allocation beyond the
existing Vec, no regex/nom dependency). Unquoted input splits exactly
as before; a dangling unbalanced quote degrades to the previous
behavior instead of erroring.

Tests: quoted value with inner ';' stays one param; real-world Linphone
Contact ;+sip.instance="<urn:uuid:...>" shape; unquoted multi-param
unchanged; dangling-quote graceful degradation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant