Skip to content

fix(channel): add limit check to qqbot response - #21859

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
flyingwhit:fix(channel)/qqbot-request-no-limit
Nov 2, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
flyingwhit:fix(channel)/qqbot-request-no-limit

Conversation

@flyingwhit

Copy link
Copy Markdown
Contributor

Fix

Cap QQBot's outbound response read at 1 MiB and truncate the response body in the error message to 200 characters.

@flyingwhit
flyingwhit requested a review from buua436 November 2, 2026 08:46
@flyingwhit flyingwhit added the ci Continue Integration label Nov 2, 2026
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b731f7fc-4035-4006-bf2b-19041e882f52
Commits

Reviewing files that changed from the base of the PR and between c6c9df0 and a844a19.

Files selected for processing: 1
  • internal/channels/qqbot.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The QQBot requestJSON function now reads at most 1 MiB from each response body. For HTTP errors, it includes no more than 200 characters of response text in the reported error.

Changes: QQBot response handling

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

Suggested reviewers: buua436

Merge Risk: Minimal · up to a844a

No actionable merge-blocking risk is established for this change.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: adding response size limits to QQBot channel handling.
Description check Passed 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 purp…
Docstring Coverage Passed 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. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.

Share

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

@buua436 buua436 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wangq8
wangq8 merged commit f1a2fa5 into infiniflow:main Nov 2, 2026
11 checks passed

@Harsh23Kashyap Harsh23Kashyap left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants