"use strict";
/**
 * Shared Sink Patterns — Canonical list of dangerous sink patterns.
 *
 * Single source of truth for sink detection patterns used by:
 * - sink-matcher.ts (intra-file taint path matching)
 * - function-classifier.ts (exported function profiling)
 * - cross-file-taint.ts (cross-file taint analysis)
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SINK_PATTERNS = void 0;
exports.escapeRegex = escapeRegex;
// ============================================================================
// Canonical Sink Patterns
// ============================================================================
exports.SINK_PATTERNS = [
    // SQL injection
    { pattern: /\.query\s*\(/, sinkType: 'sql_query' },
    { pattern: /\.raw\s*\(/, sinkType: 'sql_query' },
    { pattern: /\.execute\s*\(/, sinkType: 'sql_query' },
    { pattern: /\bsequelize\.query\s*\(/, sinkType: 'sql_query' },
    { pattern: /\bknex\.raw\s*\(/, sinkType: 'sql_query' },
    { pattern: /\bcursor\.execute\s*\(/, sinkType: 'sql_query' },
    // Code execution
    { pattern: /\beval\s*\(/, sinkType: 'eval' },
    { pattern: /new\s+Function\s*\(/, sinkType: 'eval' },
    // Command execution (Node.js)
    { pattern: /\bexec\s*\(/, sinkType: 'exec' },
    { pattern: /\bexecSync\s*\(/, sinkType: 'exec' },
    { pattern: /\bspawn\s*\(/, sinkType: 'exec' },
    { pattern: /\bchild_process\./, sinkType: 'exec' },
    // Command execution (Python)
    { pattern: /\bsubprocess\.run\s*\(/, sinkType: 'command_exec' },
    { pattern: /\bsubprocess\.call\s*\(/, sinkType: 'command_exec' },
    { pattern: /\bsubprocess\.Popen\s*\(/, sinkType: 'command_exec' },
    { pattern: /\bos\.system\s*\(/, sinkType: 'command_exec' },
    { pattern: /\bos\.popen\s*\(/, sinkType: 'command_exec' },
    // XSS / DOM injection
    { pattern: /\.innerHTML\s*=/, sinkType: 'inner_html' },
    { pattern: /\bdangerouslySetInnerHTML\b/, sinkType: 'inner_html' },
    { pattern: /\bdocument\.write\s*\(/, sinkType: 'inner_html' },
    // HTTP requests (SSRF)
    { pattern: /\bfetch\s*\(/, sinkType: 'http_request' },
    { pattern: /\baxios\.\w+\s*\(/, sinkType: 'http_request' },
    { pattern: /\bgot\s*\(/, sinkType: 'http_request' },
    { pattern: /\bhttp\.request\s*\(/, sinkType: 'http_request' },
    { pattern: /\bhttps\.request\s*\(/, sinkType: 'http_request' },
    { pattern: /\brequests\.\w+\s*\(/, sinkType: 'http_request' },
    // Redirects
    { pattern: /\bres\.redirect\s*\(/, sinkType: 'redirect' },
    { pattern: /\bResponse\.redirect\s*\(/, sinkType: 'redirect' },
    { pattern: /\blocation\.href\s*=/, sinkType: 'redirect' },
    { pattern: /\bwindow\.location\s*=/, sinkType: 'redirect' },
    // File system
    { pattern: /\bfs\.writeFile\b/, sinkType: 'file_write' },
    { pattern: /\bfs\.writeFileSync\b/, sinkType: 'file_write' },
    { pattern: /\bcreateWriteStream\s*\(/, sinkType: 'file_write' },
    { pattern: /\bfs\.readFile\b/, sinkType: 'path_access' },
    { pattern: /\bfs\.readFileSync\b/, sinkType: 'path_access' },
    { pattern: /\bpath\.join\s*\(/, sinkType: 'path_access' },
    { pattern: /\bpath\.resolve\s*\(/, sinkType: 'path_access' },
    // Template rendering
    { pattern: /\bpug\.compile\s*\(/, sinkType: 'template_render' },
    { pattern: /\bejs\.render\s*\(/, sinkType: 'template_render' },
    { pattern: /\bhandlebars\.compile\s*\(/, sinkType: 'template_render' },
    // Regex construction (ReDoS)
    { pattern: /new\s+RegExp\s*\(/, sinkType: 'regex_constructor' },
    { pattern: /\bre\.compile\s*\(/, sinkType: 'regex_constructor' },
    // Dynamic imports
    { pattern: /\bimport\s*\(/, sinkType: 'dynamic_import' },
    { pattern: /\brequire\s*\(/, sinkType: 'dynamic_import' },
    // Deserialization
    { pattern: /\bJSON\.parse\s*\(/, sinkType: 'deserialization' },
    { pattern: /\bpickle\.load\s*\(/, sinkType: 'deserialization' },
    { pattern: /\bpickle\.loads\s*\(/, sinkType: 'deserialization' },
    { pattern: /\byaml\.load\s*\(/, sinkType: 'deserialization' },
    { pattern: /\byaml\.unsafe_load\s*\(/, sinkType: 'deserialization' },
];
// ============================================================================
// Shared Utilities
// ============================================================================
/**
 * Escape special regex characters in a string for use in RegExp constructors.
 */
function escapeRegex(str) {
    return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
//# sourceMappingURL=sink-patterns.js.map