File size: 2,199 Bytes
f462b1c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | # Shared Modules
This folder contains modules used by both main and renderer processes.
## Files
### security-core.js
Enterprise-grade security system with comprehensive protection.
## Features
### 1. Input Validation
- Path traversal detection
- Malicious pattern checking
- Length validation
### 2. Path Safety
- Forbidden directory protection (Windows, System, etc.)
- Whitelist validation
- Workspace folder support
### 3. Symlink Protection
- Symlink detection
- Circular reference prevention
- Depth limiting
### 4. File Validation
- Extension whitelist
- Size limits (min/max)
- Content verification
### 5. Integrity Verification
- SHA-256 hash calculation
- File tampering detection
- Cache management
### 6. Rate Limiting
- Operation throttling
- Time-window based limits
- Abuse prevention
### 7. ReDoS Protection
- Regex timeout enforcement
- Pattern execution monitoring
- Safe regex execution
## Usage
```javascript
import { SecurityManager } from './security-core.js';
const security = new SecurityManager({
MAX_FILE_SIZE: 10 * 1024 * 1024,
ALLOWED_EXTENSIONS: ['.js', '.ts', '.py'],
EXTRA_ALLOWED_DIRS: ['/path/to/allowed/dir']
});
// Validate and read file
const result = await security.secureReadFile(filePath);
// Get statistics
const stats = security.getSecurityStats();
// Export audit log
const log = security.exportSecurityLog();
```
## Custom Error Classes
- `SecurityError` - Base security error
- `PathTraversalError` - Path attack detected
- `SymlinkError` - Symlink violation
- `FileValidationError` - File validation failed
- `ReDoSError` - Regex timeout
- `RateLimitError` - Rate limit exceeded
## Configuration
All security settings are configurable:
```javascript
const SECURITY_CONFIG = {
MAX_PATH_LENGTH: 260,
MAX_FILE_SIZE: 10 * 1024 * 1024,
ALLOWED_EXTENSIONS: [...],
FORBIDDEN_PATHS: [...],
MAX_OPERATIONS_PER_MINUTE: 500,
// ... more settings
};
```
## Adding New Validations
1. Create validation method in SecurityManager class
2. Add to validateFile() pipeline
3. Add custom error class if needed
4. Update configuration
|