Repository navigation
fix(channel): add limit check to qqbot response - #21859
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Bound response reads and error text internal/channels/qqbot.go |
requestJSON caps response-body reads at 1 MiB and truncates response text in HTTP errors to 200 characters. HTTP errors still occur for status codes of 400 or higher. |
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Possibly related PRs
- infiniflow/ragflow#21769: Caps upstream HTTP response reads in four tools.
- infiniflow/ragflow#21565: Limits WhatsApp response reads and removes gateway response bodies from HTTP error messages.
- infiniflow/ragflow#21702: Bounds Rest API response reads before JSON decoding.
Suggested reviewers: buua436
Merge Risk: 
Minimal · up to a844a
-
No actionable merge-blocking risk is established for this change.
Pre-merge checks: 
5
-
Full details: Description check
-
Explanation
The description clearly states the change and its limits. It uses a different heading from the required "### Summary" heading and does not provide background context, but it still covers the main purpose of the pull request.
Full details: Docstring Coverage
-
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the bytes in flight
One MiB keeps the stream in sight
Long error text grows short and neat
Two hundred chars, then paws retreat
QQBot replies stay trim and light
Harsh23Kashyap
left a comment
There was a problem hiding this comment.
Verified at head a844a19 (base main) by reading internal/channels/qqbot.go at that exact tree.
Before this change, requestJSON did an unbounded io.ReadAll on the QQBot gateway response, so a misbehaving or hostile endpoint could stream unlimited bytes into process memory, and on a non-2xx status the entire body landed in the returned error. The LimitReader cap at 1 MiB plus the %.200s truncation in the error path closes both. io is already imported (line 27) and %.200s applies cleanly to the []byte payload. Truncation is safe here because the payload is only parsed on success below; an over-limit success body simply fails JSON parsing as malformed, which is the right failure mode for a gateway response that large.
Small, correct hardening. LGTM.
|
Follow-up with runtime proof. Ran the verbatim requestJSON from this head against a local test server: with a 5 MiB error body the new code puts exactly 200 body bytes in the returned error, while the pre-PR version (negative control) puts the full 5 MiB in it. A 3 MiB malformed success body is cut by the 1 MiB cap and fails JSON parsing as expected. 3/3 targeted tests pass. |
Fix
Cap QQBot's outbound response read at 1 MiB and truncate the response body in the error message to 200 characters.