Reject malformed timeout headers with invalid_argument - #351
Merged
Merged
Conversation
Both timeout parsers passed the header to `int()`, which also accepts a sign, surrounding whitespace, and underscores. A negative `connect-timeout-ms` or `grpc-timeout` was therefore accepted, where connectrpc/connect-go#982 now rejects it. Both parsers now require ASCII digits. `_parse_timeout` raised `ValueError`, so a malformed `grpc-timeout` became a 500 `unknown` response and propagated to the ASGI server as an unhandled exception. It now raises `ConnectError(INVALID_ARGUMENT)`, as connect-go does. The response is still a Connect error (HTTP 400 with a JSON body), which a gRPC client reads as `internal`; grpc-go answers a malformed `grpc-timeout` with `internal` too. Signed-off-by: Stefan VanBuren <stefan@vanburen.xyz>
stefanvanburen
commented
Sep 25, 2026
Member
Author
There was a problem hiding this comment.
going to fix this being marked as "generated" separately...
stefanvanburen
commented
Sep 25, 2026
| digits = timeout[:-1] | ||
| # int() also accepts a sign, whitespace, and underscores. | ||
| if not (digits.isascii() and digits.isdigit()): | ||
| raise ConnectError( |
Member
Author
There was a problem hiding this comment.
a tad funky to do this as connect errors in gRPC-land, but seems reasonable to match connect-go.
stefanvanburen
marked this pull request as ready for review
September 25, 2026 01:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both timeout parsers passed the header to
int(), soconnect-timeout-ms: -1andgrpc-timeout: -5mwere accepted and produced a negativectx.timeout_ms. connectrpc/connect-go#982 closed the same gap forconnect-timeout-mslast week. This goes a step further and requires ASCII digits, matching the spec and connect-es's/^\d{1,10}$/, so+5and-0are rejected here where connect-go still accepts them.A malformed
grpc-timeoutpreviously raisedValueError, which surfaced as a 500unknownand an unhandled exception in the ASGI server's logs. It is nowinvalid_argument, as in connect-go.The error is still written as a Connect JSON response, so a gRPC client sees HTTP 400 and maps it to
internal, which is also what grpc-go returns for a malformedgrpc-timeout. Sending it as a trailers-only gRPC response instead would need the pre-stream error path in both servers to know the protocol; I left that out to keep this small.