|
|
|
|
|
|
| const SECURITY_CONFIG = {
|
| MAX_PATH_LENGTH: 260,
|
| ALLOWED_EXTENSIONS: [
|
| '.js', '.ts', '.jsx', '.tsx', '.mjs', '.cjs',
|
| '.json', '.md', '.txt', '.yaml', '.yml',
|
| '.html', '.css', '.scss', '.sass', '.less'
|
| ],
|
| FORBIDDEN_PATHS: [
|
| /^[A-Z]:\\Windows\\/i,
|
| /^[A-Z]:\\Program Files\\/i,
|
| /^\/etc\//,
|
| /^\/usr\/bin\//,
|
| /^\/System\//,
|
| /^\/bin\//,
|
| /^\/sbin\//
|
| ],
|
| MAX_FILE_SIZE: 50 * 1024 * 1024,
|
| REGEX_TIMEOUT: 10000,
|
| MAX_FILES_PER_SECOND: 100,
|
| ALLOW_SYMLINKS: false,
|
| MAX_SYMLINK_DEPTH: 3,
|
| ENABLE_REDOS_PROTECTION: true,
|
| MAX_PATTERN_EXECUTION_TIME: 1000
|
| };
|
|
|
|
|
| class SecurityError extends Error {
|
| constructor(message, filePath = null, errorCode = 'SEC_001') {
|
| super(message);
|
| this.name = 'SecurityError';
|
| this.filePath = filePath;
|
| this.errorCode = errorCode;
|
| this.timestamp = new Date().toISOString();
|
| }
|
| }
|
|
|
| class SymlinkError extends SecurityError {
|
| constructor(message, filePath = null, linkTarget = null) {
|
| super(message, filePath, 'SYM_001');
|
| this.name = 'SymlinkError';
|
| this.linkTarget = linkTarget;
|
| }
|
| }
|
|
|
| class PathValidationError extends SecurityError {
|
| constructor(message, filePath = null, reason = null) {
|
| super(message, filePath, 'PATH_001');
|
| this.name = 'PathValidationError';
|
| this.reason = reason;
|
| }
|
| }
|
|
|
| class ReDoSError extends SecurityError {
|
| constructor(message, pattern = null, filePath = null) {
|
| super(message, filePath, 'REDOS_001');
|
| this.name = 'ReDoSError';
|
| this.pattern = pattern;
|
| }
|
| }
|
|
|
| module.exports = {
|
| SECURITY_CONFIG,
|
| SecurityError,
|
| SymlinkError,
|
| PathValidationError,
|
| ReDoSError
|
| };
|
|
|