Repository navigation
Allow restricting serialization and transfer to the same agent cluster - #13055
Conversation
2643089 to
1d2bc89
Compare
Some serializable and transferable objects, such as VideoFrame and MediaSourceHandle, cannot leave their agent cluster. Specifications have approximated this using [Exposed=(Window,DedicatedWorker)], but Window objects in different agent clusters can communicate with each other, and a dedicated worker created by a shared worker is in the agent cluster of that shared worker. Serialization and transfer steps can now restrict their result to the same agent cluster, and [SameAgentCluster] does so for every object implementing an interface. StructuredDeserialize and StructuredDeserializeWithTransfer then throw in a different agent cluster, as they already did for SharedArrayBuffer, which now uses the same mechanism. Serializing such objects for storage throws. A result restricted this way no longer needs to be realm-independent. This will help w3c/webcodecs#717
1d2bc89 to
ceb3c16
Compare
|
Looks reasonable to me. Some suggestions from claude: AI reviewReviewed at ceb3c16. The SharedArrayBuffer refactor looks like it behaves the same as before: the order of the cross-origin isolation, Suggestions
Nits
|
|
Thanks, reworked it a bit. |
https://bugs.webkit.org/show_bug.cgi?id=327156 rdar://189747796 Reviewed by NOBODY (OOPS!). whatwg/html#13055 adds the [SameAgentCluster] extended attribute: serializing or transferring an object implementing such an interface restricts the result to the agent cluster it came from, deserializing it in another agent cluster throws a DataCloneError, and serializing it for storage throws as well. This is what w3c/webcodecs#717 needs for EncodedVideoChunk, VideoFrame, EncodedAudioChunk, and AudioData, and what the WebCodecs crossAgentCluster tests already expect. MediaStreamTrack and MediaStreamTrackHandle are transferred the same way, so restrict them too. The bindings generator now emits isRestrictedToSameAgentCluster for [Serializable] and [Transferable] interfaces. SerializedScriptValue maps each serialization tag to the PlatformObjectSerializationTraits of its interface in one place, platformObjectSerializationTraitsForTag(), which both the exposure check and the new isTagRestrictedToSameAgentCluster() use. When CloneSerializer writes a restricted tag it writes the agent cluster ID after it, as JSC already does for SharedArrayBuffer, and CloneDeserializer checks that ID before reading the object. All of these objects already refuse to be serialized for storage, before their tag is written. The existing tests only cover the video types, so add tests for AudioData, EncodedAudioChunk, MediaStreamTrack, and MediaStreamTrackHandle. Tests: imported/w3c/web-platform-tests/mediacapture-insertable-streams/MediaStreamTrackHandle-transfer-cross-agent-cluster.https.html imported/w3c/web-platform-tests/mediacapture-streams/MediaStreamTrack-transfer-cross-agent-cluster.https.html imported/w3c/web-platform-tests/webcodecs/audio-serialization.crossAgentCluster.https.html
whatwg/html#13055 adds the [SameAgentCluster] extended attribute: serializing or transferring an object implementing such an interface restricts the result to the agent cluster it came from, deserializing it in another agent cluster throws a DataCloneError, and serializing it for storage throws as well. This is what w3c/webcodecs#717 needs for EncodedVideoChunk, VideoFrame, EncodedAudioChunk, and AudioData, and what the WebCodecs crossAgentCluster tests already expect. MediaStreamTrack and MediaStreamTrackHandle are transferred the same way, so restrict them too. The bindings generator now emits isRestrictedToSameAgentCluster for [Serializable] and [Transferable] interfaces. SerializedScriptValue maps each serialization tag to the PlatformObjectSerializationTraits of its interface in one place, platformObjectSerializationTraitsForTag(), which both the exposure check and the new isTagRestrictedToSameAgentCluster() use. When CloneSerializer writes a restricted tag it writes the agent cluster ID after it, as JSC already does for SharedArrayBuffer, and CloneDeserializer checks that ID before reading the object. All of these objects already refuse to be serialized for storage, before their tag is written. The existing tests only cover the video types, so add tests for AudioData, EncodedAudioChunk, MediaStreamTrack, and MediaStreamTrackHandle. WebKit-Bug: https://bugs.webkit.org/show_bug.cgi?id=327156
https://bugs.webkit.org/show_bug.cgi?id=327156 rdar://189747796 Reviewed by Youenn Fablet. whatwg/html#13055 adds the [SameAgentCluster] extended attribute: serializing or transferring an object implementing such an interface restricts the result to the agent cluster it came from, deserializing it in another agent cluster throws a DataCloneError, and serializing it for storage throws as well. This is what w3c/webcodecs#717 needs for EncodedVideoChunk, VideoFrame, EncodedAudioChunk, and AudioData, and what the WebCodecs crossAgentCluster tests already expect. MediaStreamTrack and MediaStreamTrackHandle are transferred the same way, so restrict them too. The bindings generator now emits isRestrictedToSameAgentCluster for [Serializable] and [Transferable] interfaces. SerializedScriptValue maps each serialization tag to the PlatformObjectSerializationTraits of its interface in one place, platformObjectSerializationTraitsForTag(), which both the exposure check and the new isTagRestrictedToSameAgentCluster() use. When CloneSerializer writes a restricted tag it writes the agent cluster ID after it, as JSC already does for SharedArrayBuffer, and CloneDeserializer checks that ID before reading the object. All of these objects already refuse to be serialized for storage, before their tag is written. The existing tests only cover the video types, so add tests for AudioData, EncodedAudioChunk, MediaStreamTrack, and MediaStreamTrackHandle. Tests: imported/w3c/web-platform-tests/mediacapture-insertable-streams/MediaStreamTrackHandle-transfer-cross-agent-cluster.https.html imported/w3c/web-platform-tests/mediacapture-streams/MediaStreamTrack-transfer-cross-agent-cluster.https.html imported/w3c/web-platform-tests/webcodecs/audio-serialization.crossAgentCluster.https.html Canonical link: https://commits.webkit.org/323558@main
AI review## Review of #13055 — "Allow restricting serialization and transfer to the same agent cluster" (head `2113e92`)
|
whatwg/html#13055 adds the [SameAgentCluster] extended attribute: serializing or transferring an object implementing such an interface restricts the result to the agent cluster it came from, deserializing it in another agent cluster throws a DataCloneError, and serializing it for storage throws as well. This is what w3c/webcodecs#717 needs for EncodedVideoChunk, VideoFrame, EncodedAudioChunk, and AudioData, and what the WebCodecs crossAgentCluster tests already expect. MediaStreamTrack and MediaStreamTrackHandle are transferred the same way, so restrict them too. The bindings generator now emits isRestrictedToSameAgentCluster for [Serializable] and [Transferable] interfaces. SerializedScriptValue maps each serialization tag to the PlatformObjectSerializationTraits of its interface in one place, platformObjectSerializationTraitsForTag(), which both the exposure check and the new isTagRestrictedToSameAgentCluster() use. When CloneSerializer writes a restricted tag it writes the agent cluster ID after it, as JSC already does for SharedArrayBuffer, and CloneDeserializer checks that ID before reading the object. All of these objects already refuse to be serialized for storage, before their tag is written. The existing tests only cover the video types, so add tests for AudioData, EncodedAudioChunk, MediaStreamTrack, and MediaStreamTrackHandle. WebKit-Bug: https://bugs.webkit.org/show_bug.cgi?id=327156
AI reviewNits
When |
|
Simon, I think that’s obvious and does not need specification language. |
Allow restricting serialization and transfer to the same agent cluster
Some serializable and transferable objects, such as VideoFrame and MediaSourceHandle, cannot leave their agent cluster. Specifications have approximated this using [Exposed=(Window,DedicatedWorker)], but Window objects in different agent clusters can communicate with each other, and a dedicated worker created by a shared worker is in the agent cluster of that shared worker.
Serialization and transfer steps can now restrict their result to the same agent cluster, and [SameAgentCluster] does so for every object implementing an interface. StructuredDeserialize and StructuredDeserializeWithTransfer then throw in a different agent cluster, as they already did for SharedArrayBuffer, which now uses the same mechanism. StructuredDeserializeWithTransfer now does this, and checks that all serialized and transferred interfaces are exposed, before running any transfer-receiving steps. Serializing such objects for storage throws. A result restricted this way may additionally refer to data that is only accessible within that agent cluster.
This will help w3c/webcodecs#717
(See WHATWG Working Mode: Changes for more details.)
/index.html ( diff )
/structured-data.html ( diff )