fix: harden HTTP gateway robustness and completeness#22
Merged
Conversation
- server.go: add ReadHeaderTimeout(10s) and IdleTimeout(60s) to http.Server to prevent slowloris attacks and resource exhaustion - server.go: rewrite Serve() to fan gRPC and HTTP into a shared errCh(2) so the first failure surfaces immediately and neither goroutine leaks - server.go: use errors.Is(err, http.ErrServerClosed) per Go convention - gateway.go: drop caller ctx from RegisterLedgerServiceHandlerFromEndpoint; use context.Background() so the loopback conn lives for the server lifetime - gateway.go: add gatewayDialTarget() to rewrite wildcard bind host (0.0.0.0) to 127.0.0.1 for the loopback dial, keeping traffic off external interfaces - gateway.go: return lowercase constants from gatewayHeaderMatcher, not canonical-case HTTP header keys - start.go: document base64 encoding and restart requirement for http_listen - gateway_test.go: add TestGatewayErrorMapping (NotFound → 404) - gateway_test.go: add TestGatewayTLS (self-signed cert loopback dial)
…tion Gateway hardening: - server.go: fix hook-init failure path to close httpListener if allocated - server.go: drain second Serve goroutine error and log it to prevent silent drops - server.go: filter grpc.ErrServerStopped symmetrically with http.ErrServerClosed - start.go: document that gateway serves plain HTTP (reverse proxy for HTTPS) - gateway_internal_test.go: unit tests for gatewayDialTarget (6 cases) and gatewayHeaderMatcher (6 cases including canonical-case input) CI: - release.yml: bump goreleaser/goreleaser-action to e24998b (v7.1.0)
9aebae5 to
5218b41
Compare
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.
Summary
Addresses all findings from the design quality review of the HTTP gateway.
ReadHeaderTimeout: 10s+IdleTimeout: 60sonhttp.Server— prevents slowloris and connection exhaustionServe()fans both gRPC and HTTP into a sharederrCh(2); first failure surfaces to the caller immediately with no goroutine leaksRegisterLedgerServiceHandlerFromEndpointnow usescontext.Background()so the loopback conn lives for the server's lifetime, not the caller's short-lived ctxgatewayDialTarget()rewrites0.0.0.0→127.0.0.1so gateway→gRPC traffic never traverses external interfaceserrors.Is(err, http.ErrServerClosed)in Serve goroutinehttp_listencomment now notes base64 encoding of bytes fields and restart requirementTestGatewayErrorMapping(NotFound → HTTP 404),TestGatewayTLS(self-signed cert loopback dial)Test plan