Closed Bug 2085562 Opened 1 month ago Closed 13 days ago

WebTransport incomingBidirectionalStreams can return a usable-looking stream after the transport is closed

Categories

(Core :: DOM: Networking, defect, P3)

defect

Tracking

()

RESOLVED FIXED
163 Branch
Tracking Status
firefox163 --- fixed

People

(Reporter: jesup, Assigned: jesup, NeedInfo)

References

Details

(Whiteboard: [necko-triaged], [wptsync upstream])

Attachments

(1 external file)

When a WebTransport session closes cleanly, WebTransport::Cleanup() resolves closed with a WebTransportCloseInfo object. Resolving a promise with an object looks up then on it synchronously, so a getter on Object.prototype.then runs in the middle of cleanup, after [[SendStreams]]/[[ReceiveStreams]] have been emptied and errored but before incomingBidirectionalStreams/incomingUnidirectionalStreams are closed.

If that getter calls read() on an incoming streams reader while the server has opened streams the page hasn't pulled yet, the pull algorithm runs synchronously. WebTransportIncomingStreamsAlgorithms::BuildStream takes the next queued pipe, creates a new WebTransportBidirectionalStream (or WebTransportReceiveStream), adds it to the transport's stream sets after they were already errored, and enqueues it. The page gets a stream on a closed transport that is never errored; it only dies when its underlying pipes are torn down.

Per spec, pulling after cleanup has no session to receive a stream from, and the incoming streams are then closed, so the read should resolve with done: true.

Steps to reproduce:

  1. Connect to a server that opens several bidirectional streams, then a unidirectional stream as a marker.
  2. Read the marker from incomingUnidirectionalStreams; the bidirectional streams are now queued but not pulled.
  3. Get a reader for incomingBidirectionalStreams without reading from it, and define a then getter on Object.prototype that, when called on the close info object, calls reader.read() on that reader.
  4. Call wt.close() and await the read.

Expected: the read resolves with done: true.
Actual: the read resolves with a new bidirectional stream.

The fix is to implement step 2 of pullBidirectionalStream/pullUnidirectionalStream (reject the pull once the transport is closed or failed), and have BuildStream bail out for a waiting pull that resumes after cleanup. Testcase: webtransport/close2.https.any.js.

A 'then' getter on Object.prototype runs synchronously while Cleanup()
resolves closed, and can read from an incoming streams readable. The
pull then built a stream from a queued pipe and added it to the
transport's stream sets after they had already been errored, handing
script a live-looking stream on a closed transport.

Implement step 2 of pullBidirectionalStream/pullUnidirectionalStream,
rejecting the pull once the transport is closed or failed, and have
BuildStream bail out too for a waiting pull that resumes after cleanup.

Assignee: nobody → rjesup
Status: NEW → ASSIGNED
See Also: → 2085588
Severity: -- → S3
Priority: -- → P3
Whiteboard: [necko-triaged]
Pushed by abutkovits@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/cc8157838528 https://hg.mozilla.org/integration/autoland/rev/f6b8b56f1d93 Revert "Bug 2085562: don't build incoming WebTransport streams after cleanup r=jib" for causing bustages complaining about wt_initial_max_data.
Status: ASSIGNED → RESOLVED
Closed: 13 days ago
Resolution: --- → FIXED
Target Milestone: --- → 163 Branch

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/65566 for changes under testing/web-platform/tests

Whiteboard: [necko-triaged] → [necko-triaged], [wptsync upstream]

Upstream PR merged by moz-wptsync-bot

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: