openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

fix(security): truncate command in policy error message (closes #1941)

Open PranavAgarkar07 opened this issue 6 months ago β€’ 1 comments

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 truncated variable (80 chars, Unicode-safe via .chars().take(80)) in the Err() return
  • Updated log line to use the same truncated variable for consistency
  • No new imports needed β€” floor_char_boundary is still used elsewhere in the file

Checklist

  • [x] cargo check passes
  • [x] cargo fmt --check passes

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.

Review Change Stack

PranavAgarkar07 avatar May 16 '26 15:05 PranavAgarkar07

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_execution to 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.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 16 '26 15:05 coderabbitai[bot]