grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.57k stars 763 forks source link

Decoding grpc-web-text #1108

Open JakenVeina opened 3 years ago

JakenVeina commented 3 years ago

I'm having trouble decoding the following grpc-web-text response message, referencing the techniques and documents described in #634.

AAAAADMKMQoKQ2xvdWRmbGFyZQoHRGlzY29yZAoGR2l0SHViCgpHaXRIdWIgQVBJCgZHb29nbGU=AAAAABMSEQoHRGlzY29yZBIGEIDfoZ8BAAAAABISEAoGR29vZ2xlEgYQwNrkngE=AAAAABYSFAoKQ2xvdWRmbGFyZRIGEIDfoZ8BAAAAABYSFAoKR2l0SHViIEFQSRIGEICBt7ABAAAAAA0SCwoGR2l0SHViGIJWgAAAABBncnBjLXN0YXR1czogMA0K

I can identify the first message as encoded proto data just fine.

00
00 00 00 33
0a 31 0a 0a 43 6c 6f 75 64 66 6c 61 72 65 0a 07
44 69 73 63 6f 72 64 0a 06 47 69 74 48 75 62 0a
0a 47 69 74 48 75 62 20 41 50 49 0a 06 47 6f 6f
67 6c 65

The next part APPEARS to be a simple 4-byte data message, but by my reckoning, it's not a valid protobuf message.

00
00 00 00 04
c4 84 42 81

According to the spec documents, if I'm reading it right, next I should expect another marker, which should be either 00, 01, 80, or 81. Instead, I get D1.

d1 1a 5c d8 db dc 99 04 81 84 20 37 e8 67 c0 40
00 00 00 04 84 84 02 81 91 db db d9 db 19 44 81
84 30 36 b9 27 80 40 00 00 00 01 61 21 40 a0 a4
36 c6 f7 56 46 66 c6 17 26 51 20 61 08 0d fa 19
f0 10 00 00 00 01 61 21 40 a0 a4 76 97 44 87 56
22 04 15 04 91 20 61 08 08 1b 7b 00 10 00 00 00
00 d1 20 b0 a0 64 76 97 44 87 56 21 88 25 68 00
00 00 01 06 77 27 06 32 d7 37 46 17 47 57 33 a2
03 00 d0

Clearly, I'm missing something, because the message actually WORKS completely fine. However, what I'm seeing is that this endpoint works in local development, but somehow causes client-side exceptions in the deployed production application, so I got caught on a tangent of trying to figure out how to actually decode these messages, and learn more about what's really going on.

An actual failing message in production is...

QUFBQUFETUtNUW9LUTJ4dmRXUm1iR0Z5WlFvSFJHbHpZMjl5WkFvR1IybDBTSFZpQ2dwSGFYUklkV0lnUVZCSkNnWkhiMjluYkdVPUFBQUFBQlFTRWdvS1EyeHZkV1JtYkdGeVpSSUVFTUNFUFE9PUFBQUFBQkFTRGdvR1IyOXZaMnhsRWdRUXdJUTlBQUFBQUJFU0R3b0dSMmwwU0hWaUVnVVF3TldIQ1E9PUFBQUFBQlVTRXdvS1IybDBTSFZpSUVGUVNSSUZFTURWaHdrPUFBQUFBQkVTRHdvSFJHbHpZMjl5WkJJRUVJQ0plZz09Z0FBQUFCQm5jbkJqTFhOMFlYUjFjem9nTUEwSw==

I'm guessing this is somehow compressed?

floydjones1 commented 3 years ago

I built a tool that if you input a sample web-grpc text it should output human readable string. You can see how the internals work it might help

https://github.com/floydjones1/grpcwebtext-parser

JakenVeina commented 3 years ago

Kickass, thanks.