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
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 errorPathTraversalError- Path attack detectedSymlinkError- Symlink violationFileValidationError- File validation failedReDoSError- Regex timeoutRateLimitError- Rate limit exceeded
Configuration
All security settings are configurable:
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
- Create validation method in SecurityManager class
- Add to validateFile() pipeline
- Add custom error class if needed
- Update configuration