Fix: add explicit HTTP request timeout (default 30s)#9
Merged
Conversation
Previously, the aiohttp.ClientSession in make_p2p_service_client was constructed without a timeout, so callers silently inherited aiohttp's 5-minute total-timeout default. A hung or malicious P2P daemon could pin a client coroutine for 5 minutes per request. Add an http_timeout parameter (default 30s) and pass aiohttp.ClientTimeout(total=http_timeout) to the ClientSession.
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
Fixes security finding M3:
aiohttp.ClientSessioninmake_p2p_service_clientwas constructed without an explicittimeout=, so callers silently inherited aiohttp's 5-minute total-timeout default. A hung or malicious P2P daemon could pin a client coroutine for up to 5 minutes per request, enabling trivial resource exhaustion / liveness attacks against client services.Change
http_timeout: float = 30.0parameter tomake_p2p_service_client(seconds, total timeout — sane default for control-plane calls likeidentify/dial).timeout=aiohttp.ClientTimeout(total=http_timeout)to theClientSessionconstructor.Behavior change (heads-up for callers)
This is a default behavior change:
timeout=passed -> aiohttp's default ofClientTimeout(total=300)(5 minutes) applied.ClientTimeout(total=30)(30 seconds) applied.Callers that legitimately need longer HTTP calls can override at construction time:
To preserve the previous behavior exactly, pass
http_timeout=300.0.Out of scope
aio_pika/ RabbitMQ side — message-queue connections have their own heartbeat/timeout semantics and are handled separately.Test plan
make_p2p_service_client(...)still works with nohttp_timeoutargument (uses 30s).http_timeout=...is honored by the resultingClientSession.identify()/dial()to raiseasyncio.TimeoutError(oraiohttpequivalent) after ~30s instead of ~300s.