secure-scan 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +564 -0
- package/dist/ai/aiAnalyzer.d.ts +99 -0
- package/dist/ai/aiAnalyzer.d.ts.map +1 -0
- package/dist/ai/aiAnalyzer.js +669 -0
- package/dist/ai/aiAnalyzer.js.map +1 -0
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +21 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/analyzers/base/baseAnalyzer.d.ts +44 -0
- package/dist/analyzers/base/baseAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/base/baseAnalyzer.js +53 -0
- package/dist/analyzers/base/baseAnalyzer.js.map +1 -0
- package/dist/analyzers/base/index.d.ts +5 -0
- package/dist/analyzers/base/index.d.ts.map +1 -0
- package/dist/analyzers/base/index.js +21 -0
- package/dist/analyzers/base/index.js.map +1 -0
- package/dist/analyzers/c-cpp/cppAnalyzer.d.ts +60 -0
- package/dist/analyzers/c-cpp/cppAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/c-cpp/cppAnalyzer.js +218 -0
- package/dist/analyzers/c-cpp/cppAnalyzer.js.map +1 -0
- package/dist/analyzers/c-cpp/index.d.ts +5 -0
- package/dist/analyzers/c-cpp/index.d.ts.map +1 -0
- package/dist/analyzers/c-cpp/index.js +21 -0
- package/dist/analyzers/c-cpp/index.js.map +1 -0
- package/dist/analyzers/core/engine/index.d.ts +5 -0
- package/dist/analyzers/core/engine/index.d.ts.map +1 -0
- package/dist/analyzers/core/engine/index.js +21 -0
- package/dist/analyzers/core/engine/index.js.map +1 -0
- package/dist/analyzers/core/engine/ruleEngine.d.ts +46 -0
- package/dist/analyzers/core/engine/ruleEngine.d.ts.map +1 -0
- package/dist/analyzers/core/engine/ruleEngine.js +173 -0
- package/dist/analyzers/core/engine/ruleEngine.js.map +1 -0
- package/dist/analyzers/core/index.d.ts +8 -0
- package/dist/analyzers/core/index.d.ts.map +1 -0
- package/dist/analyzers/core/index.js +24 -0
- package/dist/analyzers/core/index.js.map +1 -0
- package/dist/analyzers/core/scanner/fileScanner.d.ts +31 -0
- package/dist/analyzers/core/scanner/fileScanner.d.ts.map +1 -0
- package/dist/analyzers/core/scanner/fileScanner.js +199 -0
- package/dist/analyzers/core/scanner/fileScanner.js.map +1 -0
- package/dist/analyzers/core/scanner/index.d.ts +5 -0
- package/dist/analyzers/core/scanner/index.d.ts.map +1 -0
- package/dist/analyzers/core/scanner/index.js +21 -0
- package/dist/analyzers/core/scanner/index.js.map +1 -0
- package/dist/analyzers/core/scoring/index.d.ts +5 -0
- package/dist/analyzers/core/scoring/index.d.ts.map +1 -0
- package/dist/analyzers/core/scoring/index.js +21 -0
- package/dist/analyzers/core/scoring/index.js.map +1 -0
- package/dist/analyzers/core/scoring/riskScoring.d.ts +49 -0
- package/dist/analyzers/core/scoring/riskScoring.d.ts.map +1 -0
- package/dist/analyzers/core/scoring/riskScoring.js +180 -0
- package/dist/analyzers/core/scoring/riskScoring.js.map +1 -0
- package/dist/analyzers/core/securityScanner.d.ts +47 -0
- package/dist/analyzers/core/securityScanner.d.ts.map +1 -0
- package/dist/analyzers/core/securityScanner.js +298 -0
- package/dist/analyzers/core/securityScanner.js.map +1 -0
- package/dist/analyzers/csharp/csharpAnalyzer.d.ts +64 -0
- package/dist/analyzers/csharp/csharpAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/csharp/csharpAnalyzer.js +232 -0
- package/dist/analyzers/csharp/csharpAnalyzer.js.map +1 -0
- package/dist/analyzers/csharp/index.d.ts +5 -0
- package/dist/analyzers/csharp/index.d.ts.map +1 -0
- package/dist/analyzers/csharp/index.js +21 -0
- package/dist/analyzers/csharp/index.js.map +1 -0
- package/dist/analyzers/iac/iacAnalyzer.d.ts +36 -0
- package/dist/analyzers/iac/iacAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/iac/iacAnalyzer.js +182 -0
- package/dist/analyzers/iac/iacAnalyzer.js.map +1 -0
- package/dist/analyzers/iac/index.d.ts +5 -0
- package/dist/analyzers/iac/index.d.ts.map +1 -0
- package/dist/analyzers/iac/index.js +21 -0
- package/dist/analyzers/iac/index.js.map +1 -0
- package/dist/analyzers/index.d.ts +30 -0
- package/dist/analyzers/index.d.ts.map +1 -0
- package/dist/analyzers/index.js +80 -0
- package/dist/analyzers/index.js.map +1 -0
- package/dist/analyzers/java/index.d.ts +5 -0
- package/dist/analyzers/java/index.d.ts.map +1 -0
- package/dist/analyzers/java/index.js +21 -0
- package/dist/analyzers/java/index.js.map +1 -0
- package/dist/analyzers/java/javaAnalyzer.d.ts +64 -0
- package/dist/analyzers/java/javaAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/java/javaAnalyzer.js +224 -0
- package/dist/analyzers/java/javaAnalyzer.js.map +1 -0
- package/dist/analyzers/javascript/astUtils.d.ts +170 -0
- package/dist/analyzers/javascript/astUtils.d.ts.map +1 -0
- package/dist/analyzers/javascript/astUtils.js +700 -0
- package/dist/analyzers/javascript/astUtils.js.map +1 -0
- package/dist/analyzers/javascript/index.d.ts +18 -0
- package/dist/analyzers/javascript/index.d.ts.map +1 -0
- package/dist/analyzers/javascript/index.js +50 -0
- package/dist/analyzers/javascript/index.js.map +1 -0
- package/dist/analyzers/javascript/javascriptAnalyzer.d.ts +111 -0
- package/dist/analyzers/javascript/javascriptAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/javascript/javascriptAnalyzer.js +860 -0
- package/dist/analyzers/javascript/javascriptAnalyzer.js.map +1 -0
- package/dist/analyzers/javascript/malwareDetector.d.ts +102 -0
- package/dist/analyzers/javascript/malwareDetector.d.ts.map +1 -0
- package/dist/analyzers/javascript/malwareDetector.js +616 -0
- package/dist/analyzers/javascript/malwareDetector.js.map +1 -0
- package/dist/analyzers/javascript/packageJsonAnalyzer.d.ts +87 -0
- package/dist/analyzers/javascript/packageJsonAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/javascript/packageJsonAnalyzer.js +553 -0
- package/dist/analyzers/javascript/packageJsonAnalyzer.js.map +1 -0
- package/dist/analyzers/javascript/taintAnalyzer.d.ts +120 -0
- package/dist/analyzers/javascript/taintAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/javascript/taintAnalyzer.js +526 -0
- package/dist/analyzers/javascript/taintAnalyzer.js.map +1 -0
- package/dist/analyzers/php/index.d.ts +5 -0
- package/dist/analyzers/php/index.d.ts.map +1 -0
- package/dist/analyzers/php/index.js +21 -0
- package/dist/analyzers/php/index.js.map +1 -0
- package/dist/analyzers/php/phpAnalyzer.d.ts +56 -0
- package/dist/analyzers/php/phpAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/php/phpAnalyzer.js +202 -0
- package/dist/analyzers/php/phpAnalyzer.js.map +1 -0
- package/dist/analyzers/python/index.d.ts +5 -0
- package/dist/analyzers/python/index.d.ts.map +1 -0
- package/dist/analyzers/python/index.js +21 -0
- package/dist/analyzers/python/index.js.map +1 -0
- package/dist/analyzers/python/pythonAnalyzer.d.ts +64 -0
- package/dist/analyzers/python/pythonAnalyzer.d.ts.map +1 -0
- package/dist/analyzers/python/pythonAnalyzer.js +226 -0
- package/dist/analyzers/python/pythonAnalyzer.js.map +1 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +281 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/engine/index.d.ts +5 -0
- package/dist/core/engine/index.d.ts.map +1 -0
- package/dist/core/engine/index.js +21 -0
- package/dist/core/engine/index.js.map +1 -0
- package/dist/core/engine/ruleEngine.d.ts +46 -0
- package/dist/core/engine/ruleEngine.d.ts.map +1 -0
- package/dist/core/engine/ruleEngine.js +173 -0
- package/dist/core/engine/ruleEngine.js.map +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +24 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/scanner/fileScanner.d.ts +31 -0
- package/dist/core/scanner/fileScanner.d.ts.map +1 -0
- package/dist/core/scanner/fileScanner.js +199 -0
- package/dist/core/scanner/fileScanner.js.map +1 -0
- package/dist/core/scanner/index.d.ts +5 -0
- package/dist/core/scanner/index.d.ts.map +1 -0
- package/dist/core/scanner/index.js +21 -0
- package/dist/core/scanner/index.js.map +1 -0
- package/dist/core/scoring/index.d.ts +5 -0
- package/dist/core/scoring/index.d.ts.map +1 -0
- package/dist/core/scoring/index.js +21 -0
- package/dist/core/scoring/index.js.map +1 -0
- package/dist/core/scoring/riskScoring.d.ts +49 -0
- package/dist/core/scoring/riskScoring.d.ts.map +1 -0
- package/dist/core/scoring/riskScoring.js +180 -0
- package/dist/core/scoring/riskScoring.js.map +1 -0
- package/dist/core/securityScanner.d.ts +47 -0
- package/dist/core/securityScanner.d.ts.map +1 -0
- package/dist/core/securityScanner.js +298 -0
- package/dist/core/securityScanner.js.map +1 -0
- package/dist/dependencies/aiDependencyAnalyzer.d.ts +96 -0
- package/dist/dependencies/aiDependencyAnalyzer.d.ts.map +1 -0
- package/dist/dependencies/aiDependencyAnalyzer.js +435 -0
- package/dist/dependencies/aiDependencyAnalyzer.js.map +1 -0
- package/dist/dependencies/database/cveDatabase.d.ts +32 -0
- package/dist/dependencies/database/cveDatabase.d.ts.map +1 -0
- package/dist/dependencies/database/cveDatabase.js +393 -0
- package/dist/dependencies/database/cveDatabase.js.map +1 -0
- package/dist/dependencies/database/index.d.ts +6 -0
- package/dist/dependencies/database/index.d.ts.map +1 -0
- package/dist/dependencies/database/index.js +22 -0
- package/dist/dependencies/database/index.js.map +1 -0
- package/dist/dependencies/database/maliciousPackages.d.ts +43 -0
- package/dist/dependencies/database/maliciousPackages.d.ts.map +1 -0
- package/dist/dependencies/database/maliciousPackages.js +279 -0
- package/dist/dependencies/database/maliciousPackages.js.map +1 -0
- package/dist/dependencies/dependencyAnalyzer.d.ts +74 -0
- package/dist/dependencies/dependencyAnalyzer.d.ts.map +1 -0
- package/dist/dependencies/dependencyAnalyzer.js +349 -0
- package/dist/dependencies/dependencyAnalyzer.js.map +1 -0
- package/dist/dependencies/detectors/index.d.ts +7 -0
- package/dist/dependencies/detectors/index.d.ts.map +1 -0
- package/dist/dependencies/detectors/index.js +28 -0
- package/dist/dependencies/detectors/index.js.map +1 -0
- package/dist/dependencies/detectors/securityStandards.d.ts +15 -0
- package/dist/dependencies/detectors/securityStandards.d.ts.map +1 -0
- package/dist/dependencies/detectors/securityStandards.js +178 -0
- package/dist/dependencies/detectors/securityStandards.js.map +1 -0
- package/dist/dependencies/detectors/vulnerabilityDetector.d.ts +53 -0
- package/dist/dependencies/detectors/vulnerabilityDetector.d.ts.map +1 -0
- package/dist/dependencies/detectors/vulnerabilityDetector.js +289 -0
- package/dist/dependencies/detectors/vulnerabilityDetector.js.map +1 -0
- package/dist/dependencies/index.d.ts +14 -0
- package/dist/dependencies/index.d.ts.map +1 -0
- package/dist/dependencies/index.js +43 -0
- package/dist/dependencies/index.js.map +1 -0
- package/dist/dependencies/installed/index.d.ts +8 -0
- package/dist/dependencies/installed/index.d.ts.map +1 -0
- package/dist/dependencies/installed/index.js +24 -0
- package/dist/dependencies/installed/index.js.map +1 -0
- package/dist/dependencies/installed/installedScanner.d.ts +91 -0
- package/dist/dependencies/installed/installedScanner.d.ts.map +1 -0
- package/dist/dependencies/installed/installedScanner.js +766 -0
- package/dist/dependencies/installed/installedScanner.js.map +1 -0
- package/dist/dependencies/installed/malwarePatterns.d.ts +32 -0
- package/dist/dependencies/installed/malwarePatterns.d.ts.map +1 -0
- package/dist/dependencies/installed/malwarePatterns.js +480 -0
- package/dist/dependencies/installed/malwarePatterns.js.map +1 -0
- package/dist/dependencies/installed/types.d.ts +274 -0
- package/dist/dependencies/installed/types.d.ts.map +1 -0
- package/dist/dependencies/installed/types.js +7 -0
- package/dist/dependencies/installed/types.js.map +1 -0
- package/dist/dependencies/parsers/base/baseParser.d.ts +44 -0
- package/dist/dependencies/parsers/base/baseParser.d.ts.map +1 -0
- package/dist/dependencies/parsers/base/baseParser.js +80 -0
- package/dist/dependencies/parsers/base/baseParser.js.map +1 -0
- package/dist/dependencies/parsers/base/index.d.ts +6 -0
- package/dist/dependencies/parsers/base/index.d.ts.map +1 -0
- package/dist/dependencies/parsers/base/index.js +27 -0
- package/dist/dependencies/parsers/base/index.js.map +1 -0
- package/dist/dependencies/parsers/cpp/cppParser.d.ts +36 -0
- package/dist/dependencies/parsers/cpp/cppParser.d.ts.map +1 -0
- package/dist/dependencies/parsers/cpp/cppParser.js +196 -0
- package/dist/dependencies/parsers/cpp/cppParser.js.map +1 -0
- package/dist/dependencies/parsers/cpp/index.d.ts +6 -0
- package/dist/dependencies/parsers/cpp/index.d.ts.map +1 -0
- package/dist/dependencies/parsers/cpp/index.js +27 -0
- package/dist/dependencies/parsers/cpp/index.js.map +1 -0
- package/dist/dependencies/parsers/csharp/csharpParser.d.ts +32 -0
- package/dist/dependencies/parsers/csharp/csharpParser.d.ts.map +1 -0
- package/dist/dependencies/parsers/csharp/csharpParser.js +125 -0
- package/dist/dependencies/parsers/csharp/csharpParser.js.map +1 -0
- package/dist/dependencies/parsers/csharp/index.d.ts +6 -0
- package/dist/dependencies/parsers/csharp/index.d.ts.map +1 -0
- package/dist/dependencies/parsers/csharp/index.js +27 -0
- package/dist/dependencies/parsers/csharp/index.js.map +1 -0
- package/dist/dependencies/parsers/index.d.ts +24 -0
- package/dist/dependencies/parsers/index.d.ts.map +1 -0
- package/dist/dependencies/parsers/index.js +69 -0
- package/dist/dependencies/parsers/index.js.map +1 -0
- package/dist/dependencies/parsers/java/index.d.ts +6 -0
- package/dist/dependencies/parsers/java/index.d.ts.map +1 -0
- package/dist/dependencies/parsers/java/index.js +27 -0
- package/dist/dependencies/parsers/java/index.js.map +1 -0
- package/dist/dependencies/parsers/java/javaParser.d.ts +32 -0
- package/dist/dependencies/parsers/java/javaParser.d.ts.map +1 -0
- package/dist/dependencies/parsers/java/javaParser.js +168 -0
- package/dist/dependencies/parsers/java/javaParser.js.map +1 -0
- package/dist/dependencies/parsers/javascript/index.d.ts +6 -0
- package/dist/dependencies/parsers/javascript/index.d.ts.map +1 -0
- package/dist/dependencies/parsers/javascript/index.js +27 -0
- package/dist/dependencies/parsers/javascript/index.js.map +1 -0
- package/dist/dependencies/parsers/javascript/javascriptParser.d.ts +55 -0
- package/dist/dependencies/parsers/javascript/javascriptParser.d.ts.map +1 -0
- package/dist/dependencies/parsers/javascript/javascriptParser.js +266 -0
- package/dist/dependencies/parsers/javascript/javascriptParser.js.map +1 -0
- package/dist/dependencies/parsers/php/index.d.ts +6 -0
- package/dist/dependencies/parsers/php/index.d.ts.map +1 -0
- package/dist/dependencies/parsers/php/index.js +27 -0
- package/dist/dependencies/parsers/php/index.js.map +1 -0
- package/dist/dependencies/parsers/php/phpParser.d.ts +35 -0
- package/dist/dependencies/parsers/php/phpParser.d.ts.map +1 -0
- package/dist/dependencies/parsers/php/phpParser.js +162 -0
- package/dist/dependencies/parsers/php/phpParser.js.map +1 -0
- package/dist/dependencies/parsers/python/index.d.ts +6 -0
- package/dist/dependencies/parsers/python/index.d.ts.map +1 -0
- package/dist/dependencies/parsers/python/index.js +27 -0
- package/dist/dependencies/parsers/python/index.js.map +1 -0
- package/dist/dependencies/parsers/python/pythonParser.d.ts +60 -0
- package/dist/dependencies/parsers/python/pythonParser.d.ts.map +1 -0
- package/dist/dependencies/parsers/python/pythonParser.js +336 -0
- package/dist/dependencies/parsers/python/pythonParser.js.map +1 -0
- package/dist/dependencies/types.d.ts +280 -0
- package/dist/dependencies/types.d.ts.map +1 -0
- package/dist/dependencies/types.js +59 -0
- package/dist/dependencies/types.js.map +1 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +18 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/translations.d.ts +55 -0
- package/dist/i18n/translations.d.ts.map +1 -0
- package/dist/i18n/translations.js +119 -0
- package/dist/i18n/translations.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/reports/dependencyReportGenerator.d.ts +20 -0
- package/dist/reports/dependencyReportGenerator.d.ts.map +1 -0
- package/dist/reports/dependencyReportGenerator.js +690 -0
- package/dist/reports/dependencyReportGenerator.js.map +1 -0
- package/dist/reports/htmlReportGenerator.d.ts +43 -0
- package/dist/reports/htmlReportGenerator.d.ts.map +1 -0
- package/dist/reports/htmlReportGenerator.js +793 -0
- package/dist/reports/htmlReportGenerator.js.map +1 -0
- package/dist/reports/index.d.ts +7 -0
- package/dist/reports/index.d.ts.map +1 -0
- package/dist/reports/index.js +23 -0
- package/dist/reports/index.js.map +1 -0
- package/dist/reports/installedDepsReportGenerator.d.ts +14 -0
- package/dist/reports/installedDepsReportGenerator.d.ts.map +1 -0
- package/dist/reports/installedDepsReportGenerator.js +872 -0
- package/dist/reports/installedDepsReportGenerator.js.map +1 -0
- package/dist/rules/index.d.ts +31 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +95 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/malware/categories/backdoors.d.ts +12 -0
- package/dist/rules/malware/categories/backdoors.d.ts.map +1 -0
- package/dist/rules/malware/categories/backdoors.js +163 -0
- package/dist/rules/malware/categories/backdoors.js.map +1 -0
- package/dist/rules/malware/categories/cryptominers.d.ts +13 -0
- package/dist/rules/malware/categories/cryptominers.d.ts.map +1 -0
- package/dist/rules/malware/categories/cryptominers.js +415 -0
- package/dist/rules/malware/categories/cryptominers.js.map +1 -0
- package/dist/rules/malware/categories/exfiltration.d.ts +20 -0
- package/dist/rules/malware/categories/exfiltration.d.ts.map +1 -0
- package/dist/rules/malware/categories/exfiltration.js +658 -0
- package/dist/rules/malware/categories/exfiltration.js.map +1 -0
- package/dist/rules/malware/categories/keyloggers.d.ts +19 -0
- package/dist/rules/malware/categories/keyloggers.d.ts.map +1 -0
- package/dist/rules/malware/categories/keyloggers.js +763 -0
- package/dist/rules/malware/categories/keyloggers.js.map +1 -0
- package/dist/rules/malware/categories/loaders.d.ts +20 -0
- package/dist/rules/malware/categories/loaders.d.ts.map +1 -0
- package/dist/rules/malware/categories/loaders.js +702 -0
- package/dist/rules/malware/categories/loaders.js.map +1 -0
- package/dist/rules/malware/categories/network.d.ts +19 -0
- package/dist/rules/malware/categories/network.d.ts.map +1 -0
- package/dist/rules/malware/categories/network.js +622 -0
- package/dist/rules/malware/categories/network.js.map +1 -0
- package/dist/rules/malware/categories/obfuscation.d.ts +22 -0
- package/dist/rules/malware/categories/obfuscation.d.ts.map +1 -0
- package/dist/rules/malware/categories/obfuscation.js +766 -0
- package/dist/rules/malware/categories/obfuscation.js.map +1 -0
- package/dist/rules/malware/constants/index.d.ts +281 -0
- package/dist/rules/malware/constants/index.d.ts.map +1 -0
- package/dist/rules/malware/constants/index.js +327 -0
- package/dist/rules/malware/constants/index.js.map +1 -0
- package/dist/rules/malware/engine/index.d.ts +178 -0
- package/dist/rules/malware/engine/index.d.ts.map +1 -0
- package/dist/rules/malware/engine/index.js +552 -0
- package/dist/rules/malware/engine/index.js.map +1 -0
- package/dist/rules/malware/index.d.ts +205 -0
- package/dist/rules/malware/index.d.ts.map +1 -0
- package/dist/rules/malware/index.js +837 -0
- package/dist/rules/malware/index.js.map +1 -0
- package/dist/rules/malware/scoring/index.d.ts +84 -0
- package/dist/rules/malware/scoring/index.d.ts.map +1 -0
- package/dist/rules/malware/scoring/index.js +441 -0
- package/dist/rules/malware/scoring/index.js.map +1 -0
- package/dist/rules/malware/types/index.d.ts +616 -0
- package/dist/rules/malware/types/index.d.ts.map +1 -0
- package/dist/rules/malware/types/index.js +155 -0
- package/dist/rules/malware/types/index.js.map +1 -0
- package/dist/rules/malware/utils/index.d.ts +117 -0
- package/dist/rules/malware/utils/index.d.ts.map +1 -0
- package/dist/rules/malware/utils/index.js +514 -0
- package/dist/rules/malware/utils/index.js.map +1 -0
- package/dist/rules/standards.d.ts +26 -0
- package/dist/rules/standards.d.ts.map +1 -0
- package/dist/rules/standards.js +352 -0
- package/dist/rules/standards.js.map +1 -0
- package/dist/rules/vulnerabilities/constants/index.d.ts +835 -0
- package/dist/rules/vulnerabilities/constants/index.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/constants/index.js +544 -0
- package/dist/rules/vulnerabilities/constants/index.js.map +1 -0
- package/dist/rules/vulnerabilities/engine/index.d.ts +145 -0
- package/dist/rules/vulnerabilities/engine/index.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/engine/index.js +581 -0
- package/dist/rules/vulnerabilities/engine/index.js.map +1 -0
- package/dist/rules/vulnerabilities/index.d.ts +148 -0
- package/dist/rules/vulnerabilities/index.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/index.js +252 -0
- package/dist/rules/vulnerabilities/index.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/authentication.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/authentication.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/authentication.js +419 -0
- package/dist/rules/vulnerabilities/rules/authentication.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/commandInjection.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/commandInjection.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/commandInjection.js +300 -0
- package/dist/rules/vulnerabilities/rules/commandInjection.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/csrf.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/csrf.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/csrf.js +261 -0
- package/dist/rules/vulnerabilities/rules/csrf.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/deserialization.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/deserialization.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/deserialization.js +336 -0
- package/dist/rules/vulnerabilities/rules/deserialization.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/fileUpload.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/fileUpload.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/fileUpload.js +325 -0
- package/dist/rules/vulnerabilities/rules/fileUpload.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/hardcodedSecrets.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/hardcodedSecrets.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/hardcodedSecrets.js +446 -0
- package/dist/rules/vulnerabilities/rules/hardcodedSecrets.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/index.d.ts +17 -0
- package/dist/rules/vulnerabilities/rules/index.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/index.js +47 -0
- package/dist/rules/vulnerabilities/rules/index.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/pathTraversal.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/pathTraversal.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/pathTraversal.js +351 -0
- package/dist/rules/vulnerabilities/rules/pathTraversal.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/prototypePollution.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/prototypePollution.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/prototypePollution.js +272 -0
- package/dist/rules/vulnerabilities/rules/prototypePollution.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/securityMisconfiguration.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/securityMisconfiguration.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/securityMisconfiguration.js +438 -0
- package/dist/rules/vulnerabilities/rules/securityMisconfiguration.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/sqlInjection.d.ts +12 -0
- package/dist/rules/vulnerabilities/rules/sqlInjection.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/sqlInjection.js +636 -0
- package/dist/rules/vulnerabilities/rules/sqlInjection.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/ssrf.d.ts +8 -0
- package/dist/rules/vulnerabilities/rules/ssrf.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/ssrf.js +401 -0
- package/dist/rules/vulnerabilities/rules/ssrf.js.map +1 -0
- package/dist/rules/vulnerabilities/rules/xss.d.ts +11 -0
- package/dist/rules/vulnerabilities/rules/xss.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/rules/xss.js +724 -0
- package/dist/rules/vulnerabilities/rules/xss.js.map +1 -0
- package/dist/rules/vulnerabilities/scoring/index.d.ts +80 -0
- package/dist/rules/vulnerabilities/scoring/index.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/scoring/index.js +414 -0
- package/dist/rules/vulnerabilities/scoring/index.js.map +1 -0
- package/dist/rules/vulnerabilities/types/index.d.ts +830 -0
- package/dist/rules/vulnerabilities/types/index.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/types/index.js +164 -0
- package/dist/rules/vulnerabilities/types/index.js.map +1 -0
- package/dist/rules/vulnerabilities/utils/index.d.ts +206 -0
- package/dist/rules/vulnerabilities/utils/index.d.ts.map +1 -0
- package/dist/rules/vulnerabilities/utils/index.js +615 -0
- package/dist/rules/vulnerabilities/utils/index.js.map +1 -0
- package/dist/types/index.d.ts +359 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +61 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +82 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +326 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +40 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +139 -0
- package/dist/utils/logger.js.map +1 -0
- package/docs/ARCHITECTURE.md +320 -0
- package/docs/V1.2.1-IA_Performances.md +116 -0
- package/docs/images/WIN_Defender.png +0 -0
- package/package.json +68 -0
- package/secure-scan.config.json +134 -0
- package/secure-scan.sln +29 -0
- package/src/ai/aiAnalyzer.ts +714 -0
- package/src/ai/index.ts +5 -0
- package/src/analyzers/base/baseAnalyzer.ts +66 -0
- package/src/analyzers/base/index.ts +5 -0
- package/src/analyzers/c-cpp/cppAnalyzer.ts +308 -0
- package/src/analyzers/c-cpp/index.ts +5 -0
- package/src/analyzers/core/engine/index.ts +5 -0
- package/src/analyzers/core/engine/ruleEngine.ts +221 -0
- package/src/analyzers/core/index.ts +8 -0
- package/src/analyzers/core/scanner/fileScanner.ts +204 -0
- package/src/analyzers/core/scanner/index.ts +5 -0
- package/src/analyzers/core/scoring/index.ts +5 -0
- package/src/analyzers/core/scoring/riskScoring.ts +198 -0
- package/src/analyzers/core/securityScanner.ts +321 -0
- package/src/analyzers/csharp/csharpAnalyzer.ts +328 -0
- package/src/analyzers/csharp/index.ts +5 -0
- package/src/analyzers/iac/iacAnalyzer.ts +318 -0
- package/src/analyzers/iac/index.ts +5 -0
- package/src/analyzers/index.ts +67 -0
- package/src/analyzers/java/index.ts +5 -0
- package/src/analyzers/java/javaAnalyzer.ts +320 -0
- package/src/analyzers/javascript/PROMPT_JS_ANALYZER.md +267 -0
- package/src/analyzers/javascript/astUtils.ts +789 -0
- package/src/analyzers/javascript/index.ts +50 -0
- package/src/analyzers/javascript/javascriptAnalyzer.ts +984 -0
- package/src/analyzers/javascript/malwareDetector.ts +697 -0
- package/src/analyzers/javascript/packageJsonAnalyzer.ts +626 -0
- package/src/analyzers/javascript/taintAnalyzer.ts +630 -0
- package/src/analyzers/php/index.ts +5 -0
- package/src/analyzers/php/phpAnalyzer.ts +280 -0
- package/src/analyzers/python/index.ts +5 -0
- package/src/analyzers/python/pythonAnalyzer.ts +319 -0
- package/src/cli/index.ts +276 -0
- package/src/dependencies/aiDependencyAnalyzer.ts +496 -0
- package/src/dependencies/database/cveDatabase.ts +426 -0
- package/src/dependencies/database/index.ts +6 -0
- package/src/dependencies/database/maliciousPackages.ts +286 -0
- package/src/dependencies/dependencyAnalyzer.ts +394 -0
- package/src/dependencies/detectors/index.ts +7 -0
- package/src/dependencies/detectors/securityStandards.ts +200 -0
- package/src/dependencies/detectors/vulnerabilityDetector.ts +343 -0
- package/src/dependencies/index.ts +27 -0
- package/src/dependencies/installed/index.ts +8 -0
- package/src/dependencies/installed/installedScanner.ts +821 -0
- package/src/dependencies/installed/malwarePatterns.ts +492 -0
- package/src/dependencies/installed/types.ts +287 -0
- package/src/dependencies/parsers/base/baseParser.ts +108 -0
- package/src/dependencies/parsers/base/index.ts +6 -0
- package/src/dependencies/parsers/cpp/cppParser.ts +245 -0
- package/src/dependencies/parsers/cpp/index.ts +6 -0
- package/src/dependencies/parsers/csharp/csharpParser.ts +151 -0
- package/src/dependencies/parsers/csharp/index.ts +6 -0
- package/src/dependencies/parsers/index.ts +56 -0
- package/src/dependencies/parsers/java/index.ts +6 -0
- package/src/dependencies/parsers/java/javaParser.ts +203 -0
- package/src/dependencies/parsers/javascript/index.ts +6 -0
- package/src/dependencies/parsers/javascript/javascriptParser.ts +362 -0
- package/src/dependencies/parsers/php/index.ts +6 -0
- package/src/dependencies/parsers/php/phpParser.ts +208 -0
- package/src/dependencies/parsers/python/index.ts +6 -0
- package/src/dependencies/parsers/python/pythonParser.ts +437 -0
- package/src/dependencies/types.ts +330 -0
- package/src/i18n/index.ts +1 -0
- package/src/i18n/translations.ts +194 -0
- package/src/index.ts +16 -0
- package/src/reports/dependencyReportGenerator.ts +717 -0
- package/src/reports/htmlReportGenerator.ts +781 -0
- package/src/reports/index.ts +7 -0
- package/src/reports/installedDepsReportGenerator.ts +899 -0
- package/src/rules/index.ts +58 -0
- package/src/rules/malware/INFO.md +287 -0
- package/src/rules/malware/categories/backdoors.ts +174 -0
- package/src/rules/malware/categories/cryptominers.ts +434 -0
- package/src/rules/malware/categories/exfiltration.ts +677 -0
- package/src/rules/malware/categories/keyloggers.ts +780 -0
- package/src/rules/malware/categories/loaders.ts +721 -0
- package/src/rules/malware/categories/network.ts +639 -0
- package/src/rules/malware/categories/obfuscation.ts +788 -0
- package/src/rules/malware/constants/index.ts +358 -0
- package/src/rules/malware/engine/index.ts +758 -0
- package/src/rules/malware/index.ts +928 -0
- package/src/rules/malware/scoring/index.ts +549 -0
- package/src/rules/malware/types/index.ts +752 -0
- package/src/rules/malware/utils/index.ts +643 -0
- package/src/rules/standards.ts +372 -0
- package/src/rules/vulnerabilities/PROMPT_VULNERABILITIES.md +226 -0
- package/src/rules/vulnerabilities/constants/index.ts +625 -0
- package/src/rules/vulnerabilities/engine/index.ts +831 -0
- package/src/rules/vulnerabilities/index.ts +312 -0
- package/src/rules/vulnerabilities/rules/authentication.ts +426 -0
- package/src/rules/vulnerabilities/rules/commandInjection.ts +307 -0
- package/src/rules/vulnerabilities/rules/csrf.ts +268 -0
- package/src/rules/vulnerabilities/rules/deserialization.ts +343 -0
- package/src/rules/vulnerabilities/rules/fileUpload.ts +332 -0
- package/src/rules/vulnerabilities/rules/hardcodedSecrets.ts +453 -0
- package/src/rules/vulnerabilities/rules/index.ts +17 -0
- package/src/rules/vulnerabilities/rules/pathTraversal.ts +358 -0
- package/src/rules/vulnerabilities/rules/prototypePollution.ts +279 -0
- package/src/rules/vulnerabilities/rules/securityMisconfiguration.ts +445 -0
- package/src/rules/vulnerabilities/rules/sqlInjection.ts +669 -0
- package/src/rules/vulnerabilities/rules/ssrf.ts +408 -0
- package/src/rules/vulnerabilities/rules/xss.ts +753 -0
- package/src/rules/vulnerabilities/scoring/index.ts +543 -0
- package/src/rules/vulnerabilities/types/index.ts +1004 -0
- package/src/rules/vulnerabilities/utils/index.ts +709 -0
- package/src/types/index.ts +391 -0
- package/src/utils/index.ts +306 -0
- package/src/utils/logger.ts +150 -0
- package/test-installed-scanner.ts +136 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Vulnerability Rule Engine - Core Detection Engine
|
|
3
|
+
* @module rules/vulnerabilities/engine
|
|
4
|
+
*
|
|
5
|
+
* Orchestrates vulnerability detection across all rule categories:
|
|
6
|
+
* - Multi-pattern matching with timeout protection
|
|
7
|
+
* - Taint analysis integration
|
|
8
|
+
* - AST-aware analysis
|
|
9
|
+
* - Dynamic scoring
|
|
10
|
+
* - Rule correlation
|
|
11
|
+
* - Finding aggregation and deduplication
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
VulnerabilityRule,
|
|
16
|
+
VulnerabilityFinding,
|
|
17
|
+
VulnerabilityPattern,
|
|
18
|
+
VulnerabilityScore,
|
|
19
|
+
AnalysisContext,
|
|
20
|
+
AnalysisOptions,
|
|
21
|
+
IVulnerabilityRuleEngine,
|
|
22
|
+
IPatternMatcher,
|
|
23
|
+
PatternMatch,
|
|
24
|
+
PatternType,
|
|
25
|
+
VulnerabilitySeverity,
|
|
26
|
+
ConfidenceLevel,
|
|
27
|
+
SourceLocation,
|
|
28
|
+
SupportedLanguage,
|
|
29
|
+
RegexPattern,
|
|
30
|
+
TaintFlow,
|
|
31
|
+
DataFlowTrace,
|
|
32
|
+
SecurityStandards
|
|
33
|
+
} from '../types';
|
|
34
|
+
|
|
35
|
+
import {
|
|
36
|
+
safeRegexMatch,
|
|
37
|
+
safeRegexMatchAsync,
|
|
38
|
+
extractSnippet,
|
|
39
|
+
formatSnippetWithLineNumbers,
|
|
40
|
+
normalizeCode,
|
|
41
|
+
generateFindingId,
|
|
42
|
+
isTestFile,
|
|
43
|
+
isVendorCode,
|
|
44
|
+
getLineNumber,
|
|
45
|
+
getColumnNumber,
|
|
46
|
+
findTaintSources,
|
|
47
|
+
findTaintSinks,
|
|
48
|
+
findSanitizers,
|
|
49
|
+
adjustConfidenceForTaintFlow
|
|
50
|
+
} from '../utils';
|
|
51
|
+
|
|
52
|
+
import { VulnerabilityScoreCalculator } from '../scoring';
|
|
53
|
+
import { LIMITS } from '../constants';
|
|
54
|
+
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// PATTERN MATCHER IMPLEMENTATION
|
|
57
|
+
// ============================================================================
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Pattern matcher with timeout protection
|
|
61
|
+
*/
|
|
62
|
+
export class PatternMatcher implements IPatternMatcher {
|
|
63
|
+
private timeoutMs: number;
|
|
64
|
+
private maxMatches: number;
|
|
65
|
+
|
|
66
|
+
constructor(options?: { timeoutMs?: number; maxMatches?: number }) {
|
|
67
|
+
this.timeoutMs = options?.timeoutMs ?? LIMITS.REGEX_TIMEOUT;
|
|
68
|
+
this.maxMatches = options?.maxMatches ?? LIMITS.MAX_MATCHES_PER_PATTERN;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Match patterns against content
|
|
73
|
+
*/
|
|
74
|
+
match(
|
|
75
|
+
content: string,
|
|
76
|
+
patterns: VulnerabilityPattern[],
|
|
77
|
+
language: SupportedLanguage
|
|
78
|
+
): PatternMatch[] {
|
|
79
|
+
const allMatches: PatternMatch[] = [];
|
|
80
|
+
|
|
81
|
+
for (const pattern of patterns) {
|
|
82
|
+
// Check language compatibility
|
|
83
|
+
if (pattern.languages && !pattern.languages.includes(language)) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const matches = this.matchSinglePattern(pattern, content, language);
|
|
88
|
+
allMatches.push(...matches);
|
|
89
|
+
|
|
90
|
+
if (allMatches.length >= this.maxMatches) {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return allMatches;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Match with timeout protection
|
|
100
|
+
*/
|
|
101
|
+
async matchWithTimeout(
|
|
102
|
+
content: string,
|
|
103
|
+
patterns: VulnerabilityPattern[],
|
|
104
|
+
language: SupportedLanguage,
|
|
105
|
+
timeout: number
|
|
106
|
+
): Promise<PatternMatch[]> {
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
const timeoutId = setTimeout(() => {
|
|
109
|
+
resolve([]);
|
|
110
|
+
}, timeout);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const results = this.match(content, patterns, language);
|
|
114
|
+
clearTimeout(timeoutId);
|
|
115
|
+
resolve(results);
|
|
116
|
+
} catch {
|
|
117
|
+
clearTimeout(timeoutId);
|
|
118
|
+
resolve([]);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Match a single pattern against code
|
|
125
|
+
*/
|
|
126
|
+
private matchSinglePattern(
|
|
127
|
+
pattern: VulnerabilityPattern,
|
|
128
|
+
code: string,
|
|
129
|
+
language: SupportedLanguage
|
|
130
|
+
): PatternMatch[] {
|
|
131
|
+
try {
|
|
132
|
+
switch (pattern.type) {
|
|
133
|
+
case PatternType.REGEX:
|
|
134
|
+
return safeRegexMatch(code, pattern as RegexPattern);
|
|
135
|
+
|
|
136
|
+
case PatternType.LITERAL:
|
|
137
|
+
return this.matchLiteralPattern(pattern, code);
|
|
138
|
+
|
|
139
|
+
case PatternType.AST:
|
|
140
|
+
// AST patterns require external AST parser
|
|
141
|
+
return [];
|
|
142
|
+
|
|
143
|
+
case PatternType.TAINT:
|
|
144
|
+
// Taint patterns are handled separately
|
|
145
|
+
return [];
|
|
146
|
+
|
|
147
|
+
case PatternType.SEMANTIC:
|
|
148
|
+
// Semantic patterns require deeper analysis
|
|
149
|
+
return [];
|
|
150
|
+
|
|
151
|
+
case PatternType.CFG:
|
|
152
|
+
// CFG patterns require control flow analysis
|
|
153
|
+
return [];
|
|
154
|
+
|
|
155
|
+
default:
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error(`Pattern matching error for ${pattern.patternId}:`, error);
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Match literal string pattern
|
|
166
|
+
*/
|
|
167
|
+
private matchLiteralPattern(
|
|
168
|
+
pattern: VulnerabilityPattern,
|
|
169
|
+
code: string
|
|
170
|
+
): PatternMatch[] {
|
|
171
|
+
const matches: PatternMatch[] = [];
|
|
172
|
+
|
|
173
|
+
if (pattern.type !== PatternType.LITERAL) return matches;
|
|
174
|
+
|
|
175
|
+
const literalPattern = pattern as { type: PatternType.LITERAL; value: string; caseSensitive?: boolean };
|
|
176
|
+
const searchString = literalPattern.value || '';
|
|
177
|
+
const searchCode = literalPattern.caseSensitive === false ? code.toLowerCase() : code;
|
|
178
|
+
const searchFor = literalPattern.caseSensitive === false ? searchString.toLowerCase() : searchString;
|
|
179
|
+
|
|
180
|
+
let index = 0;
|
|
181
|
+
|
|
182
|
+
while (index < searchCode.length && matches.length < this.maxMatches) {
|
|
183
|
+
index = searchCode.indexOf(searchFor, index);
|
|
184
|
+
if (index === -1) break;
|
|
185
|
+
|
|
186
|
+
const line = getLineNumber(code, index);
|
|
187
|
+
const column = getColumnNumber(code, index);
|
|
188
|
+
|
|
189
|
+
matches.push({
|
|
190
|
+
pattern,
|
|
191
|
+
matchedText: code.substring(index, index + searchString.length),
|
|
192
|
+
location: {
|
|
193
|
+
filePath: '',
|
|
194
|
+
startLine: line,
|
|
195
|
+
endLine: line,
|
|
196
|
+
startColumn: column,
|
|
197
|
+
endColumn: column + searchString.length
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
index += searchString.length;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return matches;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ============================================================================
|
|
209
|
+
// SIMPLE TAINT ANALYZER
|
|
210
|
+
// ============================================================================
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Simple taint analyzer for detecting data flows
|
|
214
|
+
*/
|
|
215
|
+
export class SimpleTaintAnalyzer {
|
|
216
|
+
/**
|
|
217
|
+
* Analyze taint flows in code
|
|
218
|
+
*/
|
|
219
|
+
analyze(
|
|
220
|
+
context: AnalysisContext,
|
|
221
|
+
rule: VulnerabilityRule
|
|
222
|
+
): TaintFlow[] {
|
|
223
|
+
const flows: TaintFlow[] = [];
|
|
224
|
+
|
|
225
|
+
if (!rule.taintSources || !rule.taintSinks) {
|
|
226
|
+
return flows;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Find all sources
|
|
230
|
+
const sources = findTaintSources(
|
|
231
|
+
context.content,
|
|
232
|
+
rule.taintSources,
|
|
233
|
+
context.language
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
// Find all sinks
|
|
237
|
+
const sinks = findTaintSinks(
|
|
238
|
+
context.content,
|
|
239
|
+
rule.taintSinks,
|
|
240
|
+
context.language
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
// For each source-sink pair, check if there's a potential flow
|
|
244
|
+
for (const sourceMatch of sources) {
|
|
245
|
+
for (const sinkMatch of sinks) {
|
|
246
|
+
// Simple heuristic: if source appears before sink in the same file
|
|
247
|
+
if (sourceMatch.location.startLine <= sinkMatch.location.startLine) {
|
|
248
|
+
// Check for sanitizers between source and sink
|
|
249
|
+
const sanitizers = rule.taintSanitizers
|
|
250
|
+
? findSanitizers(
|
|
251
|
+
context.content,
|
|
252
|
+
sourceMatch.location,
|
|
253
|
+
sinkMatch.location,
|
|
254
|
+
rule.taintSanitizers
|
|
255
|
+
)
|
|
256
|
+
: [];
|
|
257
|
+
|
|
258
|
+
const isExploitable = sanitizers.length === 0;
|
|
259
|
+
|
|
260
|
+
flows.push({
|
|
261
|
+
source: sourceMatch.source,
|
|
262
|
+
sink: sinkMatch.sink,
|
|
263
|
+
path: [
|
|
264
|
+
{
|
|
265
|
+
name: sourceMatch.matchedText,
|
|
266
|
+
location: sourceMatch.location,
|
|
267
|
+
operation: 'source'
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
name: sinkMatch.matchedText,
|
|
271
|
+
location: sinkMatch.location,
|
|
272
|
+
operation: 'sink'
|
|
273
|
+
}
|
|
274
|
+
],
|
|
275
|
+
sanitizers,
|
|
276
|
+
isExploitable,
|
|
277
|
+
confidence: isExploitable ? ConfidenceLevel.HIGH : ConfidenceLevel.MEDIUM
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return flows;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Convert taint flow to data flow trace for reporting
|
|
288
|
+
*/
|
|
289
|
+
createDataFlowTrace(
|
|
290
|
+
flow: TaintFlow,
|
|
291
|
+
code: string
|
|
292
|
+
): DataFlowTrace {
|
|
293
|
+
const sourceSnippet = extractSnippet(code, flow.path[0].location, 1);
|
|
294
|
+
const sinkSnippet = extractSnippet(code, flow.path[flow.path.length - 1].location, 1);
|
|
295
|
+
|
|
296
|
+
return {
|
|
297
|
+
source: {
|
|
298
|
+
name: flow.source.name,
|
|
299
|
+
location: flow.path[0].location,
|
|
300
|
+
codeSnippet: sourceSnippet.snippet
|
|
301
|
+
},
|
|
302
|
+
propagation: flow.path.slice(1, -1).map(node => ({
|
|
303
|
+
variable: node.name,
|
|
304
|
+
location: node.location,
|
|
305
|
+
operation: node.operation || 'propagate',
|
|
306
|
+
codeSnippet: extractSnippet(code, node.location, 0).snippet
|
|
307
|
+
})),
|
|
308
|
+
sink: {
|
|
309
|
+
name: flow.sink.name,
|
|
310
|
+
location: flow.path[flow.path.length - 1].location,
|
|
311
|
+
codeSnippet: sinkSnippet.snippet
|
|
312
|
+
},
|
|
313
|
+
sanitized: flow.sanitizers.length > 0,
|
|
314
|
+
sanitizationDetails: flow.sanitizers.length > 0 ? {
|
|
315
|
+
sanitizer: flow.sanitizers[0].name,
|
|
316
|
+
location: flow.path[0].location, // Approximate
|
|
317
|
+
effectiveness: flow.sanitizers[0].effectiveness ?? 80
|
|
318
|
+
} : undefined
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ============================================================================
|
|
324
|
+
// ENGINE OPTIONS
|
|
325
|
+
// ============================================================================
|
|
326
|
+
|
|
327
|
+
export interface EngineOptions {
|
|
328
|
+
enableTaintAnalysis: boolean;
|
|
329
|
+
enableAstAnalysis: boolean;
|
|
330
|
+
enableCfgAnalysis: boolean;
|
|
331
|
+
timeoutMs: number;
|
|
332
|
+
maxFindings: number;
|
|
333
|
+
minConfidence: ConfidenceLevel;
|
|
334
|
+
includeInfo: boolean;
|
|
335
|
+
excludeTestFiles: boolean;
|
|
336
|
+
excludeVendorCode: boolean;
|
|
337
|
+
language?: SupportedLanguage;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const DEFAULT_OPTIONS: EngineOptions = {
|
|
341
|
+
enableTaintAnalysis: true,
|
|
342
|
+
enableAstAnalysis: false,
|
|
343
|
+
enableCfgAnalysis: false,
|
|
344
|
+
timeoutMs: LIMITS.RULE_TIMEOUT,
|
|
345
|
+
maxFindings: LIMITS.MAX_FINDINGS_PER_FILE,
|
|
346
|
+
minConfidence: ConfidenceLevel.LOW,
|
|
347
|
+
includeInfo: false,
|
|
348
|
+
excludeTestFiles: false,
|
|
349
|
+
excludeVendorCode: true
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// ============================================================================
|
|
353
|
+
// VULNERABILITY RULE ENGINE
|
|
354
|
+
// ============================================================================
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Main vulnerability detection engine
|
|
358
|
+
*/
|
|
359
|
+
export class VulnerabilityRuleEngine implements IVulnerabilityRuleEngine {
|
|
360
|
+
private rules: Map<string, VulnerabilityRule>;
|
|
361
|
+
private patternMatcher: PatternMatcher;
|
|
362
|
+
private taintAnalyzer: SimpleTaintAnalyzer;
|
|
363
|
+
private scoreCalculator: VulnerabilityScoreCalculator;
|
|
364
|
+
private engineOptions: EngineOptions;
|
|
365
|
+
|
|
366
|
+
constructor(
|
|
367
|
+
rules: VulnerabilityRule[],
|
|
368
|
+
options?: Partial<EngineOptions>
|
|
369
|
+
) {
|
|
370
|
+
this.rules = new Map(rules.map(rule => [rule.id, rule]));
|
|
371
|
+
this.patternMatcher = new PatternMatcher();
|
|
372
|
+
this.taintAnalyzer = new SimpleTaintAnalyzer();
|
|
373
|
+
this.scoreCalculator = new VulnerabilityScoreCalculator();
|
|
374
|
+
this.engineOptions = { ...DEFAULT_OPTIONS, ...options };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Analyze code against all enabled rules
|
|
379
|
+
*/
|
|
380
|
+
async analyze(
|
|
381
|
+
context: AnalysisContext,
|
|
382
|
+
options?: AnalysisOptions
|
|
383
|
+
): Promise<VulnerabilityFinding[]> {
|
|
384
|
+
const mergedOptions = { ...this.engineOptions, ...options };
|
|
385
|
+
|
|
386
|
+
// Check exclusions
|
|
387
|
+
if (mergedOptions.excludeTestFiles && isTestFile(context.filePath)) {
|
|
388
|
+
return [];
|
|
389
|
+
}
|
|
390
|
+
if (mergedOptions.excludeVendorCode && isVendorCode(context.filePath)) {
|
|
391
|
+
return [];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Normalize code
|
|
395
|
+
const normalizedCode = normalizeCode(context.content, context.language);
|
|
396
|
+
const normalizedContext = { ...context, content: normalizedCode };
|
|
397
|
+
|
|
398
|
+
// Get applicable rules
|
|
399
|
+
const applicableRules = this.getApplicableRules(context.language);
|
|
400
|
+
|
|
401
|
+
const findings: VulnerabilityFinding[] = [];
|
|
402
|
+
|
|
403
|
+
for (const rule of applicableRules) {
|
|
404
|
+
try {
|
|
405
|
+
const ruleFindings = await this.analyzeWithRule(
|
|
406
|
+
normalizedContext,
|
|
407
|
+
rule,
|
|
408
|
+
mergedOptions
|
|
409
|
+
);
|
|
410
|
+
findings.push(...ruleFindings);
|
|
411
|
+
|
|
412
|
+
if (findings.length >= mergedOptions.maxFindings) {
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
} catch (error) {
|
|
416
|
+
console.error(`Error analyzing with rule ${rule.id}:`, error);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Sort by severity and score
|
|
421
|
+
findings.sort((a, b) => {
|
|
422
|
+
const severityOrder = {
|
|
423
|
+
[VulnerabilitySeverity.CRITICAL]: 0,
|
|
424
|
+
[VulnerabilitySeverity.HIGH]: 1,
|
|
425
|
+
[VulnerabilitySeverity.MEDIUM]: 2,
|
|
426
|
+
[VulnerabilitySeverity.LOW]: 3,
|
|
427
|
+
[VulnerabilitySeverity.INFO]: 4
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const severityDiff = severityOrder[a.severity] - severityOrder[b.severity];
|
|
431
|
+
if (severityDiff !== 0) return severityDiff;
|
|
432
|
+
|
|
433
|
+
return b.score.score - a.score.score;
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// Deduplicate
|
|
437
|
+
return this.deduplicateFindings(findings);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Analyze code with a specific rule
|
|
442
|
+
*/
|
|
443
|
+
private async analyzeWithRule(
|
|
444
|
+
context: AnalysisContext,
|
|
445
|
+
rule: VulnerabilityRule,
|
|
446
|
+
options: EngineOptions
|
|
447
|
+
): Promise<VulnerabilityFinding[]> {
|
|
448
|
+
const findings: VulnerabilityFinding[] = [];
|
|
449
|
+
|
|
450
|
+
// Pattern matching
|
|
451
|
+
const matches = await this.patternMatcher.matchWithTimeout(
|
|
452
|
+
context.content,
|
|
453
|
+
rule.patterns,
|
|
454
|
+
context.language,
|
|
455
|
+
options.timeoutMs
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
if (matches.length === 0) {
|
|
459
|
+
return findings;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Taint analysis if enabled
|
|
463
|
+
let taintFlows: TaintFlow[] = [];
|
|
464
|
+
if (options.enableTaintAnalysis && (rule.taintSources || rule.taintSinks)) {
|
|
465
|
+
taintFlows = this.taintAnalyzer.analyze(context, rule);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// Group matches by location to avoid duplicate findings
|
|
469
|
+
const locationGroups = this.groupMatchesByLocation(matches);
|
|
470
|
+
|
|
471
|
+
for (const [locationKey, groupMatches] of locationGroups) {
|
|
472
|
+
// Find relevant taint flow for this location
|
|
473
|
+
const relevantFlow = taintFlows.find(flow =>
|
|
474
|
+
flow.path.some(node =>
|
|
475
|
+
this.locationsOverlap(node.location, groupMatches[0].location)
|
|
476
|
+
)
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
// Calculate score
|
|
480
|
+
const score = this.scoreCalculator.calculateScore(
|
|
481
|
+
rule,
|
|
482
|
+
groupMatches,
|
|
483
|
+
context,
|
|
484
|
+
relevantFlow
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
// Check minimum confidence
|
|
488
|
+
const confidence = relevantFlow
|
|
489
|
+
? adjustConfidenceForTaintFlow(rule.confidence, true)
|
|
490
|
+
: rule.confidence;
|
|
491
|
+
|
|
492
|
+
if (!this.meetsMinConfidence(confidence, options.minConfidence)) {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Filter out INFO if not requested
|
|
497
|
+
if (!options.includeInfo && score.calculatedSeverity === VulnerabilitySeverity.INFO) {
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Create finding
|
|
502
|
+
const finding = this.createFinding(
|
|
503
|
+
rule,
|
|
504
|
+
groupMatches,
|
|
505
|
+
context,
|
|
506
|
+
score,
|
|
507
|
+
relevantFlow
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
findings.push(finding);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return findings;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Create a vulnerability finding
|
|
518
|
+
*/
|
|
519
|
+
private createFinding(
|
|
520
|
+
rule: VulnerabilityRule,
|
|
521
|
+
matches: PatternMatch[],
|
|
522
|
+
context: AnalysisContext,
|
|
523
|
+
score: VulnerabilityScore,
|
|
524
|
+
taintFlow?: TaintFlow
|
|
525
|
+
): VulnerabilityFinding {
|
|
526
|
+
const primaryMatch = matches[0];
|
|
527
|
+
const location: SourceLocation = {
|
|
528
|
+
filePath: context.filePath,
|
|
529
|
+
startLine: primaryMatch.location.startLine,
|
|
530
|
+
endLine: primaryMatch.location.endLine,
|
|
531
|
+
startColumn: primaryMatch.location.startColumn,
|
|
532
|
+
endColumn: primaryMatch.location.endColumn
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const { snippet } = extractSnippet(context.content, location, 3);
|
|
536
|
+
|
|
537
|
+
// Build data flow trace if taint flow exists
|
|
538
|
+
let dataFlowTrace: DataFlowTrace | undefined;
|
|
539
|
+
if (taintFlow) {
|
|
540
|
+
dataFlowTrace = this.taintAnalyzer.createDataFlowTrace(
|
|
541
|
+
taintFlow,
|
|
542
|
+
context.content
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// Determine final confidence
|
|
547
|
+
const confidence = taintFlow
|
|
548
|
+
? adjustConfidenceForTaintFlow(rule.confidence, true)
|
|
549
|
+
: rule.confidence;
|
|
550
|
+
|
|
551
|
+
return {
|
|
552
|
+
id: generateFindingId(rule.id, context.filePath, location.startLine),
|
|
553
|
+
ruleId: rule.id,
|
|
554
|
+
ruleName: rule.name,
|
|
555
|
+
location,
|
|
556
|
+
codeSnippet: snippet,
|
|
557
|
+
highlightedCode: primaryMatch.matchedText,
|
|
558
|
+
vulnerabilityType: rule.vulnerabilityType,
|
|
559
|
+
category: rule.category,
|
|
560
|
+
severity: score.calculatedSeverity,
|
|
561
|
+
confidence,
|
|
562
|
+
score,
|
|
563
|
+
patternMatches: matches,
|
|
564
|
+
taintFlow,
|
|
565
|
+
dataFlowTrace,
|
|
566
|
+
message: this.generateMessage(rule, matches, taintFlow),
|
|
567
|
+
auditAnalysis: this.generateAuditAnalysis(rule, matches, taintFlow, score),
|
|
568
|
+
developerExplanation: this.generateDeveloperExplanation(rule, matches),
|
|
569
|
+
remediation: rule.remediation,
|
|
570
|
+
standards: rule.standards,
|
|
571
|
+
detectedAt: new Date().toISOString(),
|
|
572
|
+
language: context.language,
|
|
573
|
+
isTestCode: context.isTestFile,
|
|
574
|
+
isVendorCode: context.isVendorCode
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Generate finding message
|
|
580
|
+
*/
|
|
581
|
+
private generateMessage(
|
|
582
|
+
rule: VulnerabilityRule,
|
|
583
|
+
matches: PatternMatch[],
|
|
584
|
+
taintFlow?: TaintFlow
|
|
585
|
+
): string {
|
|
586
|
+
let message = `${rule.name}: ${rule.description}`;
|
|
587
|
+
|
|
588
|
+
if (taintFlow && taintFlow.isExploitable) {
|
|
589
|
+
message += ` Confirmed data flow from '${taintFlow.source.name}' to '${taintFlow.sink.name}'.`;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
return message;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Generate detailed audit analysis
|
|
597
|
+
*/
|
|
598
|
+
private generateAuditAnalysis(
|
|
599
|
+
rule: VulnerabilityRule,
|
|
600
|
+
matches: PatternMatch[],
|
|
601
|
+
taintFlow: TaintFlow | undefined,
|
|
602
|
+
score: VulnerabilityScore
|
|
603
|
+
): string {
|
|
604
|
+
const parts: string[] = [];
|
|
605
|
+
|
|
606
|
+
parts.push(`## Vulnerability Analysis: ${rule.name}`);
|
|
607
|
+
parts.push('');
|
|
608
|
+
parts.push(`**Vulnerability Type:** ${rule.vulnerabilityType}`);
|
|
609
|
+
parts.push(`**Category:** ${rule.category}`);
|
|
610
|
+
parts.push(`**Severity:** ${score.calculatedSeverity.toUpperCase()}`);
|
|
611
|
+
parts.push(`**Risk Score:** ${score.score}/100`);
|
|
612
|
+
parts.push('');
|
|
613
|
+
|
|
614
|
+
// Standards mapping
|
|
615
|
+
parts.push('### Security Standards');
|
|
616
|
+
if (rule.standards.owasp?.length) {
|
|
617
|
+
parts.push(`**OWASP:** ${rule.standards.owasp.map(o => o.id).join(', ')}`);
|
|
618
|
+
}
|
|
619
|
+
if (rule.standards.cwe?.length) {
|
|
620
|
+
parts.push(`**CWE:** ${rule.standards.cwe.map(c => c.id).join(', ')}`);
|
|
621
|
+
}
|
|
622
|
+
parts.push('');
|
|
623
|
+
|
|
624
|
+
// Detection details
|
|
625
|
+
parts.push('### Detection Details');
|
|
626
|
+
parts.push(`**Pattern Matches:** ${matches.length}`);
|
|
627
|
+
|
|
628
|
+
if (taintFlow) {
|
|
629
|
+
parts.push('');
|
|
630
|
+
parts.push('### Data Flow Analysis');
|
|
631
|
+
parts.push(`**Source:** ${taintFlow.source.name}`);
|
|
632
|
+
parts.push(`**Sink:** ${taintFlow.sink.name}`);
|
|
633
|
+
parts.push(`**Exploitable:** ${taintFlow.isExploitable ? 'Yes' : 'No'}`);
|
|
634
|
+
if (taintFlow.sanitizers.length > 0) {
|
|
635
|
+
parts.push(`**Sanitizers Applied:** ${taintFlow.sanitizers.map(s => s.name).join(', ')}`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
parts.push('');
|
|
640
|
+
parts.push('### Impact Assessment');
|
|
641
|
+
if (rule.impact) {
|
|
642
|
+
parts.push(`**Confidentiality:** ${rule.impact.confidentiality}`);
|
|
643
|
+
parts.push(`**Integrity:** ${rule.impact.integrity}`);
|
|
644
|
+
parts.push(`**Availability:** ${rule.impact.availability}`);
|
|
645
|
+
parts.push(`**Technical Impact:** ${rule.impact.technicalImpact}`);
|
|
646
|
+
parts.push(`**Business Impact:** ${rule.impact.businessImpact}`);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
parts.push('');
|
|
650
|
+
parts.push('### Score Breakdown');
|
|
651
|
+
parts.push('```');
|
|
652
|
+
parts.push(score.explanation);
|
|
653
|
+
parts.push('```');
|
|
654
|
+
|
|
655
|
+
return parts.join('\n');
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Generate developer-friendly explanation
|
|
660
|
+
*/
|
|
661
|
+
private generateDeveloperExplanation(
|
|
662
|
+
rule: VulnerabilityRule,
|
|
663
|
+
matches: PatternMatch[]
|
|
664
|
+
): string {
|
|
665
|
+
const parts: string[] = [];
|
|
666
|
+
|
|
667
|
+
parts.push(`**What's the problem?**`);
|
|
668
|
+
parts.push(rule.description);
|
|
669
|
+
parts.push('');
|
|
670
|
+
|
|
671
|
+
parts.push(`**Why is this dangerous?**`);
|
|
672
|
+
if (rule.impact) {
|
|
673
|
+
parts.push(rule.impact.technicalImpact);
|
|
674
|
+
}
|
|
675
|
+
parts.push('');
|
|
676
|
+
|
|
677
|
+
parts.push(`**How to fix it:**`);
|
|
678
|
+
parts.push(rule.remediation.summary);
|
|
679
|
+
if (rule.remediation.steps?.length) {
|
|
680
|
+
rule.remediation.steps.forEach((step, i) => {
|
|
681
|
+
parts.push(`${i + 1}. ${step}`);
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (rule.remediation.secureCodeExample) {
|
|
686
|
+
parts.push('');
|
|
687
|
+
parts.push('**Secure code example:**');
|
|
688
|
+
parts.push('```');
|
|
689
|
+
parts.push(rule.remediation.secureCodeExample);
|
|
690
|
+
parts.push('```');
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return parts.join('\n');
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Get rules applicable to a language
|
|
698
|
+
*/
|
|
699
|
+
private getApplicableRules(language: SupportedLanguage): VulnerabilityRule[] {
|
|
700
|
+
return Array.from(this.rules.values()).filter(rule =>
|
|
701
|
+
rule.enabled && rule.languages.includes(language)
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Get all registered rules
|
|
707
|
+
*/
|
|
708
|
+
getRules(): VulnerabilityRule[] {
|
|
709
|
+
return Array.from(this.rules.values());
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Get rule by ID
|
|
714
|
+
*/
|
|
715
|
+
getRule(id: string): VulnerabilityRule | undefined {
|
|
716
|
+
return this.rules.get(id);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Enable/disable a rule
|
|
721
|
+
*/
|
|
722
|
+
setRuleEnabled(id: string, enabled: boolean): void {
|
|
723
|
+
const rule = this.rules.get(id);
|
|
724
|
+
if (rule) {
|
|
725
|
+
rule.enabled = enabled;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Add a custom rule
|
|
731
|
+
*/
|
|
732
|
+
addRule(rule: VulnerabilityRule): void {
|
|
733
|
+
this.rules.set(rule.id, rule);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Group matches by location
|
|
738
|
+
*/
|
|
739
|
+
private groupMatchesByLocation(
|
|
740
|
+
matches: PatternMatch[]
|
|
741
|
+
): Map<string, PatternMatch[]> {
|
|
742
|
+
const groups = new Map<string, PatternMatch[]>();
|
|
743
|
+
|
|
744
|
+
for (const match of matches) {
|
|
745
|
+
const key = `${match.location.startLine}:${match.location.startColumn}`;
|
|
746
|
+
const existing = groups.get(key) || [];
|
|
747
|
+
existing.push(match);
|
|
748
|
+
groups.set(key, existing);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
return groups;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Check if two locations overlap
|
|
756
|
+
*/
|
|
757
|
+
private locationsOverlap(a: SourceLocation, b: SourceLocation): boolean {
|
|
758
|
+
return a.startLine <= b.endLine && b.startLine <= a.endLine;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Check if confidence meets minimum
|
|
763
|
+
*/
|
|
764
|
+
private meetsMinConfidence(
|
|
765
|
+
confidence: ConfidenceLevel,
|
|
766
|
+
minConfidence: ConfidenceLevel
|
|
767
|
+
): boolean {
|
|
768
|
+
const levels = [
|
|
769
|
+
ConfidenceLevel.TENTATIVE,
|
|
770
|
+
ConfidenceLevel.LOW,
|
|
771
|
+
ConfidenceLevel.MEDIUM,
|
|
772
|
+
ConfidenceLevel.HIGH,
|
|
773
|
+
ConfidenceLevel.CONFIRMED
|
|
774
|
+
];
|
|
775
|
+
return levels.indexOf(confidence) >= levels.indexOf(minConfidence);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Deduplicate findings
|
|
780
|
+
*/
|
|
781
|
+
private deduplicateFindings(
|
|
782
|
+
findings: VulnerabilityFinding[]
|
|
783
|
+
): VulnerabilityFinding[] {
|
|
784
|
+
const seen = new Set<string>();
|
|
785
|
+
return findings.filter(finding => {
|
|
786
|
+
const key = `${finding.ruleId}:${finding.location.filePath}:${finding.location.startLine}`;
|
|
787
|
+
if (seen.has(key)) {
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
seen.add(key);
|
|
791
|
+
return true;
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// ============================================================================
|
|
797
|
+
// FACTORY FUNCTIONS
|
|
798
|
+
// ============================================================================
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Create default vulnerability engine
|
|
802
|
+
*/
|
|
803
|
+
export function createDefaultEngine(
|
|
804
|
+
rules: VulnerabilityRule[],
|
|
805
|
+
options?: Partial<EngineOptions>
|
|
806
|
+
): VulnerabilityRuleEngine {
|
|
807
|
+
return new VulnerabilityRuleEngine(rules, options);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Quick scan function for simple usage
|
|
812
|
+
*/
|
|
813
|
+
export async function quickScan(
|
|
814
|
+
code: string,
|
|
815
|
+
filePath: string,
|
|
816
|
+
language: SupportedLanguage,
|
|
817
|
+
rules: VulnerabilityRule[],
|
|
818
|
+
options?: Partial<EngineOptions>
|
|
819
|
+
): Promise<VulnerabilityFinding[]> {
|
|
820
|
+
const engine = createDefaultEngine(rules, options);
|
|
821
|
+
|
|
822
|
+
const context: AnalysisContext = {
|
|
823
|
+
filePath,
|
|
824
|
+
content: code,
|
|
825
|
+
language,
|
|
826
|
+
isTestFile: isTestFile(filePath),
|
|
827
|
+
isVendorCode: isVendorCode(filePath)
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
return engine.analyze(context);
|
|
831
|
+
}
|