| name | security-review |
| description | Security review for Rust systems code. Covers memory safety, buffer handling, unsafe code, input validation, resource exhaustion, and supply chain security. Use when this capability is needed. |
| metadata | {"author":"evilbit-labs"} |
Security Review (Rust Systems Code)
When to Activate
- Adding new buffer access or offset resolution code
- Handling untrusted input (magic files, target files)
- Adding or reviewing dependencies
- Modifying parser or evaluator logic
- Before releases or PRs with security-sensitive changes
Security Checklist
1. Memory Safety
Bounds-Checked Buffer Access
let byte = buffer[offset];
let byte = buffer.get(offset).ok_or(MagicError::OutOfBounds)?;
let slice = buffer.get(start..end).ok_or(MagicError::OutOfBounds)?;
Safe String Operations
let rest = &input[2..];
let rest = input.strip_prefix("0x").unwrap_or(input);
Verification Steps
2. Unsafe Code Policy
Zero Tolerance
#![forbid(unsafe_code)]
Verification Steps
3. Integer Safety
Overflow Protection
let offset = base + adjustment;
let offset = base.checked_add(adjustment)
.ok_or(MagicError::InvalidOffset { offset: format!("{} + {}", base, adjustment) })?;
let score = base_score.saturating_add(bonus);
Verification Steps
4. Input Validation (Magic Files)
Parser Robustness
fn parse_magic_line(line: &str) -> Result<MagicRule, ParseError> {
}
Verification Steps
5. Input Validation (Target Files)
File Buffer Safety
let fb = FileBuffer::open(path)?;
if fb.len() > MAX_FILE_SIZE {
return Err(MagicError::FileTooLarge);
}
let data = fb.get(offset, length)?;
Verification Steps
6. Resource Exhaustion Prevention
CPU Limits
let config = EvaluationConfig {
timeout: Duration::from_secs(5),
max_rules: 10_000,
..Default::default()
};
Memory Limits
const MAX_MATCHES: usize = 100;
if matches.len() >= MAX_MATCHES {
break;
}
Verification Steps
7. Supply Chain Security
Dependency Audit
cargo audit
cargo deny check
cargo tree --depth 2
Verification Steps
8. Error Information Leakage
Safe Error Messages
Err(format!("Failed to read {}: {}", full_path, system_error))
Err(MagicError::IoError(std::io::Error::new(
std::io::ErrorKind::NotFound,
"magic file not found"
)))
Verification Steps
9. CLI Argument Safety
Path Handling
#[derive(Parser)]
struct Args {
file: PathBuf,
#[arg(long)]
magic_file: Option<PathBuf>,
}
Verification Steps
Pre-Release Security Checklist
References
Converted and distributed by TomeVault — claim your Tome and manage your conversions.