Security Testing with Fail Points
June 12, 2026 · View on GitHub
Overview
Bashkit uses fail-rs for fault injection security testing of error handling paths and resource limit enforcement. Fail points are disabled by default, zero runtime overhead when disabled.
cargo test --features failpoints security_ -- --test-threads=1
Available Fail Points
Resource Limits (limits.rs)
| Fail Point | Actions | Security Test Purpose |
|---|---|---|
limits::tick_command | skip_increment, force_overflow, corrupt_high | Test command limit bypass resistance |
limits::tick_loop | skip_check, reset_counter | Test loop limit bypass resistance |
limits::push_function | skip_check, corrupt_depth | Test recursion limit bypass resistance |
Filesystem (fs/memory.rs)
| Fail Point | Actions | Security Test Purpose |
|---|---|---|
fs::read_file | io_error, permission_denied, corrupt_data | Test read failure handling |
fs::write_file | io_error, disk_full, permission_denied, partial_write | Test write failure handling |
Interpreter (interpreter/mod.rs)
| Fail Point | Actions | Security Test Purpose |
|---|---|---|
interp::execute_command | panic, error, exit_nonzero | Test command execution failure handling |
Usage
In tests: fail::cfg("limits::tick_command", "return(skip_increment)") before,
fail::cfg("name", "off") after. Action syntax (return/panic/sleep/pause,
probability 10%, count 5*): see fail crate docs.
Security Test Categories
- Resource limit bypass: counter corruption, check skipping, overflow/underflow
- Filesystem failure: I/O errors, permission denied, disk full, partial writes, data corruption
- Interpreter failure: execution errors, panic recovery, unexpected exit codes
Adding New Fail Points
Add fail_point!("module::function", |action| ...) under
#[cfg(feature = "failpoints")] at the critical location, document it in this
spec, and add tests in tests/security_failpoint_tests.rs.
Best Practices
- Always clean up: Call
fail::cfg("name", "off")after tests. - Single-threaded tests: Use
--test-threads=1for fail point tests due to global state. - Document actions: List all supported actions in code comments and this spec.
- Test both paths: Test that fail points affect behavior AND that normal operation works without them.
JavaScript Security Tests
The JavaScript/TypeScript bindings have a dedicated security test suite at
crates/bashkit-js/__test__/security.spec.ts (run: cd crates/bashkit-js && pnpm test). White-box and black-box scenarios across 18 categories:
- Resource limit enforcement (TM-DOS)
- Output truncation (TM-DOS)
- Sandbox escape prevention (TM-ESC)
- VFS security — path traversal, file count, nesting, filename limits (TM-DOS, TM-INJ)
- Instance isolation (TM-ISO)
- Error message safety (TM-INT)
- TypeScript wrapper injection prevention (TM-INJ)
- Adversarial script inputs — null bytes, deep nesting, expansion bombs
- Unicode & encoding attacks (TM-UNI)
- Injection via constructor options (TM-INJ)
- Concurrency & cancellation (TM-DOS)
- Async API security
- BashTool metadata safety
- Bash feature abuse — traps, special variables, /dev/tcp
- Mounted files security
- Rapid instance creation/destruction
- Edge case inputs
- Async factory security
Related Files
crates/bashkit/tests/security_failpoint_tests.rs- Fail-point security testscrates/bashkit/tests/threat_model_tests.rs- Threat model tests (51 tests)crates/bashkit/tests/builtin_error_security_tests.rs- Builtin error security tests (39 tests, includes TM-INT-003)crates/bashkit-js/__test__/security.spec.ts- JavaScript security tests (90+ tests, 18 categories)crates/bashkit/src/limits.rs- Resource limit fail pointscrates/bashkit/src/fs/memory.rs- Filesystem fail pointscrates/bashkit/src/interpreter/mod.rs- Interpreter fail points, panic catchingcrates/bashkit/src/builtins/system.rs- Hardcoded system builtinsspecs/threat-model.md- Threat model specification