Fix review: H-L8-08 (answer SDP ends the server process)
From mnema-talk v3.3.13, rendered on this site.
Update: review of the tip 065d9b451 (supersedes the verdict below)
Tip 065d9b451 merges the H-L8-07 tip e365c714d into e01ced711 and adds
vetAnswerSections: an answer must have the pending offer's media sections
(same count, same order, same mids), checked before the SSRC lines and the
candidates.
Verdict for the tip: MERGE AFTER FIXES (one blocker left).
- Blocker 2 (repeated mid) is closed. The SFU's offers carry unique mids,
so a position-by-position mid match makes a repeated mid impossible. The case
I used against
e01ced711is now refused witherrAnswerSections, and the client's honest answer is then accepted and the connection reachesconnected. Both the library (getMidValue,sdp.go:830) and the vetter (MediaDescription.Attribute, pion/sdp v3.0.20) take the firsta=midof a section, so a section with two mid lines is read the same way by both. - BLOCKER 1 is still open on the tip.
ssrcPairstill usesstrings.Fields(internal/sfu/answer_candidates.go:197). The three spacing variants of an FID group (see Blocker 1 below) are still accepted (err=<nil>), and each still ends the test binary with thertpreceiver.go:544nil-pointer panic. The section rule cannot catch them because sections, order and mids are all the offer's. Fix as before: split the group value on a single space the way the library does, and refuse anything that is not exactly three fields. Add the three variants toTestAnAnswerNamesOneStreamPerMediaSection.
Checks of the new rule:
- Is PendingLocalDescription the right offer on every path? Yes, for the
paths the SFU has. The SFU creates an offer only in the stable state
(
room_signal.go:113), so no second offer is ever made while one is pending. The watchdog resends the same pending description (resendOffer), so a late answer to a resent offer is compared with that same offer. The SFU never does an ICE restart or a rollback (noICERestart/rollback ininternal/sfu). With no offer outstanding the rule passes and Pion refuses the answer for the wrong signaling state, as before. A late answer to offer N that arrives after offer N+1 was sent is compared with N+1. That was already possible before this change (Pion would apply it if the shapes agree) and is not a regression. - Can an honest client answer with a different count, order or mid? No.
JSEP requires the answer to keep every offered m-section, in order; a
rejected section stays in place with port 0 and is never dropped. Chrome and
Firefox keep
a=midon a rejected section. That is my understanding of both browsers; I could not run them here, and CI's e2e call specs are the real check. The repo's web client never rejects a section itself: it stops tracks but never a transceiver (web/src/talk/composables/webrtc/), and it munges only the offer, never the answer. NOTE: if some browser lefta=midoff a port-0 section, the rule would refuse every answer and the member would be dropped aftermaxOfferResends. A port-0 section without a mid could be allowed at its position as a cheap safeguard; optional. - Does a refusal leave the peer able to continue? Yes. I checked it myself
for both rules: after a refused answer (SSRC rule, and section rule via the
repeated mid), the honest answer is accepted and the connection reaches
connected.TestAnAnswerWithASectionOfItsOwnIsRefusedasserts the same. - Cost.
vetAnswerSectionson a 200-section offer (116 KB of SDP) costs about 0.22 ms and 440 KB allocated (2 239 allocs) per answer, because the offer is parsed again for every answer. Answers are capped at 200 a second per connection (signaling budget), so a member sending refused answers can cost about 45 ms of CPU and about 88 MB of garbage a second. That is about the same as the existing parse of the answer itself (up to 64 KiB) per event. SHOULD-FIX (not blocking): keep the offered mids when the offer is made (perofferGen) and compare with that list, so no offer is parsed per answer. - Revert check. With the
vetAnswerSectionscall removed,TestAnAnswerWithASectionOfItsOwnIsRefusedfails ("an answer with a section of its own:"). The unit matrix tests the function directly and passes. The changed fixture in attach_viewer_test.goonly adds the offer's mid and still asserts the same refusal; nothing weakened. - Suites and gates at the tip.
go test -race -p 1 ./internal/sfu/ok (97.6 s).internal/wsandinternal/repook. gofmt clean, vet clean with and without-tags=integration,make complexity-checkexit 0, the English check andmake docs-checkpass,make bench-allocs0 allocs/op.answer_candidates.gois 209 lines. SECURITY.md has one merged entry (no duplicate) that describes both rules. Commit typefix, no attribution. - Known flaky test.
TestSubscriptionTogglesMakeQuietStreamsdid not fail in my-racerun of the tip.
The review of e01ced711 follows unchanged.
Reviewer: independent fix-reviewer (wrote neither finding nor fix).
Fix under review: local branch fix-h-l8-08-local, commit e01ced711
("fix: the SFU vets the SSRC lines of an answer against its offer"), on top of
origin/msch128/fix-h-l8-07 (fd4645559).
Baseline: origin/main f58bc3fc6 (release 3.0.9).
Library studied: github.com/pion/webrtc/v4@v4.2.26 (module cache).
Verdict: MERGE AFTER FIXES
The fix removes the exact reproduced defect and every variant the finding's
test names, and leaves honest clients untouched. But the finding's own
"Not examined" list (section count and order, directions) is where the same
unrecovered, process-ending failure still hides: I found two further inputs,
each outside the fix's tests, that pass the new rule and still reach the same
nil-pointer dereference in the library's own goroutine (rtpreceiver.go:544)
and end the process. Both are the same defect class as the finding, not new
behaviour. They must be closed before merge.
Each blocker below was reproduced against the fix and then closed by a candidate change that I ran; the honest path keeps working with the change in place.
What the fix does, and why the invariant is right
vetAnswerCandidates now calls vetAnswerSSRCs on the parsed SDP before any
candidate is counted and before SetRemoteDescription. The rule: per media
section at most one stream (one SSRC, plus the SSRCs an a=ssrc-group FID or
FEC-FR line ties to it); no SSRC in two sections; otherwise the whole answer is
refused (SetAnswer returns errAnswerSSRCs, internal/ws/handle.go:209 logs
it at warn, the offer's watchdog resends).
Why one stream per section is correct, confirmed against the library source:
trackDetailsFromSDP (sdp.go:79) decides how many inbound tracks a section
has, and it reads only two attribute kinds to do so — a=ssrc and
a=ssrc-group (FID/FEC-FR, which demote the repair SSRC out of the track
list). For every track it then calls startReceiver →
startReceive (rtpreceiver.go), which opens an SRTP read stream per SSRC.
The SFU creates exactly one receiver per section, so a section the library
reads as carrying two streams makes the library start a receiver the SFU never
built, and the unguarded dereference follows. One stream per section is the
right invariant for the SSRC path.
Two caveats the fix does not fully honour (the blockers):
- The library decides the number of streams from
a=ssrc/a=ssrc-group, but it attaches each to a transceiver by mid. The rule never checks that mids are unique, so an answer can stay within "one stream per section" and still drive the library to two streams on one transceiver. - The library parses
a=ssrc-groupdifferently from the fix. The fix must read a group exactly the way the library reads it, or an answer the fix treats as a benign repair pair is treated by the library as a second independent stream.
The library does read a=rid/a=simulcast and session-level attributes, but
neither leads to the crash (see Confirmations), so the rule's silence on them
is acceptable.
BLOCKER 1 — a=ssrc-group parsed more leniently than the library
ssrcPair (internal/sfu/answer_candidates.go) splits the group value with
strings.Fields, which collapses runs of whitespace and splits on tabs. The
library splits the same value with strings.Split(attr.Value, " ")
(sdp.go:111) and only demotes the repair SSRC when that single-space split
has exactly three fields (sdp.go:117, :145). The answer SDP that reaches
the library is the fix's own re-marshalled form, so the exact spacing the
client wrote is preserved through to the library.
Consequence: a FID group whose value is spaced so that the single-space split is not length-3 (an extra inner space, a trailing space, or a tab) is read by the fix as a valid repair pair (benign) and by the library as "no repair pair" — so the library keeps the second SSRC as an independent stream, starts a second receiver on the section, and the process ends.
Reproduced against the fix: three spacing variants of a FID group, each
accepted by SetAnswer (err=<nil>) and each followed by the
rtpreceiver.go:544 nil-pointer panic that exits the test binary. Honest
answers are unaffected.
Suggested fix: parse the group exactly as the library does — split on a single
space, require length 3 and the FID/FEC-FR token — and refuse any group
value that is not exactly that shape. I made this one change
(strings.Fields → strings.Split(value, " ") in ssrcPair), rebuilt, and
all three spacing variants were then refused with errAnswerSSRCs while the
honest answer still connected and TestAnAnswer* still passed.
BLOCKER 2 — two media sections sharing one a=mid
vetAnswerSSRCs checks SSRCs per section and cross-section SSRC uniqueness but
never checks that mids are unique. The library matches each section's tracks to
a transceiver by mid (runIfNewReceiver, peerconnection.go:1760;
configureRTPReceivers). An answer with two media sections that carry the same
mid, each one honest-looking (one SSRC, distinct from the other), passes the
new rule and still drives the library onto the same unrecovered path.
Reproduced against the fix: an answer whose second audio section is relabelled
with the first section's mid and given one SSRC of its own is accepted
(err=<nil>) and is followed by the same rtpreceiver.go:544 panic. It
reproduces whether the duplicated section keeps its negotiated direction or is
forced to sendrecv.
Suggested fix: refuse an answer with a repeated mid. More robustly, vet that
the answer's media sections correspond one-to-one to the offer's (same mids,
no extra section) — this subsumes both blockers and the finding's whole
"Not examined" list rather than enumerating bad shapes. I added a repeated-mid
check to vetAnswerSSRCs, rebuilt, and both variants were then refused while
every honest and benign case still behaved as before.
Confirmations (all positive)
- Reproduces on main, refused on the fix. The finding's recorded repro
ends the test binary with the nil-pointer dereference on
f58bc3fc6; on the fix the same answer is refused (errAnswerSSRCs) and the suite isok. - Revert check. Removing the
vetAnswerSSRCscall fromvetAnswerCandidatesmakesTestAnAnswerWithASecondStreamInASectionIsRefusedfail (the second stream is accepted); restoring it passes. The new unit matrixTestAnAnswerNamesOneStreamPerMediaSectionpasses. The recorded tests run as ordinary tests (no build tag, no env gate). - Honest clients. A Pion loopback client's own answer (audio publish)
connects through the fix; the full
internal/sfusuite with-raceis green (94 s), as isinternal/ws(16 s). The rule refuses only what the library would over-read. - Library read surface.
trackDetailsFromSDPreads onlya=ssrcanda=ssrc-groupto count streams; it never reads session-levela=ssrc(it iteratesmedia.Attributesonly) — I confirmed a session-levela=ssrcis accepted and harmless, and the fix likewise ignores it, so the two agree.a=rid/a=simulcastgo down the RID path (receiveForRid), which does not open a per-SSRC receiver the way the crash needs — I confirmed a section with extraa=rid/a=simulcastlines is accepted and harmless. So the rule not looking at rid/simulcast/session-ssrc is safe. ssrc-group:SIMrefusal is safe. The SFU offers each layer as its own m-section (seeweb/src/talk/composables/webrtc/sdp.ts), so a browser is never asked to simulcast within one section and will not answer with a SIM group; refusing SIM rejects nothing honest.- Interplay with H-L8-07.
p.rtcp.declare(answer.SDP)runs only afterSetRemoteDescriptionreturns nil (room_signal.go:31); a refused answer returns earlier, sodeclarenever sees a rejected answer.declare's own SSRC parse (ingress.go) is an independent per-line single-spaceCutwith its own budget and does not conflict with the new vetting. - Refusal path cost. A refused answer returns an error;
internal/wslogs it at warn and the offer watchdog resends (room_signal.go), capped atmaxOfferResends = 6before the peer is dropped. Answers are metered by themaxSignalingPerSec = 200budget and the 64 KiB frame cap. No goroutine or timer is pinned per refused attempt;SetAnsweron a refused answer touches no connection state. The warn log is not itself rate-limited, but the resend cap and the per-second signaling budget bound the volume.
Gates
gofmt -l: clean.go vet ./internal/sfu/andgo vet -tags=integration: clean.make complexity-check: exit 0.node scripts/check-english-only.mjs: pass.make docs-check: pass.go test ./internal/repo/: ok (production file cap respected — the code was added to an existing file).make bench-allocs: 0 allocs/op on the forward path (the fix is not on it).- SECURITY.md entry matches the implemented behaviour. Commit type
fix; nofeat, no!, no AI attribution. No gate, allowlist, size limit or existing test weakened; no runtime dependency added.
What I did not check
- The library's behaviour for mismatched bundle groups and rejected (port-0) sections beyond the two blockers above; the one-to-one section/mid vetting suggested for Blocker 2 would be the durable way to cover these, and I recommend the coordinator consider it rather than patching shape by shape.
- Real browsers (Chrome/Firefox/Safari): only the Pion loopback clients exist locally. The reasoning on honest answers rests on the library source and the repo's own web client SDP code, not on a live browser run.
Summary
- Whitespace in
a=ssrc-group— BLOCKER: fix parses groups more leniently than the library; a tab/extra/trailing space reaches the same process-ending panic. One-line parser alignment closes it. - Duplicate
a=mid— BLOCKER: rule checks SSRCs per section but not mid uniqueness; the library keys receivers by mid and reaches the same panic. A repeated-mid (better: offer-vs-answer section) check closes it. - Everything else reviewed is correct: the one-stream-per-section invariant is right for the SSRC path, honest and benign answers are untouched, the gates pass, and the H-L8-07 interplay is consistent.
Round 2: tip 0e5b74b47
Three commits: e01ced711 (SSRC rule), 065d9b451 (section rule, merged with
the H-L8-07 tip), 0e5b74b47 (SSRC lines read the way the connection reads
them).
Verdict: MERGE. Both blockers are closed, I found nothing new that blocks, and every gate exits 0.
Both reproductions are refused before the connection reads the answer
On the tip, run on loopback against the SFU's real peer, one test binary per case:
- The finding's own shape (a second SSRC in a section): refused by the SSRC rule.
- Blocker 1, all three spacing variants of a repair group (two spaces, a space at the end, a tab), and a repair SSRC with a leading zero: refused by the SSRC rule. None of them reaches the library any more.
- Blocker 2 (repeated mid): refused by the section rule.
- After each refusal, the client's honest answer is accepted and the
connection reaches
connected. - Benign shapes still pass: the honest answer, a well-formed FID pair, and a well-formed FID plus FEC-FR pair.
How the library and the vetting read each attribute
The library counts streams in trackDetailsFromSDP (sdp.go:79, webrtc
v4.2.26), section by section, and then attaches them to transceivers by mid.
Each thing it reads there, compared with the vetting:
| What the library reads | How | Vetting |
|---|---|---|
Section direction (getPeerDirection, media then session level): skips recvonly and inactive sections | attribute key | More strict: it vets every section, whatever its direction. |
a=mid (getMidValue): skips sections without one; receivers are keyed by it | first mid attribute | More strict: the first mid (pion/sdp Attribute, the same choice) must equal the offer's mid at the same position, and the count must match. Repeated, missing or foreign mids are refused. |
| Media kind: skips kinds it does not know | m= line | More strict: it vets every section. |
a=ssrc-group FID and FEC-FR: demote the repair SSRC | split at single spaces, exactly three parts, base-10 numbers; anything else is ignored | Same reading where it accepts: the same split, three parts, and only canonical decimal numbers (parseSSRC round trip), so both get the same two numbers. More strict otherwise: any other group (SIM, other separators, extra parts, signs, leading zeros, a self-repair, circles, two primaries) refuses the answer, where the library would ignore the line. |
a=ssrc: one track per distinct SSRC that is not a repair | first token before the first space, base 10; a line that does not parse is ignored | Same reading where it accepts: the same first token, required to be a canonical decimal, so it is the same number. Distinct SSRCs are counted as a set, the same dedupe as the library. More strict otherwise: a line the library would skip, or would read as another number, refuses the answer. |
a=msid and the msid: part of an a=ssrc line | labels (stream id, track id) | Not read. Harmless: they never change how many tracks a section has. Their only other use is the RID condition below. |
a=rid / a=simulcast (getRids) | with an msid, they replace the section's tracks with one RID-based track | Not read. Harmless: this path ends with one track, and RID encodings get no per-SSRC receiver (startReceive skips them, startReceiver returns for RID tracks). Tested earlier: accepted and harmless. |
Session-level a=ssrc | never read (only media attributes are) | Not read either. Same result. Tested earlier: harmless. |
Attribute keys are compared exactly on both sides (ssrc, ssrc-group,
mid). A key in other capitals, or with a stray character in it, is ignored
by both.
Re-parse. The library reads the vetted SDP after it has been marshalled and parsed again. I checked that this round trip cannot change how many streams the library counts:
- A value without a bare carriage return comes back unchanged. That includes spaces and tabs, which is why the spacing variants reached the library intact in round 1.
- A bare carriage return inside a line makes pion/sdp trim the end of the value when it parses the line again.
- The round trip never adds an attribute, and never turns a key into
ssrc. - Every value the vetting accepts as an SSRC id or a group is free of that character, so it comes back unchanged.
So the difference only touches values the vetting already refuses. This is an oddity of the pion/sdp parser worth reporting upstream (NOTE), but it is not a gap in the vetting.
Across answers. The rules are checked per answer. Across answers, the
library starts a section's receiver only once (haveReceived), and a section
whose SSRCs change is stopped and replaced by the library itself. I found no
way, across a sequence of answers that each pass, to put two streams on one
receiver. I worked this out by reading the code and tested it with the
renegotiation case below. A receiver whose start failed on an SRTP error was
not examined (NOTE).
PendingLocalDescription on every path
- First negotiation: checked against the first offer (tests above).
- Renegotiation: a second member publishes, the SFU sends the first member
a new offer, and a mutated answer to it is refused. The honest answer is then
applied, the connection is
connectedand signaling isstable. Tested. - Late answer after the watchdog resent the offer: with a short
offerTimeout, the first answer arrives after the resend and is accepted. It is the same pending description, because the watchdog resends it and the SFU creates offers only in the stable state (room_signal.go:113). Tested. - ICE restart and rollback: the SFU does neither.
- NOTE: an answer to an older offer N, sent while offer N+1 is pending, is compared with N+1. When the sections and mids agree (the SFU reuses sections), it passes and Pion applies it, which uses up offer N+1. The client's real answer to N+1 then fails with a signaling-state error, and the next round of signaling repairs that. This happened the same way before the fix, and the SSRC rule still applies to such an answer. It is not a regression and not a crash.
Honest answers, refusals, gates
go test -race -p 1 ./internal/sfu/exit 0 (95 s).go test ./internal/ws/exit 0.TestSubscriptionTogglesMakeQuietStreamsdid not fail in my run.- A refused answer leaves the peer able to take the next honest one, for every case I tried with both rules (above).
- Revert check of
0e5b74b47: withstrings.Fieldsand the oldparseSSRCput back, the rows for two spaces, a space at the end, a tab, and a leading zero fail. The rows for a sign, a leading space, and a tab-split line already pass without it, becauseParseUintrefuses those inputs; they are guards. - Exit codes at the tip: gofmt 0, vet 0, vet with
-tags=integration0,make complexity-check0, the English check 0,make docs-check0,internal/repotests 0,make bench-allocs0 (0 allocs/op). - Still open, not blocking: the SHOULD-FIX from the 065d9b451 review (the
offer is parsed again for every answer; keep its mids per
offerGen), and the NOTE about a browser leavinga=midoff a port-0 section. An end-to-endSetAnswertest for one spacing variant would be a cheap addition; the unit rows already cover the parser.