fix(security): truncate command in policy error message (closes #1941)
Summary
Truncate the full command string returned in error messages from validate_command_execution to prevent leaking potentially-sensitive command arguments in error responses.
Changes
- Reused existing
truncatedvariable (80 chars, Unicode-safe via.chars().take(80)) in theErr()return - Updated log line to use the same
truncatedvariable for consistency - No new imports needed β
floor_char_boundaryis still used elsewhere in the file
Checklist
- [x]
cargo checkpasses - [x]
cargo fmt --checkpasses
Summary by CodeRabbit
- Bug Fixes
- Consistent truncation of blocked commands in security messages: both warning logs and error responses now show the first 80 characters of a blocked command, yielding clearer and more uniform feedback to users. No external-facing APIs or signatures were changed.
No actionable comments were generated in the recent review. π
βΉοΈ Recent review info
βοΈ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c9fa3ede-b687-4d52-b50a-f9fb6969cb3a
π₯ Commits
Reviewing files that changed from the base of the PR and between cec6ebf2549d942a55dc83939958b129907b4c4a and b0a484e87218b8e43ec74c8a1d71468c3ef6346b.
π Files selected for processing (1)
src/openhuman/security/policy.rs
π§ Files skipped from review as they are similar to previous changes (1)
- src/openhuman/security/policy.rs
π Walkthrough
Walkthrough
The PR modifies SecurityPolicy::validate_command_execution to consistently truncate rejected commands to 80 Unicode characters for both warning logs and returned error messages, eliminating the prior inconsistency where warnings used floor_char_boundary truncation but errors included the full command text.
Changes
Security Policy Command Truncation Consistency
| Layer / File(s) | Summary |
|---|---|
Consistent command truncation in allowlist validation src/openhuman/security/policy.rs |
The allowlist-block error path now truncates the command to the first 80 Unicode scalar values for both the warning message and the Err response, replacing mixed truncation strategies that differed between log output and error messages. |
Estimated code review effort
π― 2 (Simple) | β±οΈ ~10 minutes
Possibly related issues
- tinyhumansai/openhuman#1941: Directly addresses the issue reporting that blocked commands were leaking full text in error messages by implementing the suggested truncation fix in
SecurityPolicy::validate_command_execution.
Possibly related PRs
- tinyhumansai/openhuman#1817: Also modifies
SecurityPolicy::validate_command_executionto truncate blocked commands to 80 characters for warning/error messages; this PR refines the truncation approach to use consistent Unicode-safe slicing across both message types.
Suggested reviewers
- graycyrus
Poem
π° A command flows through security's gate,
Now truncated with consistent fateβ
Eighty characters, clear and clean,
Both warning and error now aligned serene,
No secrets leak from policy's decree! π
π₯ Pre-merge checks | β 5
β Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title clearly and specifically describes the main change: truncating commands in security policy error messages to fix a potential information leak issue. |
| Docstring Coverage | β Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| 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. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
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.
Comment @coderabbitai help to get the list of available commands and usage tips.