Skip to content

Commit 348c025

Browse files
committed
feat: implement enhanced security middleware with YAML configuration
- Add SecurityMiddleware class with YAML-based configuration support - Implement three-tier configuration hierarchy (Enterprise → Global → Project → Custom) - Add ASK action support for prompting users instead of just blocking - Create EnhancedRooIgnoreController that integrates with SecurityMiddleware - Support both gitignore-style and regex patterns for file matching - Add comprehensive type definitions for security configuration - Include example YAML configurations for different use cases - Add documentation for the new security middleware features - Implement tests for core functionality Fixes #7912
1 parent 33fe6fb commit 348c025

12 files changed

+2999
-0
lines changed

docs/README-SECURITY.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Security Middleware - Quick Start Guide
2+
3+
## What's New?
4+
5+
RooCode now supports enhanced security controls beyond `.rooignore`:
6+
7+
- **ASK Action**: Prompt for approval instead of just blocking
8+
- **YAML Configuration**: More flexible than gitignore patterns
9+
- **Three-Tier Hierarchy**: Enterprise → Global → Project → Custom
10+
- **Regex Support**: Complex pattern matching
11+
- **Command Protection**: Block terminal commands too
12+
13+
## Quick Setup
14+
15+
### 1. Enable Security Middleware
16+
17+
Create `.roo-security.yaml` in your project root:
18+
19+
```yaml
20+
version: "1.0"
21+
security:
22+
enabled: true
23+
rules:
24+
- pattern: "**/.env*"
25+
action: ASK
26+
description: "Environment files may contain secrets"
27+
askMessage: "Allow access to ${file}?"
28+
29+
- pattern: "**/*.key"
30+
action: BLOCK
31+
description: "Private keys are blocked"
32+
```
33+
34+
### 2. Global User Settings
35+
36+
Create `~/.roo-security.yaml` for personal defaults:
37+
38+
```yaml
39+
version: "1.0"
40+
security:
41+
enabled: true
42+
rules:
43+
- pattern: "**/.ssh/**"
44+
action: BLOCK
45+
description: "SSH directory protection"
46+
```
47+
48+
### 3. Custom Overrides
49+
50+
Create `.roo-security-custom.yaml` for personal project overrides:
51+
52+
```yaml
53+
version: "1.0"
54+
security:
55+
enabled: true
56+
inheritRules: true
57+
rules:
58+
- pattern: ".env.local"
59+
action: ALLOW
60+
priority: 200
61+
description: "Allow local development env"
62+
```
63+
64+
## Actions Explained
65+
66+
| Action | Description | Use Case |
67+
| --------- | ------------------------ | --------------------------------------- |
68+
| **BLOCK** | Deny access completely | Sensitive files, production configs |
69+
| **ASK** | Prompt user for approval | Files that might be needed occasionally |
70+
| **ALLOW** | Explicitly allow access | Override inherited blocks |
71+
72+
## Pattern Examples
73+
74+
### Gitignore-style
75+
76+
- `*.log` - All log files
77+
- `**/.env*` - Any .env file
78+
- `config/*.json` - JSON files in config/
79+
80+
### Regular Expressions
81+
82+
- `/.*password.*/` - Files containing "password"
83+
- `/.*\d{3}-\d{2}-\d{4}.*/` - SSN-like patterns
84+
85+
## Priority System
86+
87+
Higher numbers win when multiple patterns match:
88+
89+
- **1000+**: Enterprise/compliance (unchangeable)
90+
- **100-999**: Important security rules
91+
- **50-99**: Standard rules
92+
- **1-49**: Suggestions
93+
94+
## Command Protection
95+
96+
Protect against terminal access:
97+
98+
```yaml
99+
- pattern: "**/.env"
100+
action: BLOCK
101+
applyToCommands: true # Also blocks: cat .env
102+
```
103+
104+
## Inheritance Control
105+
106+
```yaml
107+
security:
108+
inheritRules: false # Don't inherit from parent configs
109+
```
110+
111+
## Backward Compatibility
112+
113+
- `.rooignore` still works exactly as before
114+
- `.rooignore` blocks take precedence over security rules
115+
- You can use both systems together
116+
117+
## Examples
118+
119+
### Protect API Keys
120+
121+
```yaml
122+
- pattern: "**/api_keys.*"
123+
action: BLOCK
124+
priority: 100
125+
description: "API keys must not be accessed"
126+
```
127+
128+
### Ask for Database Access
129+
130+
```yaml
131+
- pattern: "**/*.db"
132+
action: ASK
133+
priority: 80
134+
askMessage: "Database file ${file} - allow access?"
135+
```
136+
137+
### Allow Test Files
138+
139+
```yaml
140+
- pattern: "test/**"
141+
action: ALLOW
142+
priority: 50
143+
description: "Test files are safe"
144+
```
145+
146+
## Configuration Files
147+
148+
| File | Location | Purpose | Priority |
149+
| --------------------------- | -------------- | --------------------- | --------- |
150+
| `.roo-security.yaml` | Project root | Project rules | Medium |
151+
| `.roo-security-custom.yaml` | Project root | Personal overrides | High |
152+
| `~/.roo-security.yaml` | Home directory | User defaults | Low |
153+
| Enterprise config | Cloud/managed | Organization policies | Highest\* |
154+
155+
\*Enterprise rules with `inheritRules: false` cannot be overridden
156+
157+
## Troubleshooting
158+
159+
### Rules not working?
160+
161+
1. Check `enabled: true` is set
162+
2. Verify pattern syntax
163+
3. Check priority values
164+
4. Enable debug mode
165+
166+
### ASK prompts not appearing?
167+
168+
- Ensure VS Code extension is updated
169+
- Check notification settings
170+
- Verify pattern matches
171+
172+
## See Also
173+
174+
- [Full Documentation](./security-middleware.md)
175+
- [Example Configurations](../examples/security-configs/)
176+
- [Migration Guide](#migration-from-rooignore)
177+
178+
## Support
179+
180+
For issues or questions:
181+
182+
- GitHub Issues: [RooCodeInc/Roo-Code](https://github.com/RooCodeInc/Roo-Code/issues)
183+
- Documentation: [Security Middleware Guide](./security-middleware.md)

0 commit comments

Comments
 (0)