File size: 2,038 Bytes
4fea3ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Security Configuration and Protection Functions
// Based on enterprise-grade security patterns from emoji-cleaner.js

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, // 50MB
    REGEX_TIMEOUT: 10000,             // 10 seconds
    MAX_FILES_PER_SECOND: 100,
    ALLOW_SYMLINKS: false,
    MAX_SYMLINK_DEPTH: 3,
    ENABLE_REDOS_PROTECTION: true,
    MAX_PATTERN_EXECUTION_TIME: 1000  // 1 second
};

// Custom Error Classes
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
};