Commit 7673aa6
fix: Address PR #21 review feedback - improve safety
This commit addresses the two high-priority issues identified in PR review:
## 1. Fixed .unwrap() on Path Conversion (status.rs:163)
**Issue:** Using `.unwrap()` on `path.to_str()` panics on non-UTF-8 paths.
**Fix:** Replaced with proper error handling:
```rust
let settings_path_str = settings_path
.to_str()
.ok_or_else(|| {
CatalystError::InvalidPath(format!(
"Settings path contains non-UTF-8 characters: {:?}",
settings_path
))
})?;
```
Now gracefully handles non-UTF-8 paths with a descriptive error message.
## 2. Added Binary Name Validation (status.rs:534-544)
**Issue:** Potential template injection in `fix_hook_wrapper` where binary_name
is extracted from wrapper_name and used in template substitution without validation.
**Fix:** Added strict validation that only allows safe characters:
```rust
// Validate binary name to prevent potential injection
// Only allow alphanumeric characters, hyphens, and underscores
if !binary_name
.chars()
.all(|c| c.is_alphanumeric() || c == '-' || c == '_')
{
return Err(CatalystError::InvalidConfig(format!(
"Invalid binary name '{}': must contain only alphanumeric, hyphens, underscores",
binary_name
)));
}
```
This prevents injection of shell metacharacters like `;`, `$`, `|`, `..`, etc.
## Test Coverage
Added comprehensive test `test_fix_hook_wrapper_validates_binary_name`:
- ✅ Valid names accepted: `skill-activation-prompt`, `file-change-tracker`
- ❌ Invalid names rejected: `test;rm-rf`, `test$command`, `test/../etc/passwd`
All tests passing: **36 in catalyst-cli + 28 in catalyst-core = 64 total**
## Security Impact
These fixes eliminate two potential security issues:
1. **Path handling**: No more panics on non-UTF-8 paths
2. **Injection prevention**: Malicious binary names cannot inject commands
The changes maintain backward compatibility while improving robustness.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 59bbc9d commit 7673aa6
1 file changed
Lines changed: 53 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
164 | 171 | | |
165 | 172 | | |
166 | 173 | | |
| |||
522 | 529 | | |
523 | 530 | | |
524 | 531 | | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
525 | 544 | | |
526 | 545 | | |
527 | 546 | | |
| |||
535 | 554 | | |
536 | 555 | | |
537 | 556 | | |
538 | | - | |
| 557 | + | |
539 | 558 | | |
540 | 559 | | |
541 | 560 | | |
| |||
631 | 650 | | |
632 | 651 | | |
633 | 652 | | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
634 | 685 | | |
0 commit comments