feat: tolerate bare LF line endings in SIP header parsing#291
Open
HectorMalot wants to merge 1 commit intoemiago:mainfrom
Open
feat: tolerate bare LF line endings in SIP header parsing#291HectorMalot wants to merge 1 commit intoemiago:mainfrom
HectorMalot wants to merge 1 commit intoemiago:mainfrom
Conversation
Some PBX stacks emit \n instead of \r\n for custom headers, causing the parser to bleed past the header/body boundary and fail. Modify nextLine() to accept bare LF as a line terminator when it appears before any CR, and update parseStartLine() to strip bare LF in stream-mode preamble.
Owner
|
Hi @HectorMalot . What are these stacks, and why trying make lib to go out of RFC? |
Author
|
Have responded in the related issue in the tracker. Let’s pause this PR until discussion is resolved. |
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.
Summary
Some PBX stacks emit
\ninstead of\r\nfor custom headers. This causes the parser to bleed past the header/body boundary and attempt to parse SDP body lines as SIP headers, producing errors like:field name with no value in header: "v=0"Real-world example:
Changes
Backwards compatibility
Messages that currently parse successfully with
\r\nare unaffected. The new code path only activates when\nappears before\r. Messages that currently fail (like the example above) will now succeed.Notes
The RFC 4475 'A Short Tortuous INVITE' test was previously parsing a multi-line header because the bare
\nin the source of the sipgo tests allowed the current parser to continue with the next line. But, this is not in line with the spec, RFC 3261 sec 7.3.1 specifies:Header fields can be extended over multiple lines by preceding each extra line with at least one SP or horizontal tab (HT).. Header folding is currently not implemented in Sipgo's header parsing (and fairly uncommon anyway). I'm happy to provide this in a follow-up PR if desired.This does not affect testing. The torture test is disabled and header folding is not implemented at the parser level regardless.