This document describes the security specifications for the TeaAgent codebase, including security requirements, threat model, and security controls implemented.
- Requirement: All shell command execution must use safe parsing
- Implementation: Use
shlex.split()instead ofshell=True - Files:
workspace_tools/_shell.py,cli/_handlers/_chat.py - Status: ✅ Implemented
- Requirement: All user inputs must be validated before processing
- Implementation:
- Regex pattern validation with error handling
- Line number bounds checking
- Path traversal prevention
- Symlink validation
- Files:
workspace_tools/_files.py - Status: ✅ Implemented
- Requirement: Use cryptographically secure random number generation
- Implementation: Use
secretsmodule instead ofrandom - Files:
context_bus.py,llm/_retry.py - Status: ✅ Implemented
- Requirement: Filter sensitive environment variables from subprocess environments
- Implementation: Use allowlist approach instead of blacklist
- Files:
workspace_tools/_shell.py - Status: ✅ Implemented
- Requirement: Use strong hashing for tokens with salt
- Implementation: PBKDF2 with random salt for new tokens
- Files:
surface_auth.py - Status: ✅ Implemented
- Requirement: Atomic file operations to prevent race conditions
- Implementation: Use temp files with atomic rename
- Files:
workspace_tools/_files.py - Status: ✅ Implemented
- Command Injection: Malicious commands injected via shell execution
- Path Traversal: Accessing files outside workspace via
..sequences - Symlink Attacks: Accessing files through symbolic links
- Race Conditions: TOCTOU attacks on file operations
- Information Disclosure: Leaking sensitive environment variables
- Weak Cryptography: Predictable random numbers or weak hashing
- Input Validation: All inputs validated before processing
- Safe Parsing: Use
shlex.split()for command parsing - Path Validation: Validate paths are within workspace root
- Symlink Checks: Block symlink access
- Atomic Operations: Use temp files for atomic writes
- Secure Random: Use
secretsmodule for cryptographic randomness - Environment Filtering: Allowlist approach for environment variables
- Strong Hashing: PBKDF2 with salt for token hashing
- Unit tests for all security fixes:
tests/test_security_fixes.py - Integration tests for command execution
- Fuzzing tests for input validation
- Penetration testing for common vulnerabilities
- L2 (default): Redacted payloads suitable for routine operator review.
- L3: Full payloads written without redaction and without encryption at rest. Do not enable L3 on shared or compliance-sensitive storage unless a future audit-encryption extra is enabled and reviewed.
| Backend | Isolation | Use when |
|---|---|---|
ChildProcessCodeModeBackend |
Fork + SAFE_BUILTINS + resource limits |
Trusted user inputs only (trusted_only=True, default) |
ContainerCodeModeBackend |
Docker with network isolation | Untrusted or multi-tenant workloads |
Setting ChildProcessCodeModeBackend(trusted_only=False) raises at execute time.
- Audit logging for all security-relevant operations
- Error logging for failed security checks
- Metrics for security violations prevented
- OWASP Top 10: Addresses injection, broken access control, security misconfiguration
- CWE: Addresses CWE-78 (OS Command Injection), CWE-20 (Improper Input Validation)
- Industry Standards: Follows secure coding best practices
- OWASP Command Injection Prevention Cheat Sheet
- Python Security Best Practices
- CWE Mitigation Strategies