chahuadev's picture
Upload 51 files
f462b1c verified

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 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:

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