---
name: security-reviewer-6b88c6a43cc4
description: Audit memory safety and security in unsafe code blocks, buffer handling, and security-sensitive operations
---

# Security Reviewer

Review unsafe code and security-sensitive operations in this secret scanning engine.

## When to Use

- After modifying any `unsafe` block
- When adding new parsing or decoding logic
- Before merging changes to `src/async_io/` or buffer handling code
- When implementing new transform chains

## Critical Areas in This Codebase

### High-Risk Files
- `src/runtime.rs` - Buffer pool with unsafe pointer operations
- `src/async_io/` - Platform-specific async I/O with raw pointers
- `src/engine/scratch.rs` - Scratch memory management
- `src/engine/stream_decode.rs` - Streaming decoder state machine
- `src/engine/buffer_scan.rs` - Buffer scanning with offsets

## Security Checklist

### Memory Safety
- [ ] All pointer arithmetic checked for overflow
- [ ] Slice bounds validated before `get_unchecked`
- [ ] Lifetimes correctly constrain returned references
- [ ] No use-after-free in buffer pool operations
- [ ] Alignment requirements satisfied for casts

### Buffer Handling
- [ ] No buffer overflows in write operations
- [ ] Length checks before copying
- [ ] Integer overflow checks on size calculations
- [ ] Proper handling of truncated reads

### Unsafe Block Audit
For each `unsafe` block:
- [ ] Documented safety invariants (why this is safe)
- [ ] Minimal scope (only unsafe operations inside)
- [ ] Kani proof or extensive testing coverage
- [ ] No undefined behavior paths

### Input Validation
- [ ] Untrusted input length-limited
- [ ] Malformed input cannot cause panics
- [ ] No amplification attacks (small input -> huge allocation)
- [ ] Transform chains handle edge cases (empty, max-size)

## Output Format

```markdown
## Security Review: [file/module]

### Unsafe Block Audit

| Location | Purpose | Safety Justification | Status |
|----------|---------|---------------------|--------|
| line:XX | ptr arithmetic | bounds checked at line:YY | SAFE |
| line:XX | transmute | MISSING JUSTIFICATION | REVIEW |

### Findings

| Severity | Issue | Location | CWE |
|----------|-------|----------|-----|
| CRITICAL | Unchecked bounds | line:XX | CWE-125 |
| HIGH | Integer overflow | line:XX | CWE-190 |

### Recommendations

1. **[Issue]**: Add bounds check before unsafe access
   ```rust
   // Before (unsafe)
   // After (safe)
   ```

### Verification

- [ ] Add Kani proof for memory safety
- [ ] Add fuzz target for this code path
- [ ] Add property test for invariant
```

## Related Resources

- `docs/kani-verification.md` - Existing Kani proofs
- `/test-strategy` - Choose appropriate verification approach
- `/run-fuzz` - Run fuzz targets for security testing


---
Source attribution: ahrav
Original project: https://github.com/ahrav/scratch-scanner-rs/blob/3fb8740fb576a9859c84b7a5a08f3bbae06a9f05/.claude/skills/security-reviewer/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 ahrav

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ahrav
Original project: https://github.com/ahrav/scratch-scanner-rs/blob/3fb8740fb576a9859c84b7a5a08f3bbae06a9f05/.claude/skills/security-reviewer/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Backend Developer, QA / Test Engineer, Security Engineer
Specialties: Backend
Tools: Tool not specified
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 1a8694a203af4389c01b9df406348c2804548b99834fd0e508133e77a4da457d
