Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught handlerTrailers exception when decodeURI on unencoded grpc-message #2209

Closed
clww opened this issue Aug 29, 2022 · 2 comments
Closed

Comments

@clww
Copy link

clww commented Aug 29, 2022

Problem description

We are currently calling a grpc server which doesn't handle the grpc-message correctly, so sometimes it will send unencoded grpc-message containing %, causing the decodeURI (code) to throw the following exception.

            details = decodeURI(metadataMap['grpc-message']);
                      ^

URIError: URI malformed
    at decodeURI (<anonymous>)
    at Http2CallStream.handleTrailers (.../node_modules/@grpc/grpc-js/build/src/call-stream.js:322:23)
    at ClientHttp2Stream.<anonymous> (.../node_modules/@grpc/grpc-js/build/src/call-stream.js:378:26)
    at ClientHttp2Stream.emit (node:events:520:28)
    at ClientHttp2Stream.emit (node:domain:475:12)

Reproduction steps

decodeURI('%') <---- throws a unhandled exception, then crashes the server

Additional context

There are 2 ways to handle the exception:

  • catch the exception and use endCall to return an error (similar code) . or
  • return the raw grpc-message if decodeURI failed

The gRPC HTTP/2 spec seems to prefer the second way:

When decoding invalid values, implementations MUST NOT error or throw away the message. At worst, the implementation can abort decoding the status message altogether such that the user would received the raw percent-encoded form. Alternatively, the implementation can decode valid portions while leaving broken %-encodings as-is or replacing them with a replacement character (e.g., '?' or the Unicode replacement character).

@murgatroid99
Copy link
Member

I have published a fix for this in version 1.6.11

@clww
Copy link
Author

clww commented Aug 30, 2022

Thanks @murgatroid99 ! though I found that there is a typo in the PR changes. The grpc-messages in the catch block should be grpc-message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants