fix(weixin): clamp server-suggested long-poll timeout - #76184
Open
SebTardif wants to merge 1 commit into
Open
Conversation
iLink may return longpolling_timeout_ms after getUpdates; the value is fed into asyncio.wait_for for the next poll. Trust positive ints but clamp to MAX_LONG_POLL_TIMEOUT_MS so a huge or malicious suggestion cannot pin the poll task (and delay disconnect) unbounded. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Contributor
|
Thanks for the focused guard. Current The change is narrow, preserves valid positive hints below the ceiling, and the added tests cover the helper's clamp and invalid-hint behavior. Repository-wide search found no sibling consumer of Automated hermes-sweeper review. |
Open
1 task
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.
What does this PR do?
After each Weixin/iLink
getUpdatescall, the server may returnlongpolling_timeout_ms. Hermes stores that value and uses it as the nextasyncio.wait_forbudget for the long-poll.Previously any positive int was accepted with no upper bound. A huge or malicious suggestion (for example
10**12) pins_poll_loopfor an unbounded wall-clock wait and delays disconnect cancellation while the wait is in progress.This PR keeps trusting legitimate server suggestions (including values above the 35s default boot timeout) but clamps them to
MAX_LONG_POLL_TIMEOUT_MS(120s).Related Issue
No open issue tracked; found during a scoped security/hang audit of
gateway/platforms/weixin.py(audit finding F006).Type of Change
Changes Made
gateway/platforms/weixin.py: addMAX_LONG_POLL_TIMEOUT_MSand_apply_long_poll_timeout_hint(); use it in_poll_loopinstead of unbounded assignmenttests/gateway/test_weixin.py: unit tests for clamp, normal keep, and non-positive / non-int keep-current behaviorHow to Test
AttributeError/ missing clamp (or huge values accepted).10**12clamps toMAX_LONG_POLL_TIMEOUT_MS.Checklist
Code
fix(scope):, etc.)Documentation & Housekeeping
Origin
Unbounded assignment was introduced with native Weixin support in
5b63bf7f9a(2026-04-10, "feat(gateway): add native Weixin/WeChat support via iLink Bot API"). Later work (#35117) moved API waits ontoasyncio.wait_forbut did not cap the server-suggested long-poll budget.Related
fix(weixin): asyncio.wait_for timeout in _api_post/_api_get