fix(cli): reject non-success HTTP responses - #903
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesHTTP response handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/genie-ctl/src/main.rs`:
- Around line 2894-2899: Sanitize the server-provided detail in the non-success
response handling before passing it to anyhow::bail!. Update the response.body
processing in the visible status-check block to remove carriage returns and ANSI
escape sequences, while preserving the existing trimming, empty-detail fallback,
and HTTP status formatting behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 115d3ec4-91fc-4e7a-b5c8-c211cd4e3ce0
📒 Files selected for processing (1)
crates/genie-ctl/src/main.rs
| if !(200..300).contains(&response.status) { | ||
| let detail = response.body.trim().replace('\n', " "); | ||
| if detail.is_empty() { | ||
| anyhow::bail!("HTTP {}", response.status); | ||
| } | ||
| anyhow::bail!("HTTP {}: {}", response.status, detail); |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Sanitize server-provided error text before formatting it.
Replacing only \n leaves embedded \r and ANSI escape sequences intact. A responding server can therefore forge or manipulate terminal/log output through the CLI diagnostic.
Proposed fix
- let detail = response.body.trim().replace('\n', " ");
+ let detail = response
+ .body
+ .chars()
+ .map(|ch| if ch.is_control() { ' ' } else { ch })
+ .collect::<String>()
+ .split_whitespace()
+ .collect::<Vec<_>>()
+ .join(" ");📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if !(200..300).contains(&response.status) { | |
| let detail = response.body.trim().replace('\n', " "); | |
| if detail.is_empty() { | |
| anyhow::bail!("HTTP {}", response.status); | |
| } | |
| anyhow::bail!("HTTP {}: {}", response.status, detail); | |
| if !(200..300).contains(&response.status) { | |
| let detail = response | |
| .body | |
| .chars() | |
| .map(|ch| if ch.is_control() { ' ' } else { ch }) | |
| .collect::<String>() | |
| .split_whitespace() | |
| .collect::<Vec<_>>() | |
| .join(" "); | |
| if detail.is_empty() { | |
| anyhow::bail!("HTTP {}", response.status); | |
| } | |
| anyhow::bail!("HTTP {}: {}", response.status, detail); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/genie-ctl/src/main.rs` around lines 2894 - 2899, Sanitize the
server-provided detail in the non-success response handling before passing it to
anyhow::bail!. Update the response.body processing in the visible status-check
block to remove carriage returns and ANSI escape sequences, while preserving the
existing trimming, empty-detail fallback, and HTTP status formatting behavior.
Summary
The
genie-ctlHTTP helper discarded the HTTP status line and returned everyresponse body as
Ok. A403,404, or500therefore looked like asuccessful request to callers. For example, an authentication error from the
conversation-history endpoint could be parsed as an empty result and displayed
as “no messages yet,” while diagnostics could report a service as up merely
because it returned an HTTP response.
Parse CLI responses with the shared bounded HTTP parser and reject non-2xx
statuses with the status code and server-provided error detail.
Changes
genie_common::http::read_response.Real Behavior Proof
below.
Tested profile / hardware:
jetsonraspberry_piportable_sbclaptopmacWhat I ran
What I observed
git diff --checkpasses.cargo.Test Plan
cargo fmt --all -- --check.cargo test -p genie-ctl http_get.200response returns its body unchanged.403response returns an error containingHTTP 403and theserver response detail.
404and500responses cause CLI commands to exit with errors.Notes for Reviewers
CLI callers.
Summary by CodeRabbit