1.2 KiB
1.2 KiB
L3a: L4 Whitelist Hook
Implement a production-grade L4 security whitelist hook.
Module: M3 Safety & Security
Est. Time: 60 min
Files: starter.py, solution.py
Objective
Block ALL bash commands except 10 safelisted patterns. This prevents the L3 marque break (agent writing and running scripts).
Concepts
- L4 whitelist (architectural security)
- Regex pattern matching
- Compound shell operator detection
- Defense in depth
Starter
cd course/labs/L3-whitelist-hook/
python starter.py
The starter has:
- A safelist patterns list (currently empty)
- A compound operators detector (currently empty)
- A whitelist check function (currently TODO)
- Test cases for both ALLOWED and BLOCKED commands
Solution
python solution.py
Key Design Rules
- Pin specific scripts:
^npm test$not^npm .*$ - Never pattern-match an interpreter:
^python .*$allows running any script - Block compound operators before regex
- Audit log all blocks
Test Cases
npm test → ALLOW
git status → ALLOW
rm -rf target/ → BLOCK
python cleanup.py → BLOCK (L3 marque break)
npm test && rm -rf / → BLOCK (compound operator)