Bug 202401 - REGRESSION (Safari 13): WebSocket payload is truncated when x-webkit-deflate-frame is used
Summary: REGRESSION (Safari 13): WebSocket payload is truncated when x-webkit-deflate-...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: Other
Hardware: Macintosh macOS 10.14
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
: 204237 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-10-01 06:03 PDT by Volodymyr Sorokin
Modified: 2019-11-25 00:50 PST (History)
12 users (show)

See Also:


Attachments
Patch (5.71 KB, patch)
2019-11-22 01:08 PST, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Volodymyr Sorokin 2019-10-01 06:03:40 PDT
Since Safari 13.0 release, webkit starts to truncate websocket's payload to 4092 bytes when 'x-webkit-deflate-frame' extension is used.

The issue is fairly easy to reproduce - just send to a websocket any data whose compressed size is 5kb or more.

Moreover, the websocket (most likely the deflator component) on the browser side also gets 'corrupted' once a large message is sent. This leads to a 'Failed to compress frame' error in console on subsequent attempts to send more messages (even small messages) to the socket.

This behavior is only reproducible when 'x-webkit-deflate-frame' extension enabled. 
If server rejects the extension - then browser behaves correctly and the payload does not get truncated, but obviously the compression is not used in this case.

Safari 12 does not have this issue. In Safari 12 the 'x-webkit-deflate-frame' extension behaves as expected and large payload does not get truncated.
Comment 1 Alexey Proskuryakov 2019-10-02 13:43:02 PDT
Thank you for the report!

Do you have a live website that we could reproduce this?
Comment 2 Radar WebKit Bug Importer 2019-10-02 13:43:16 PDT
<rdar://problem/55922632>
Comment 3 Volodymyr Sorokin 2019-10-03 06:55:11 PDT
I wasn't able to find a public working websocket server that supports 'permessage-deflate' extension.

But I created a simple server on java to reproduce the issue:

1) Clone it from https://github.com/vlsorokin/websocket-sandbox

2) Run server
> mvn compile exec:java

3) To run client open this jsfiddle in Safari 13: http://jsfiddle.net/sorrro/8b3yawod/

4) Click - Connect, Send short text, Send large text, Send short text
This will send to a websocket a random string of 10 characters, then a random string of 10,000 characters, then 10 characters again

5) You will notice an error in console saying: 'Failed to compress frame'

6) Server logs will indicate that the server has not received less than 10,000 characters

7) If you inspect traffic with Wireshark you may notice that in Safari 13, a large frame gets truncated to 4092 bytes and the second short message does not get sent.

At the same time, these steps work fine in Chrome.
Comment 4 Alexey Proskuryakov 2019-10-03 09:13:38 PDT
Thank you. More direct steps to reproduce would help (it's unlikely that anyone here has JDK installed), but we can probably figure it out.

Sadly, we had a test for deflate fail for a long time:

../OpenSource/LayoutTests/platform/win/TestExpectations:3177:http/tests/websocket/tests/hybi/deflate-frame-parameter.html [ Failure ]
../OpenSource/LayoutTests/platform/ios/TestExpectations:2886:# <rdar://problem/33630526> http/tests/websocket/tests/hybi/deflate-frame-parameter.html is failing on iOS 11
../OpenSource/LayoutTests/platform/ios/TestExpectations:2887:http/tests/websocket/tests/hybi/deflate-frame-parameter.html [ Failure ]
../OpenSource/LayoutTests/platform/mac/TestExpectations:1569:[ HighSierra+ ] http/tests/websocket/tests/hybi/deflate-frame-parameter.html [ Failure ]
../OpenSource/LayoutTests/platform/wincairo/TestExpectations:972:http/tests/websocket/tests/hybi/deflate-frame-parameter.html [ Failure ]
Comment 5 Volodymyr Sorokin 2019-10-03 10:40:38 PDT
There is nothing special in that java websocket server (I shared it to have a complete working example)

I.e. any server that supports `x-webkit-deflate-frame` extension should be enough, so hopefully you will be able to reproduce the bug with your own server (just make sure you use Safari 13 and `x-webkit-deflate-frame` extension is enabled).

p.s
minor correction: I wrote "permessage-deflate extension" in my previous comment, but I meant "x-webkit-deflate-frame extension" (which is default in Safari)
Comment 6 Fabrizio Ruggeri 2019-10-26 02:18:05 PDT
Any news on the status of this? Does it affect any other browser?
Comment 7 berkus 2019-11-15 11:26:34 PST
Fabrizio, as far as I'm aware it only affects Safari 13 (Safari 13.0.2 included), but on both macOS and iOS (and probably ipadOS).
Comment 8 youenn fablet 2019-11-21 20:43:25 PST
I can repro the failure with Volodymyr repro case.
Failure happens after sending 32kb roughly.
Reverting https://trac.webkit.org/changeset/246573 fixes the issue in that specific case.
Comment 9 youenn fablet 2019-11-22 01:08:06 PST
Created attachment 384131 [details]
Patch
Comment 10 berkus 2019-11-22 06:12:34 PST
@Volodymyr Sorokin

We have force-disabled support for "x-webkit-deflate-frame" extension on the server side. This seems to work around the problem for the time being.
Comment 11 Alexey Proskuryakov 2019-11-22 09:32:22 PST
*** Bug 204237 has been marked as a duplicate of this bug. ***
Comment 12 WebKit Commit Bot 2019-11-25 00:50:20 PST
Comment on attachment 384131 [details]
Patch

Clearing flags on attachment: 384131

Committed r252847: <https://trac.webkit.org/changeset/252847>
Comment 13 WebKit Commit Bot 2019-11-25 00:50:22 PST
All reviewed patches have been landed.  Closing bug.