Skip to content

Accept whitespace and extra params in the NOTIFY Event header - #922

Open
RaphaelFakhri wants to merge 1 commit into
livekit:mainfrom
RaphaelFakhri:fix/notify-event-header-params
Open

RaphaelFakhri wants to merge 1 commit into
livekit:mainfrom
RaphaelFakhri:fix/notify-event-header-params

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

handleNotify matches the Event header value against ^refer(;id=(\d+))?$. RFC 3261 defines SEMI and EQUAL with optional whitespace around them, and RFC 6665 allows generic event-params besides id. So Event: refer; id=2, Event: refer ;id=2 and Event: refer;id=2;foo=bar are all valid NOTIFYs for a REFER subscription, but each one fails the match with unknown event.

The NOTIFY is then answered 501 Not Implemented and its sipfrag status is dropped. For a transfer, the 200 that reports success is lost. TransferSIPParticipant waits until the transfer deadline and reports a failure, even though the transfer completed.

This change splits the header on ;, compares the event type and parameter names case-insensitively after trimming whitespace, and ignores parameters other than id. A non-numeric id returns 400 Bad Request instead of 501. The regular expression is removed.

Testing

TestHandleNotify gains three cases: refer ; id = 1234, Refer;foo=bar;ID=1234;baz and refer;id=abc. On current main the first two fail with unknown event. With the change, go test ./pkg/sip -run '^TestHandleNotify$' passes (15 of 15 subtests), and go test ./pkg/sip passes.

Fixes #921

@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner October 24, 2026 19:47

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

Comment thread pkg/sip/protocol.go
if len(m) == 0 {
// Event: event-type *( SEMI event-param ). SEMI and EQUAL allow whitespace
// around them, and generic params other than id may follow (RFC 6665).
params := strings.Split(event.Value(), ";")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Quoted parameters lose transfer results

For Event: refer;id=12;foo="tag;id=13;rest", handleNotify replaces the real id with 13. handleReferNotify then discards the final status for REFER 12, leaving the transfer to fail.

Learn more

An Event header permits generic parameters whose values are quoted strings. A semicolon inside such a string belongs to the value, not to the parameter list. Splitting the entire header on every semicolon turns quoted content into new parameters. handleReferNotify uses the parsed id to decide whether a NOTIFY belongs to the current REFER, so a spurious id can discard its final result. Both inbound NOTIFY handling and outbound NOTIFY handling call this parser.

Example: After REFER CSeq 12 receives a successful response, its peer sends NOTIFY with Event: refer;id=12;foo="tag;id=13;rest" and a SIP/2.0 200 OK sipfrag. The parser overwrites id 12 with 13, and the success is ignored rather than completing the transfer.

Recommended fix: Tokenize Event parameters while respecting quoted strings and escaped quotes; only treat semicolons outside quoted values as delimiters. Add a test with an id-like substring inside a quoted generic parameter.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.75%. Comparing base (0460b40) to head (dc5e18d).
⚠️ Report is 429 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #922      +/-   ##
==========================================
+ Coverage   65.25%   70.75%   +5.50%     
==========================================
  Files          51       45       -6     
  Lines        6588     8984    +2396     
==========================================
+ Hits         4299     6357    +2058     
- Misses       1915     2118     +203     
- Partials      374      509     +135     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

NOTIFY rejected with 501 when the Event header has whitespace or extra params

1 participant