Websocket incorrectly decoded

837 views
Skip to first unread message

Emeric Chassagne

unread,
Apr 7, 2017, 10:44:51 AM4/7/17
to Fiddler
Hi,
I use fiddler (and fiddlercore) to see websocket traffic, but some messages appears like they weren't decoded (�}�n�8�&� � t ;�*�E�� �8H���) but all other are fully readable.
I try the same with charlesproxy and every messages a readable in plain text.

Is there something wrong with Fiddler/FiddlerCore ? Od did I miss something about "OnWebSocketMessageHandler" and "oWSM.PayloadAsString" ?

Thanks,
Emeric.

Eric Lawrence

unread,
Apr 10, 2017, 2:44:49 PM4/10/17
to Fiddler
If you provide a SAZ file containing some traffic I can help you, but you may be encountering deflated websocket traffic. See https://fiddler.ideas.aha.io/ideas/FID-I-103 for the feature request and a workaround you can use.

Eric Lawrence

unread,
Apr 11, 2017, 12:37:58 PM4/11/17
to Fiddler
(File received and analyzed)

Yeah, this is caused by the WebSocket using the deflate extension; you can see this in the response headers on the Tunnel itself:

    permessage-deflate; server_no_context_takeover 

Sadly, the https://fiddler.ideas.aha.io/ideas/FID-I-103 link lost the script where I showed how to fix this but the simple approach is to do something like this inside your BeforeRequest handler:

   if (oSession.RequestHeaders.ExistsAndContains("Sec-WebSocket-Extensions", "permessage-deflate")) {
      oSession.RequestHeaders.Remove("Sec-WebSocket-Extensions");
   }

This will cause the client to stop advertising support for deflate which should cause the server to stop trying to use it.

Emeric Chassagne

unread,
Apr 14, 2017, 5:52:55 AM4/14/17
to Fiddler
Thank you a lot eric :)

I fanilly get it works thanks to your help.
I had to read 2nd bit of 1st byte in message header here is my code :

Imports Fiddler
Imports Fiddler.Utilities
Imports System.Text.Encoding

[... more code]
    Public Sub OnWebSocketMessageHandler(Sender As Object, e As WebSocketMessageEventArgs)
        If Not e.oWSM.IsOutbound And e.oWSM.PayloadData.Any Then
 
            Dim FirstByte As New BitArray(New Byte() {e.oWSM.ToByteArray(0)}) 'Get first byte from header
            Dim UseDeflate As Boolean = FirstByte.Get(FirstByte.Length - 2) 'Get 2nd bit value (RSV1)
 
            Dim Response As String = Nothing
 
            If UseDeflate Then
                Response = UTF8.GetString(DeflaterExpand(e.oWSM.PayloadData))
            Else
                Response = e.oWSM.PayloadAsString()
            End If
 
            If Not Response = String.Empty Then
                ReadResponse(Response)
#If DEBUG Then
                Debug.Print(Response)
#End If
            End If
        End If
    End Sub
Reply all
Reply to author
Forward
0 new messages