Repository navigation
fix(sip): keep ; inside quoted parameter values - #259
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
The value is split into
received="sip:192.0.2.10:47522andtransport=tls". The second part fails withunknown 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_paramssplits only outside quoted strings and honours quoted-pairs (\"), consistent with the quoted-pair support added in 0.8.6.unterminated quoted parameter) instead of being split or accepted, in line with 0.8.6's grammar checks.Tests
quoted_contact_params_may_contain_semicolonsparses a complete REGISTER 200 OK like the one above. It checks that there is one Contact withexpires=600, the quotedreceivedvalue intact, andreg-id=1. It also checks that an unterminated quote is refused and that the header prints back to an equal header. On currentmainit fails with the sameunknown transporterror.cargo test: 786 passed, 0 failed.cargo fmt --all -- --checkis clean, andcargo clippy --all-targetsreports 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