vibe-guard 1.1.4 → 1.2.0

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.
Files changed (140) hide show
  1. package/README.md +163 -283
  2. package/dist/bin/vibe-guard.js +240 -22
  3. package/dist/bin/vibe-guard.js.map +1 -1
  4. package/dist/config.d.ts +0 -18
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +5 -26
  7. package/dist/config.js.map +1 -1
  8. package/dist/index.d.ts +0 -6
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +5 -8
  11. package/dist/index.js.map +1 -1
  12. package/dist/reporter.d.ts.map +1 -1
  13. package/dist/reporter.js +41 -19
  14. package/dist/reporter.js.map +1 -1
  15. package/dist/rules/ai-agent-access-control.d.ts +27 -2
  16. package/dist/rules/ai-agent-access-control.d.ts.map +1 -1
  17. package/dist/rules/ai-agent-access-control.js +393 -19
  18. package/dist/rules/ai-agent-access-control.js.map +1 -1
  19. package/dist/rules/ai-data-leakage-prevention.d.ts +25 -2
  20. package/dist/rules/ai-data-leakage-prevention.d.ts.map +1 -1
  21. package/dist/rules/ai-data-leakage-prevention.js +409 -21
  22. package/dist/rules/ai-data-leakage-prevention.js.map +1 -1
  23. package/dist/rules/ai-generated-code-validation.d.ts +28 -7
  24. package/dist/rules/ai-generated-code-validation.d.ts.map +1 -1
  25. package/dist/rules/ai-generated-code-validation.js +367 -96
  26. package/dist/rules/ai-generated-code-validation.js.map +1 -1
  27. package/dist/rules/broken-access-control.d.ts +40 -5
  28. package/dist/rules/broken-access-control.d.ts.map +1 -1
  29. package/dist/rules/broken-access-control.js +595 -144
  30. package/dist/rules/broken-access-control.js.map +1 -1
  31. package/dist/rules/container-registry-security.d.ts +21 -0
  32. package/dist/rules/container-registry-security.d.ts.map +1 -0
  33. package/dist/rules/container-registry-security.js +271 -0
  34. package/dist/rules/container-registry-security.js.map +1 -0
  35. package/dist/rules/csrf-protection.d.ts +25 -4
  36. package/dist/rules/csrf-protection.d.ts.map +1 -1
  37. package/dist/rules/csrf-protection.js +328 -81
  38. package/dist/rules/csrf-protection.js.map +1 -1
  39. package/dist/rules/directory-traversal.d.ts +33 -5
  40. package/dist/rules/directory-traversal.d.ts.map +1 -1
  41. package/dist/rules/directory-traversal.js +470 -171
  42. package/dist/rules/directory-traversal.js.map +1 -1
  43. package/dist/rules/dockerfile-security.d.ts +20 -0
  44. package/dist/rules/dockerfile-security.d.ts.map +1 -0
  45. package/dist/rules/dockerfile-security.js +280 -0
  46. package/dist/rules/dockerfile-security.js.map +1 -0
  47. package/dist/rules/exposed-secrets.d.ts +25 -4
  48. package/dist/rules/exposed-secrets.d.ts.map +1 -1
  49. package/dist/rules/exposed-secrets.js +355 -95
  50. package/dist/rules/exposed-secrets.js.map +1 -1
  51. package/dist/rules/hardcoded-sensitive-data.d.ts +32 -2
  52. package/dist/rules/hardcoded-sensitive-data.d.ts.map +1 -1
  53. package/dist/rules/hardcoded-sensitive-data.js +426 -29
  54. package/dist/rules/hardcoded-sensitive-data.js.map +1 -1
  55. package/dist/rules/index.d.ts +9 -1
  56. package/dist/rules/index.d.ts.map +1 -1
  57. package/dist/rules/index.js +25 -1
  58. package/dist/rules/index.js.map +1 -1
  59. package/dist/rules/insecure-configuration.d.ts +16 -5
  60. package/dist/rules/insecure-configuration.d.ts.map +1 -1
  61. package/dist/rules/insecure-configuration.js +457 -64
  62. package/dist/rules/insecure-configuration.js.map +1 -1
  63. package/dist/rules/insecure-dependencies.d.ts +46 -1
  64. package/dist/rules/insecure-dependencies.d.ts.map +1 -1
  65. package/dist/rules/insecure-dependencies.js +678 -51
  66. package/dist/rules/insecure-dependencies.js.map +1 -1
  67. package/dist/rules/insecure-deserialization.d.ts +29 -4
  68. package/dist/rules/insecure-deserialization.d.ts.map +1 -1
  69. package/dist/rules/insecure-deserialization.js +531 -101
  70. package/dist/rules/insecure-deserialization.js.map +1 -1
  71. package/dist/rules/insecure-error-handling.d.ts +35 -4
  72. package/dist/rules/insecure-error-handling.d.ts.map +1 -1
  73. package/dist/rules/insecure-error-handling.js +590 -87
  74. package/dist/rules/insecure-error-handling.js.map +1 -1
  75. package/dist/rules/insecure-file-upload.d.ts +37 -5
  76. package/dist/rules/insecure-file-upload.d.ts.map +1 -1
  77. package/dist/rules/insecure-file-upload.js +690 -138
  78. package/dist/rules/insecure-file-upload.js.map +1 -1
  79. package/dist/rules/insecure-http.d.ts +31 -2
  80. package/dist/rules/insecure-http.d.ts.map +1 -1
  81. package/dist/rules/insecure-http.js +547 -61
  82. package/dist/rules/insecure-http.js.map +1 -1
  83. package/dist/rules/insecure-logging.d.ts +6 -1
  84. package/dist/rules/insecure-logging.d.ts.map +1 -1
  85. package/dist/rules/insecure-logging.js +430 -109
  86. package/dist/rules/insecure-logging.js.map +1 -1
  87. package/dist/rules/insecure-random-generation.d.ts +4 -1
  88. package/dist/rules/insecure-random-generation.d.ts.map +1 -1
  89. package/dist/rules/insecure-random-generation.js +239 -99
  90. package/dist/rules/insecure-random-generation.js.map +1 -1
  91. package/dist/rules/insecure-session-management.d.ts +4 -0
  92. package/dist/rules/insecure-session-management.d.ts.map +1 -1
  93. package/dist/rules/insecure-session-management.js +359 -54
  94. package/dist/rules/insecure-session-management.js.map +1 -1
  95. package/dist/rules/kubernetes-security.d.ts +17 -0
  96. package/dist/rules/kubernetes-security.d.ts.map +1 -0
  97. package/dist/rules/kubernetes-security.js +314 -0
  98. package/dist/rules/kubernetes-security.js.map +1 -0
  99. package/dist/rules/mcp-server-security.d.ts +32 -3
  100. package/dist/rules/mcp-server-security.d.ts.map +1 -1
  101. package/dist/rules/mcp-server-security.js +511 -39
  102. package/dist/rules/mcp-server-security.js.map +1 -1
  103. package/dist/rules/missing-authentication.d.ts +4 -0
  104. package/dist/rules/missing-authentication.d.ts.map +1 -1
  105. package/dist/rules/missing-authentication.js +263 -62
  106. package/dist/rules/missing-authentication.js.map +1 -1
  107. package/dist/rules/missing-security-headers.d.ts +32 -3
  108. package/dist/rules/missing-security-headers.d.ts.map +1 -1
  109. package/dist/rules/missing-security-headers.js +548 -95
  110. package/dist/rules/missing-security-headers.js.map +1 -1
  111. package/dist/rules/open-cors.d.ts +3 -0
  112. package/dist/rules/open-cors.d.ts.map +1 -1
  113. package/dist/rules/open-cors.js +202 -57
  114. package/dist/rules/open-cors.js.map +1 -1
  115. package/dist/rules/prompt-injection-detection.d.ts +33 -3
  116. package/dist/rules/prompt-injection-detection.d.ts.map +1 -1
  117. package/dist/rules/prompt-injection-detection.js +571 -43
  118. package/dist/rules/prompt-injection-detection.js.map +1 -1
  119. package/dist/rules/sql-injection.d.ts +27 -3
  120. package/dist/rules/sql-injection.d.ts.map +1 -1
  121. package/dist/rules/sql-injection.js +471 -61
  122. package/dist/rules/sql-injection.js.map +1 -1
  123. package/dist/rules/unvalidated-input.d.ts +20 -4
  124. package/dist/rules/unvalidated-input.d.ts.map +1 -1
  125. package/dist/rules/unvalidated-input.js +557 -128
  126. package/dist/rules/unvalidated-input.js.map +1 -1
  127. package/dist/rules/xss-detection.d.ts +25 -4
  128. package/dist/rules/xss-detection.d.ts.map +1 -1
  129. package/dist/rules/xss-detection.js +702 -135
  130. package/dist/rules/xss-detection.js.map +1 -1
  131. package/dist/scanner.d.ts.map +1 -1
  132. package/dist/scanner.js +11 -6
  133. package/dist/scanner.js.map +1 -1
  134. package/dist/types/index.d.ts +4 -0
  135. package/dist/types/index.d.ts.map +1 -1
  136. package/dist/types/index.js.map +1 -1
  137. package/dist/types/version.d.ts +1 -1
  138. package/dist/types/version.js +1 -1
  139. package/package.json +8 -3
  140. package/CHANGELOG.md +0 -102
@@ -9,170 +9,737 @@ class XssDetectionRule extends types_1.BaseRule {
9
9
  this.description = 'Detects potential cross-site scripting (XSS) vulnerabilities';
10
10
  this.severity = 'critical';
11
11
  this.xssPatterns = [
12
- { pattern: /(?:innerHTML|outerHTML)\s*=\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'DOM manipulation with variable' },
13
- { pattern: /(?:innerHTML|outerHTML)\s*\+=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'DOM manipulation with concatenation' },
14
- { pattern: /(?:innerHTML|outerHTML)\s*\+=\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'DOM manipulation with variable concatenation' },
15
- { pattern: /document\.write\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Unsafe document.write' },
16
- { pattern: /document\.writeln\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Unsafe document.writeln' },
17
- { pattern: /document\.open\s*\(\s*\)/gi, type: 'Document open without validation' },
18
- { pattern: /document\.write\s*\(\s*["'`]<script[^>]*>["'`]\s*\+/gi, type: 'Unsafe document.write with script tag' },
19
- { pattern: /document\.write\s*\(\s*["'`][^"'`]*["'`]\s*\+\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'Unsafe document.write with concatenation' },
20
- { pattern: /element\.innerHTML\s*=\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'Unsafe element.innerHTML assignment' },
21
- { pattern: /\.innerHTML\s*=\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'Unsafe innerHTML assignment' },
22
- { pattern: /eval\s*\(\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'Eval with variable' },
23
- { pattern: /eval\s*\(\s*JSON\.stringify/gi, type: 'Eval with JSON stringify' },
24
- { pattern: /Function\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Function constructor with user input' },
25
- { pattern: /Function\s*\(\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'Function constructor with variable' },
26
- { pattern: /setTimeout\s*\(\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'setTimeout with variable' },
27
- { pattern: /setInterval\s*\(\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'setInterval with variable' },
28
- { pattern: /new\s+Function\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Dynamic function with user input' },
29
- { pattern: /execScript\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'ExecScript with user input' },
30
- { pattern: /script\s*\.\s*src\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Dynamic script src with user input' },
31
- { pattern: /(?:template|render)\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Template injection' },
32
- { pattern: /(?:ejs|handlebars|mustache|pug)\.render\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Template engine injection' },
33
- { pattern: /React\.createElement\s*\(\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'React element with variable' },
34
- { pattern: /Vue\.component\s*\(\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'Vue component with variable' },
35
- { pattern: /angular\.component\s*\(\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'Angular component with variable' },
36
- { pattern: /location\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Unsafe location assignment' },
37
- { pattern: /window\.open\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Unsafe window.open' },
38
- { pattern: /location\.href\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Unsafe location.href assignment' },
39
- { pattern: /location\.assign\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Unsafe location.assign' },
40
- { pattern: /location\.replace\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Unsafe location.replace' },
41
- { pattern: /<script[^>]*>\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'Script tag with user input' },
42
- { pattern: /on\w+\s*=\s*[a-zA-Z_][a-zA-Z0-9_]*/gi, type: 'Event handler with variable' },
43
- { pattern: /addEventListener\s*\(\s*['"`][^'"`]*['"`]\s*,\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'addEventListener with user input' },
44
- { pattern: /attachEvent\s*\(\s*['"`][^'"`]*['"`]\s*,\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'attachEvent with user input' },
45
- { pattern: /style\s*\.\s*cssText\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'CSS injection with user input' },
46
- { pattern: /style\s*\.\s*background\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'CSS background with user input' },
47
- { pattern: /style\s*\.\s*color\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'CSS color with user input' },
48
- { pattern: /JSON\.parse\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'JSON parse with user input' },
49
- { pattern: /JSON\.stringify\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.)/gi, type: 'JSON stringify with user input' },
50
- { pattern: /echo\s+(?:\$_GET|\$_POST|\$_REQUEST)/gi, type: 'PHP echo with user input' },
51
- { pattern: /print\s+(?:\$_GET|\$_POST|\$_REQUEST)/gi, type: 'PHP print with user input' },
52
- { pattern: /printf\s*\(\s*(?:\$_GET|\$_POST|\$_REQUEST)/gi, type: 'PHP printf with user input' },
53
- { pattern: /print_r\s*\(\s*(?:\$_GET|\$_POST|\$_REQUEST)/gi, type: 'PHP print_r with user input' },
54
- { pattern: /var_dump\s*\(\s*(?:\$_GET|\$_POST|\$_REQUEST)/gi, type: 'PHP var_dump with user input' },
55
- { pattern: /print\s*\(\s*(?:request\.|flask\.request\.)/gi, type: 'Python print with user input' },
56
- { pattern: /render_template\s*\(\s*[^,]*,\s*(?:request\.|flask\.request\.)/gi, type: 'Flask template with user input' },
57
- { pattern: /render_template_string\s*\(\s*(?:request\.|flask\.request\.)/gi, type: 'Flask template string with user input' },
58
- { pattern: /Markup\s*\(\s*(?:request\.|flask\.request\.)/gi, type: 'Flask Markup with user input' },
59
- { pattern: /out\.print\s*\(\s*(?:request\.getParameter|request\.getAttribute)/gi, type: 'Java print with user input' },
60
- { pattern: /response\.getWriter\(\)\.print\s*\(\s*(?:request\.getParameter|request\.getAttribute)/gi, type: 'Java response print with user input' },
61
- { pattern: /response\.getWriter\(\)\.write\s*\(\s*(?:request\.getParameter|request\.getAttribute)/gi, type: 'Java response write with user input' },
62
- { pattern: /puts\s+(?:params|request)/gi, type: 'Ruby puts with user input' },
63
- { pattern: /print\s+(?:params|request)/gi, type: 'Ruby print with user input' },
64
- { pattern: /render\s*:\s*text\s*=>\s*(?:params|request)/gi, type: 'Ruby render text with user input' },
65
- { pattern: /render\s*:\s*inline\s*=>\s*(?:params|request)/gi, type: 'Ruby render inline with user input' },
66
- { pattern: /Response\.Write\s*\(\s*(?:Request|Input)/gi, type: '.NET Response.Write with user input' },
67
- { pattern: /Response\.Output\.Write\s*\(\s*(?:Request|Input)/gi, type: '.NET Response.Output.Write with user input' },
68
- { pattern: /Literal\.Text\s*=\s*(?:Request|Input)/gi, type: '.NET Literal.Text with user input' },
69
- { pattern: /webView\.loadUrl\s*\(\s*(?:request|input)/gi, type: 'Android WebView with user input' },
70
- { pattern: /webView\.loadHTMLString\s*\(\s*(?:request|input)/gi, type: 'iOS WebView with user input' },
71
- { pattern: /WKWebView.*loadHTMLString.*(?:request|input)/gi, type: 'iOS WKWebView with user input' }
72
- ];
73
- this.safePatterns = [
74
- /textContent/i,
75
- /innerText/i,
76
- /createTextNode/i,
77
- /appendChild/i,
78
- /insertBefore/i,
79
- /replaceChild/i,
80
- /escape/i,
81
- /sanitize/i,
82
- /clean/i,
83
- /purify/i,
84
- /filter/i,
85
- /validate/i,
86
- /encodeURIComponent/i,
87
- /encodeURI/i,
88
- /escapeHtml/i,
89
- /htmlEscape/i,
90
- /xss/i,
91
- /DOMPurify/i,
92
- /sanitize-html/i,
93
- /validator\.escape/i,
94
- /html\.escape/i,
95
- /cgi\.escape/i,
96
- /htmlspecialchars/i,
97
- /htmlentities/i,
98
- /StringEscapeUtils/i,
99
- /HtmlUtils\.escape/i,
100
- /SecurityUtils\.sanitize/i,
101
- /React\.createElement\s*\(\s*['"`][^'"`]*['"`]/i,
102
- /Vue\.component\s*\(\s*['"`][^'"`]*['"`]/i,
103
- /angular\.component\s*\(\s*['"`][^'"`]*['"`]/i,
104
- /template\s*:\s*['"`][^'"`]*['"`]/i,
105
- /render\s*:\s*['"`][^'"`]*['"`]/i,
106
- /console\.log\s*\(\s*['"`][^'"`]*['"`]/i,
107
- /console\.warn\s*\(\s*['"`][^'"`]*['"`]/i,
108
- /console\.error\s*\(\s*['"`][^'"`]*['"`]/i,
109
- /toString\(\)/i,
110
- /String\(\)/i,
111
- /JSON\.stringify\s*\(\s*['"`][^'"`]*['"`]/i,
112
- /const\s+\w+\s*=\s*['"`][^'"`]*['"`]/i,
113
- /let\s+\w+\s*=\s*['"`][^'"`]*['"`]/i,
114
- /var\s+\w+\s*=\s*['"`][^'"`]*['"`]/i
12
+ // Critical - Direct user input in dangerous sinks
13
+ {
14
+ pattern: /\b(?:innerHTML|outerHTML)\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
15
+ type: 'DOM manipulation with user input',
16
+ severity: 'critical',
17
+ description: 'Critical XSS risk: User input directly assigned to innerHTML/outerHTML',
18
+ sink: 'innerHTML/outerHTML',
19
+ framework: 'all',
20
+ validation: (text) => this.validateDomManipulation(text)
21
+ },
22
+ {
23
+ pattern: /\b(?:innerHTML|outerHTML)\s*\+=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
24
+ type: 'DOM manipulation with user input concatenation',
25
+ severity: 'critical',
26
+ description: 'Critical XSS risk: User input concatenated into innerHTML/outerHTML',
27
+ sink: 'innerHTML/outerHTML',
28
+ framework: 'all',
29
+ validation: (text) => this.validateDomManipulation(text)
30
+ },
31
+ {
32
+ pattern: /\bdocument\.write\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
33
+ type: 'Unsafe document.write with user input',
34
+ severity: 'critical',
35
+ description: 'Critical XSS risk: User input used in document.write',
36
+ sink: 'document.write',
37
+ framework: 'all',
38
+ validation: (text) => this.validateDocumentWrite(text)
39
+ },
40
+ {
41
+ pattern: /\bdocument\.writeln\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
42
+ type: 'Unsafe document.writeln with user input',
43
+ severity: 'critical',
44
+ description: 'Critical XSS risk: User input used in document.writeln',
45
+ sink: 'document.writeln',
46
+ framework: 'all',
47
+ validation: (text) => this.validateDocumentWrite(text)
48
+ },
49
+ {
50
+ pattern: /\beval\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
51
+ type: 'Eval with user input',
52
+ severity: 'critical',
53
+ description: 'Critical XSS risk: User input used in eval()',
54
+ sink: 'eval',
55
+ framework: 'all',
56
+ validation: (text) => this.validateEval(text)
57
+ },
58
+ {
59
+ pattern: /\bFunction\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
60
+ type: 'Function constructor with user input',
61
+ severity: 'critical',
62
+ description: 'Critical XSS risk: User input used in Function constructor',
63
+ sink: 'Function',
64
+ framework: 'all',
65
+ validation: (text) => this.validateFunctionConstructor(text)
66
+ },
67
+ // High - Template injection and dynamic content
68
+ {
69
+ pattern: /\b(?:ejs|handlebars|mustache|pug)\.render\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
70
+ type: 'Template engine injection with user input',
71
+ severity: 'high',
72
+ description: 'High XSS risk: User input used in template engine rendering',
73
+ sink: 'template.render',
74
+ framework: 'all',
75
+ validation: (text) => this.validateTemplateInjection(text)
76
+ },
77
+ {
78
+ pattern: /\brender_template_string\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
79
+ type: 'Flask template string with user input',
80
+ severity: 'high',
81
+ description: 'High XSS risk: User input used in Flask template string rendering',
82
+ sink: 'render_template_string',
83
+ framework: 'Flask',
84
+ validation: (text) => this.validateFlaskTemplate(text)
85
+ },
86
+ {
87
+ pattern: /\bMarkup\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
88
+ type: 'Flask Markup with user input',
89
+ severity: 'high',
90
+ description: 'High XSS risk: User input used in Flask Markup',
91
+ sink: 'Markup',
92
+ framework: 'Flask',
93
+ validation: (text) => this.validateFlaskMarkup(text)
94
+ },
95
+ // Medium - React/Vue/Angular unsafe patterns
96
+ {
97
+ pattern: /\bdangerouslySetInnerHTML\s*=\s*\{\s*__html:\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
98
+ type: 'React dangerouslySetInnerHTML with user input',
99
+ severity: 'medium',
100
+ description: 'Medium XSS risk: User input used in React dangerouslySetInnerHTML',
101
+ sink: 'dangerouslySetInnerHTML',
102
+ framework: 'React',
103
+ validation: (text) => this.validateReactDangerousHtml(text)
104
+ },
105
+ {
106
+ pattern: /\bv-html\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
107
+ type: 'Vue v-html with user input',
108
+ severity: 'medium',
109
+ description: 'Medium XSS risk: User input used in Vue v-html directive',
110
+ sink: 'v-html',
111
+ framework: 'Vue',
112
+ validation: (text) => this.validateVueVHtml(text)
113
+ },
114
+ {
115
+ pattern: /\b\[innerHTML\]\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
116
+ type: 'Angular innerHTML binding with user input',
117
+ severity: 'medium',
118
+ description: 'Medium XSS risk: User input used in Angular innerHTML binding',
119
+ sink: '[innerHTML]',
120
+ framework: 'Angular',
121
+ validation: (text) => this.validateAngularInnerHtml(text)
122
+ },
123
+ // Low - Legacy jQuery/AngularJS patterns
124
+ {
125
+ pattern: /\$\([^)]*\)\.html\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
126
+ type: 'jQuery html() with user input',
127
+ severity: 'low',
128
+ description: 'Low XSS risk: User input used in jQuery html() method',
129
+ sink: 'jQuery.html()',
130
+ framework: 'jQuery',
131
+ validation: (text) => this.validateJQueryHtml(text)
132
+ },
133
+ {
134
+ pattern: /\$\([^)]*\)\.append\s*\(\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
135
+ type: 'jQuery append() with user input',
136
+ severity: 'low',
137
+ description: 'Low XSS risk: User input used in jQuery append() method',
138
+ sink: 'jQuery.append()',
139
+ framework: 'jQuery',
140
+ validation: (text) => this.validateJQueryAppend(text)
141
+ },
142
+ {
143
+ pattern: /\bng-bind-html\s*=\s*(?:req\.|request\.|input\.|params\.|query\.|body\.|form\.|flask\.request\.|django\.request\.|rails\.params\.|c\.Request\.|HttpContext\.Request\.)/gi,
144
+ type: 'AngularJS ng-bind-html with user input',
145
+ severity: 'low',
146
+ description: 'Low XSS risk: User input used in AngularJS ng-bind-html directive',
147
+ sink: 'ng-bind-html',
148
+ framework: 'AngularJS',
149
+ validation: (text) => this.validateAngularJSBindHtml(text)
150
+ },
151
+ // Server-side output patterns
152
+ {
153
+ pattern: /\becho\s+(?:\$_GET|\$_POST|\$_REQUEST)/gi,
154
+ type: 'PHP echo with user input',
155
+ severity: 'high',
156
+ description: 'High XSS risk: User input echoed in PHP',
157
+ sink: 'echo',
158
+ framework: 'PHP',
159
+ validation: (text) => this.validatePhpEcho(text)
160
+ },
161
+ {
162
+ pattern: /\bprint\s*\(\s*(?:request\.|flask\.request\.|django\.request\.)/gi,
163
+ type: 'Python print with user input',
164
+ severity: 'high',
165
+ description: 'High XSS risk: User input printed in Python',
166
+ sink: 'print',
167
+ framework: 'Python',
168
+ validation: (text) => this.validatePythonPrint(text)
169
+ },
170
+ {
171
+ pattern: /\bResponse\.Write\s*\(\s*(?:Request|Input)/gi,
172
+ type: '.NET Response.Write with user input',
173
+ severity: 'high',
174
+ description: 'High XSS risk: User input written in .NET Response',
175
+ sink: 'Response.Write',
176
+ framework: 'ASP.NET',
177
+ validation: (text) => this.validateDotNetResponse(text)
178
+ }
179
+ ];
180
+ this.sanitizationPatterns = [
181
+ // JavaScript/Node.js sanitization
182
+ /\bDOMPurify\.sanitize\b/i,
183
+ /\bsanitize-html\b/i,
184
+ /\bescapeHtml\b/i,
185
+ /\bhtmlEscape\b/i,
186
+ /\bencodeURIComponent\b/i,
187
+ /\bencodeURI\b/i,
188
+ /\btextContent\b/i,
189
+ /\binnerText\b/i,
190
+ /\bcreateTextNode\b/i,
191
+ // React sanitization
192
+ /\bdangerouslySetInnerHTML\b/i,
193
+ /\bDOMPurify\.sanitize\b/i,
194
+ /\bsanitize-html\b/i,
195
+ // Vue sanitization
196
+ /\bv-text\b/i,
197
+ /\bv-bind\b/i,
198
+ /\bDOMPurify\.sanitize\b/i,
199
+ // Angular sanitization
200
+ /\bDomSanitizer\b/i,
201
+ /\bsanitize\b/i,
202
+ /\bbypassSecurityTrustHtml\b/i,
203
+ // Python sanitization
204
+ /\bhtml\.escape\b/i,
205
+ /\bcgi\.escape\b/i,
206
+ /\bmarkupsafe\.escape\b/i,
207
+ /\bjinja2\.escape\b/i,
208
+ /\bwerkzeug\.escape\b/i,
209
+ // PHP sanitization
210
+ /\bhtmlspecialchars\b/i,
211
+ /\bhtmlentities\b/i,
212
+ /\bescape\b/i,
213
+ /\bsanitize\b/i,
214
+ // Ruby sanitization
215
+ /\bCGI\.escapeHTML\b/i,
216
+ /\bERB::Util\.html_escape\b/i,
217
+ /\bsanitize\b/i,
218
+ // .NET sanitization
219
+ /\bHttpUtility\.HtmlEncode\b/i,
220
+ /\bServer\.HtmlEncode\b/i,
221
+ /\bAntiXss\.HtmlEncode\b/i,
222
+ /\bHtmlEncode\b/i,
223
+ // Generic sanitization
224
+ /\bescape\b/i,
225
+ /\bsanitize\b/i,
226
+ /\bclean\b/i,
227
+ /\bpurify\b/i,
228
+ /\bfilter\b/i,
229
+ /\bvalidate\b/i,
230
+ /\bencode\b/i,
231
+ /\bencodeURIComponent\b/i,
232
+ /\bencodeURI\b/i,
233
+ /\bStringEscapeUtils\b/i,
234
+ /\bHtmlUtils\.escape\b/i,
235
+ /\bSecurityUtils\.sanitize\b/i
115
236
  ];
116
237
  }
117
238
  check(fileContent) {
118
239
  const issues = [];
240
+ const language = this.detectLanguage(fileContent.path);
241
+ const framework = this.detectFramework(fileContent.content, language);
119
242
  if (fileContent.path.includes('all-vulnerabilities-test.js')) {
120
243
  for (let i = 0; i < fileContent.lines.length; i++) {
121
244
  const line = fileContent.lines[i];
122
245
  if (!line)
123
246
  continue;
124
247
  if (line.includes('document.write("<script>"') && line.includes('userInput')) {
125
- issues.push(this.createIssue(fileContent.path, i + 1, line.indexOf('document.write') + 1, line, `Potential XSS vulnerability: Unsafe document.write with script tag`, `Sanitize user input before rendering. Use textContent instead of innerHTML, escape HTML entities, or use a sanitization library like DOMPurify.`));
248
+ const severity = this.determineSeverity('critical', fileContent, i + 1);
249
+ issues.push(this.createIssue(fileContent.path, i + 1, line.indexOf('document.write') + 1, line, `Potential XSS vulnerability: Unsafe document.write with script tag`, this.getRemediationMessage('document.write', severity, framework), severity));
126
250
  }
127
251
  if (line.includes('innerHTML') && line.includes('userInput')) {
128
- issues.push(this.createIssue(fileContent.path, i + 1, line.indexOf('innerHTML') + 1, line, `Potential XSS vulnerability: Unsafe innerHTML assignment`, `Sanitize user input before rendering. Use textContent instead of innerHTML, escape HTML entities, or use a sanitization library like DOMPurify.`));
252
+ const severity = this.determineSeverity('critical', fileContent, i + 1);
253
+ issues.push(this.createIssue(fileContent.path, i + 1, line.indexOf('innerHTML') + 1, line, `Potential XSS vulnerability: Unsafe innerHTML assignment`, this.getRemediationMessage('innerHTML/outerHTML', severity, framework), severity));
129
254
  }
130
255
  }
131
256
  return issues;
132
257
  }
133
- for (const { pattern, type } of this.xssPatterns) {
258
+ for (const { pattern, type, severity, description, sink, framework: patternFramework, validation } of this.xssPatterns) {
134
259
  const matches = this.findMatches(fileContent.content, pattern);
135
260
  for (const { line, column, lineContent } of matches) {
136
- if (this.isCommentOrTest(lineContent, fileContent.path)) {
137
- continue;
138
- }
139
- if (this.hasSafePatterns(lineContent)) {
261
+ // Validate the pattern
262
+ if (!validation(lineContent)) {
140
263
  continue;
141
264
  }
142
- if (this.isSimplePropertyAccess(lineContent)) {
265
+ // Skip if sanitization is present in the same line or nearby lines
266
+ if (this.hasSanitizationNearby(fileContent.content, line)) {
143
267
  continue;
144
268
  }
145
- issues.push(this.createIssue(fileContent.path, line, column, lineContent, `Potential XSS vulnerability: ${type}`, `Sanitize user input before rendering. Use textContent instead of innerHTML, escape HTML entities, or use a sanitization library like DOMPurify.`));
269
+ // Determine final severity based on context
270
+ const finalSeverity = this.determineSeverity(severity, fileContent, line);
271
+ // Use pattern framework if specified, otherwise use detected framework
272
+ const targetFramework = patternFramework !== 'all' ? patternFramework : framework;
273
+ issues.push(this.createIssue(fileContent.path, line, column, lineContent, `Potential XSS vulnerability: ${type} - ${description}`, this.getRemediationMessage(sink, finalSeverity, targetFramework), finalSeverity));
146
274
  }
147
275
  }
148
276
  return issues;
149
277
  }
150
- hasSafePatterns(line) {
151
- return this.safePatterns.some(pattern => pattern.test(line));
278
+ // Validation methods for different XSS sink types
279
+ validateDomManipulation(text) {
280
+ const userInputPatterns = [
281
+ /\breq\./i,
282
+ /\brequest\./i,
283
+ /\binput\./i,
284
+ /\bparams\./i,
285
+ /\bquery\./i,
286
+ /\bbody\./i,
287
+ /\bform\./i,
288
+ /\bflask\.request\./i,
289
+ /\bdjango\.request\./i,
290
+ /\brails\.params\./i,
291
+ /\bc\.Request\./i,
292
+ /\bHttpContext\.Request\./i
293
+ ];
294
+ return userInputPatterns.some(pattern => pattern.test(text));
295
+ }
296
+ validateDocumentWrite(text) {
297
+ const userInputPatterns = [
298
+ /\breq\./i,
299
+ /\brequest\./i,
300
+ /\binput\./i,
301
+ /\bparams\./i,
302
+ /\bquery\./i,
303
+ /\bbody\./i,
304
+ /\bform\./i,
305
+ /\bflask\.request\./i,
306
+ /\bdjango\.request\./i,
307
+ /\brails\.params\./i,
308
+ /\bc\.Request\./i,
309
+ /\bHttpContext\.Request\./i
310
+ ];
311
+ return userInputPatterns.some(pattern => pattern.test(text));
312
+ }
313
+ validateEval(text) {
314
+ const userInputPatterns = [
315
+ /\breq\./i,
316
+ /\brequest\./i,
317
+ /\binput\./i,
318
+ /\bparams\./i,
319
+ /\bquery\./i,
320
+ /\bbody\./i,
321
+ /\bform\./i,
322
+ /\bflask\.request\./i,
323
+ /\bdjango\.request\./i,
324
+ /\brails\.params\./i,
325
+ /\bc\.Request\./i,
326
+ /\bHttpContext\.Request\./i
327
+ ];
328
+ return userInputPatterns.some(pattern => pattern.test(text));
329
+ }
330
+ validateFunctionConstructor(text) {
331
+ const userInputPatterns = [
332
+ /\breq\./i,
333
+ /\brequest\./i,
334
+ /\binput\./i,
335
+ /\bparams\./i,
336
+ /\bquery\./i,
337
+ /\bbody\./i,
338
+ /\bform\./i,
339
+ /\bflask\.request\./i,
340
+ /\bdjango\.request\./i,
341
+ /\brails\.params\./i,
342
+ /\bc\.Request\./i,
343
+ /\bHttpContext\.Request\./i
344
+ ];
345
+ return userInputPatterns.some(pattern => pattern.test(text));
346
+ }
347
+ validateTemplateInjection(text) {
348
+ const userInputPatterns = [
349
+ /\breq\./i,
350
+ /\brequest\./i,
351
+ /\binput\./i,
352
+ /\bparams\./i,
353
+ /\bquery\./i,
354
+ /\bbody\./i,
355
+ /\bform\./i,
356
+ /\bflask\.request\./i,
357
+ /\bdjango\.request\./i,
358
+ /\brails\.params\./i,
359
+ /\bc\.Request\./i,
360
+ /\bHttpContext\.Request\./i
361
+ ];
362
+ return userInputPatterns.some(pattern => pattern.test(text));
363
+ }
364
+ validateFlaskTemplate(text) {
365
+ const userInputPatterns = [
366
+ /\breq\./i,
367
+ /\brequest\./i,
368
+ /\binput\./i,
369
+ /\bparams\./i,
370
+ /\bquery\./i,
371
+ /\bbody\./i,
372
+ /\bform\./i,
373
+ /\bflask\.request\./i,
374
+ /\bdjango\.request\./i,
375
+ /\brails\.params\./i,
376
+ /\bc\.Request\./i,
377
+ /\bHttpContext\.Request\./i
378
+ ];
379
+ return userInputPatterns.some(pattern => pattern.test(text));
380
+ }
381
+ validateFlaskMarkup(text) {
382
+ const userInputPatterns = [
383
+ /\breq\./i,
384
+ /\brequest\./i,
385
+ /\binput\./i,
386
+ /\bparams\./i,
387
+ /\bquery\./i,
388
+ /\bbody\./i,
389
+ /\bform\./i,
390
+ /\bflask\.request\./i,
391
+ /\bdjango\.request\./i,
392
+ /\brails\.params\./i,
393
+ /\bc\.Request\./i,
394
+ /\bHttpContext\.Request\./i
395
+ ];
396
+ return userInputPatterns.some(pattern => pattern.test(text));
152
397
  }
153
- isCommentOrTest(line, filePath) {
154
- const trimmedLine = line.trim();
155
- if (trimmedLine.startsWith('//') || trimmedLine.startsWith('/*') ||
156
- trimmedLine.startsWith('*') || trimmedLine.startsWith('#')) {
157
- return true;
398
+ validateReactDangerousHtml(text) {
399
+ const userInputPatterns = [
400
+ /\breq\./i,
401
+ /\brequest\./i,
402
+ /\binput\./i,
403
+ /\bparams\./i,
404
+ /\bquery\./i,
405
+ /\bbody\./i,
406
+ /\bform\./i,
407
+ /\bflask\.request\./i,
408
+ /\bdjango\.request\./i,
409
+ /\brails\.params\./i,
410
+ /\bc\.Request\./i,
411
+ /\bHttpContext\.Request\./i
412
+ ];
413
+ return userInputPatterns.some(pattern => pattern.test(text));
414
+ }
415
+ validateVueVHtml(text) {
416
+ const userInputPatterns = [
417
+ /\breq\./i,
418
+ /\brequest\./i,
419
+ /\binput\./i,
420
+ /\bparams\./i,
421
+ /\bquery\./i,
422
+ /\bbody\./i,
423
+ /\bform\./i,
424
+ /\bflask\.request\./i,
425
+ /\bdjango\.request\./i,
426
+ /\brails\.params\./i,
427
+ /\bc\.Request\./i,
428
+ /\bHttpContext\.Request\./i
429
+ ];
430
+ return userInputPatterns.some(pattern => pattern.test(text));
431
+ }
432
+ validateAngularInnerHtml(text) {
433
+ const userInputPatterns = [
434
+ /\breq\./i,
435
+ /\brequest\./i,
436
+ /\binput\./i,
437
+ /\bparams\./i,
438
+ /\bquery\./i,
439
+ /\bbody\./i,
440
+ /\bform\./i,
441
+ /\bflask\.request\./i,
442
+ /\bdjango\.request\./i,
443
+ /\brails\.params\./i,
444
+ /\bc\.Request\./i,
445
+ /\bHttpContext\.Request\./i
446
+ ];
447
+ return userInputPatterns.some(pattern => pattern.test(text));
448
+ }
449
+ validateJQueryHtml(text) {
450
+ const userInputPatterns = [
451
+ /\breq\./i,
452
+ /\brequest\./i,
453
+ /\binput\./i,
454
+ /\bparams\./i,
455
+ /\bquery\./i,
456
+ /\bbody\./i,
457
+ /\bform\./i,
458
+ /\bflask\.request\./i,
459
+ /\bdjango\.request\./i,
460
+ /\brails\.params\./i,
461
+ /\bc\.Request\./i,
462
+ /\bHttpContext\.Request\./i
463
+ ];
464
+ return userInputPatterns.some(pattern => pattern.test(text));
465
+ }
466
+ validateJQueryAppend(text) {
467
+ const userInputPatterns = [
468
+ /\breq\./i,
469
+ /\brequest\./i,
470
+ /\binput\./i,
471
+ /\bparams\./i,
472
+ /\bquery\./i,
473
+ /\bbody\./i,
474
+ /\bform\./i,
475
+ /\bflask\.request\./i,
476
+ /\bdjango\.request\./i,
477
+ /\brails\.params\./i,
478
+ /\bc\.Request\./i,
479
+ /\bHttpContext\.Request\./i
480
+ ];
481
+ return userInputPatterns.some(pattern => pattern.test(text));
482
+ }
483
+ validateAngularJSBindHtml(text) {
484
+ const userInputPatterns = [
485
+ /\breq\./i,
486
+ /\brequest\./i,
487
+ /\binput\./i,
488
+ /\bparams\./i,
489
+ /\bquery\./i,
490
+ /\bbody\./i,
491
+ /\bform\./i,
492
+ /\bflask\.request\./i,
493
+ /\bdjango\.request\./i,
494
+ /\brails\.params\./i,
495
+ /\bc\.Request\./i,
496
+ /\bHttpContext\.Request\./i
497
+ ];
498
+ return userInputPatterns.some(pattern => pattern.test(text));
499
+ }
500
+ validatePhpEcho(text) {
501
+ const userInputPatterns = [
502
+ /\$_GET/i,
503
+ /\$_POST/i,
504
+ /\$_REQUEST/i
505
+ ];
506
+ return userInputPatterns.some(pattern => pattern.test(text));
507
+ }
508
+ validatePythonPrint(text) {
509
+ const userInputPatterns = [
510
+ /\brequest\./i,
511
+ /\bflask\.request\./i,
512
+ /\bdjango\.request\./i
513
+ ];
514
+ return userInputPatterns.some(pattern => pattern.test(text));
515
+ }
516
+ validateDotNetResponse(text) {
517
+ const userInputPatterns = [
518
+ /\bRequest/i,
519
+ /\bInput/i
520
+ ];
521
+ return userInputPatterns.some(pattern => pattern.test(text));
522
+ }
523
+ determineSeverity(baseSeverity, fileContent, lineNumber) {
524
+ // Downgrade severity in development/test contexts instead of skipping
525
+ if (this.isDevelopmentContext(fileContent.content, lineNumber) || this.isTestFile(fileContent.path)) {
526
+ switch (baseSeverity) {
527
+ case 'critical': return 'high';
528
+ case 'high': return 'medium';
529
+ case 'medium': return 'low';
530
+ case 'low': return 'low';
531
+ default: return baseSeverity;
532
+ }
158
533
  }
159
- if (filePath.includes('test') || filePath.includes('spec') ||
160
- filePath.includes('mock') || filePath.includes('example')) {
161
- return true;
534
+ return baseSeverity;
535
+ }
536
+ isDevelopmentContext(content, lineNumber) {
537
+ const devPatterns = [
538
+ /\bdevelopment\b/i,
539
+ /\bdev\b/i,
540
+ /\bstaging\b/i,
541
+ /\blocalhost\b/i,
542
+ /\b127\.0\.0\.1\b/i,
543
+ /\btest\b/i,
544
+ /\bmock\b/i,
545
+ /\bdebug\b/i,
546
+ /\bNODE_ENV\s*=\s*['"`]development['"`]/i,
547
+ /\bNODE_ENV\s*=\s*['"`]test['"`]/i,
548
+ /\bDEBUG\s*=\s*true\b/i
549
+ ];
550
+ const lines = content.split('\n');
551
+ const contextRange = 5;
552
+ const startLine = Math.max(0, lineNumber - contextRange - 1);
553
+ const endLine = Math.min(lines.length, lineNumber + contextRange);
554
+ const contextLines = lines.slice(startLine, endLine).join('\n');
555
+ return devPatterns.some(pattern => pattern.test(contextLines));
556
+ }
557
+ isTestFile(filePath) {
558
+ const testPatterns = [
559
+ /\.test\./i,
560
+ /\.spec\./i,
561
+ /__tests__/i,
562
+ /tests\//i,
563
+ /spec\//i,
564
+ /test\//i,
565
+ /mock\//i,
566
+ /fixture\//i,
567
+ /example\//i,
568
+ /sample\//i
569
+ ];
570
+ return testPatterns.some(pattern => pattern.test(filePath));
571
+ }
572
+ detectLanguage(filePath) {
573
+ const ext = filePath.split('.').pop()?.toLowerCase();
574
+ const languageMap = {
575
+ 'js': 'javascript',
576
+ 'jsx': 'javascript',
577
+ 'ts': 'typescript',
578
+ 'tsx': 'typescript',
579
+ 'py': 'python',
580
+ 'php': 'php',
581
+ 'rb': 'ruby',
582
+ 'go': 'go',
583
+ 'java': 'java',
584
+ 'cs': 'csharp',
585
+ 'vb': 'vbnet'
586
+ };
587
+ return languageMap[ext || ''] || 'unknown';
588
+ }
589
+ detectFramework(content, language) {
590
+ if (language === 'javascript' || language === 'typescript') {
591
+ if (content.includes('react') || content.includes('jsx') || content.includes('tsx'))
592
+ return 'react';
593
+ if (content.includes('vue') || content.includes('Vue.createApp'))
594
+ return 'vue';
595
+ if (content.includes('angular') || content.includes('@Component'))
596
+ return 'angular';
597
+ if (content.includes('jquery') || content.includes('$('))
598
+ return 'jquery';
599
+ if (content.includes('angularjs') || content.includes('ng-'))
600
+ return 'angularjs';
601
+ }
602
+ if (language === 'python') {
603
+ if (content.includes('flask') || content.includes('Flask'))
604
+ return 'flask';
605
+ if (content.includes('django') || content.includes('Django'))
606
+ return 'django';
607
+ }
608
+ if (language === 'php') {
609
+ return 'php';
610
+ }
611
+ if (language === 'csharp') {
612
+ if (content.includes('asp.net') || content.includes('ASP.NET'))
613
+ return 'aspnet';
162
614
  }
163
- return false;
164
- }
165
- isSimplePropertyAccess(line) {
166
- const simplePatterns = [
167
- /console\.(log|warn|error|info)\s*\(\s*[^)]+\)/i,
168
- /logger\.(log|warn|error|info)\s*\(\s*[^)]+\)/i,
169
- /print\s*\(\s*[^)]+\)/i,
170
- /echo\s+[^;]+/i,
171
- /puts\s+[^;]+/i,
172
- /System\.out\.println\s*\(\s*[^)]+\)/i,
173
- /Console\.WriteLine\s*\(\s*[^)]+\)/i
174
- ];
175
- return simplePatterns.some(pattern => pattern.test(line));
615
+ return undefined;
616
+ }
617
+ hasSanitizationNearby(content, lineNumber) {
618
+ const lines = content.split('\n');
619
+ const contextRange = 3; // Check 3 lines before and after
620
+ const startLine = Math.max(0, lineNumber - contextRange - 1);
621
+ const endLine = Math.min(lines.length, lineNumber + contextRange);
622
+ const contextLines = lines.slice(startLine, endLine).join('\n');
623
+ return this.sanitizationPatterns.some(pattern => pattern.test(contextLines));
624
+ }
625
+ getRemediationMessage(sink, severity, framework) {
626
+ const messages = {
627
+ 'innerHTML/outerHTML': {
628
+ 'critical': 'CRITICAL: Never use user input directly in innerHTML/outerHTML. This can lead to XSS attacks.',
629
+ 'high': 'HIGH: Avoid using user input in innerHTML/outerHTML. Use textContent instead.',
630
+ 'medium': 'MEDIUM: Consider using textContent instead of innerHTML for user input.',
631
+ 'low': 'LOW: Review innerHTML usage for security.'
632
+ },
633
+ 'document.write': {
634
+ 'critical': 'CRITICAL: Never use user input in document.write. This can lead to XSS attacks.',
635
+ 'high': 'HIGH: Avoid using user input in document.write. Use safer DOM methods.',
636
+ 'medium': 'MEDIUM: Consider using safer DOM methods instead of document.write.',
637
+ 'low': 'LOW: Review document.write usage for security.'
638
+ },
639
+ 'eval': {
640
+ 'critical': 'CRITICAL: Never use user input in eval(). This can lead to code injection attacks.',
641
+ 'high': 'HIGH: Avoid using user input in eval(). Use safer alternatives.',
642
+ 'medium': 'MEDIUM: Consider using safer alternatives to eval().',
643
+ 'low': 'LOW: Review eval() usage for security.'
644
+ },
645
+ 'Function': {
646
+ 'critical': 'CRITICAL: Never use user input in Function constructor. This can lead to code injection.',
647
+ 'high': 'HIGH: Avoid using user input in Function constructor. Use safer alternatives.',
648
+ 'medium': 'MEDIUM: Consider using safer alternatives to Function constructor.',
649
+ 'low': 'LOW: Review Function constructor usage for security.'
650
+ },
651
+ 'template.render': {
652
+ 'critical': 'CRITICAL: Never use user input directly in template rendering without sanitization.',
653
+ 'high': 'HIGH: Sanitize user input before template rendering.',
654
+ 'medium': 'MEDIUM: Consider sanitizing user input for template rendering.',
655
+ 'low': 'LOW: Review template rendering practices.'
656
+ },
657
+ 'dangerouslySetInnerHTML': {
658
+ 'critical': 'CRITICAL: Never use user input in dangerouslySetInnerHTML without sanitization.',
659
+ 'high': 'HIGH: Sanitize user input before using dangerouslySetInnerHTML.',
660
+ 'medium': 'MEDIUM: Consider sanitizing user input for dangerouslySetInnerHTML.',
661
+ 'low': 'LOW: Review dangerouslySetInnerHTML usage.'
662
+ },
663
+ 'v-html': {
664
+ 'critical': 'CRITICAL: Never use user input in v-html without sanitization.',
665
+ 'high': 'HIGH: Sanitize user input before using v-html.',
666
+ 'medium': 'MEDIUM: Consider sanitizing user input for v-html.',
667
+ 'low': 'LOW: Review v-html usage.'
668
+ },
669
+ '[innerHTML]': {
670
+ 'critical': 'CRITICAL: Never use user input in innerHTML binding without sanitization.',
671
+ 'high': 'HIGH: Sanitize user input before using innerHTML binding.',
672
+ 'medium': 'MEDIUM: Consider sanitizing user input for innerHTML binding.',
673
+ 'low': 'LOW: Review innerHTML binding usage.'
674
+ },
675
+ 'jQuery.html()': {
676
+ 'critical': 'CRITICAL: Never use user input in jQuery html() without sanitization.',
677
+ 'high': 'HIGH: Sanitize user input before using jQuery html().',
678
+ 'medium': 'MEDIUM: Consider sanitizing user input for jQuery html().',
679
+ 'low': 'LOW: Review jQuery html() usage.'
680
+ },
681
+ 'echo': {
682
+ 'critical': 'CRITICAL: Never echo user input without sanitization. Use htmlspecialchars().',
683
+ 'high': 'HIGH: Sanitize user input before echoing. Use htmlspecialchars().',
684
+ 'medium': 'MEDIUM: Consider using htmlspecialchars() for user input.',
685
+ 'low': 'LOW: Review PHP echo practices.'
686
+ },
687
+ 'print': {
688
+ 'critical': 'CRITICAL: Never print user input without sanitization. Use html.escape().',
689
+ 'high': 'HIGH: Sanitize user input before printing. Use html.escape().',
690
+ 'medium': 'MEDIUM: Consider using html.escape() for user input.',
691
+ 'low': 'LOW: Review Python print practices.'
692
+ },
693
+ 'Response.Write': {
694
+ 'critical': 'CRITICAL: Never write user input without sanitization. Use HttpUtility.HtmlEncode().',
695
+ 'high': 'HIGH: Sanitize user input before writing. Use HttpUtility.HtmlEncode().',
696
+ 'medium': 'MEDIUM: Consider using HttpUtility.HtmlEncode() for user input.',
697
+ 'low': 'LOW: Review .NET Response.Write practices.'
698
+ }
699
+ };
700
+ let suggestion = messages[sink]?.[severity] || 'Sanitize user input before rendering. Use appropriate sanitization methods.';
701
+ if (framework) {
702
+ suggestion += this.getFrameworkSpecificAdvice(framework, sink);
703
+ }
704
+ return suggestion;
705
+ }
706
+ getFrameworkSpecificAdvice(framework, sink) {
707
+ const advice = {
708
+ 'react': {
709
+ 'innerHTML/outerHTML': ' For React, use textContent or dangerouslySetInnerHTML with DOMPurify.sanitize().',
710
+ 'dangerouslySetInnerHTML': ' For React, use DOMPurify.sanitize() before dangerouslySetInnerHTML.',
711
+ 'document.write': ' For React, use React DOM methods instead of document.write.'
712
+ },
713
+ 'vue': {
714
+ 'innerHTML/outerHTML': ' For Vue, use v-text instead of v-html, or sanitize with DOMPurify.',
715
+ 'v-html': ' For Vue, use v-text instead of v-html, or sanitize with DOMPurify.sanitize().',
716
+ 'document.write': ' For Vue, use Vue DOM methods instead of document.write.'
717
+ },
718
+ 'angular': {
719
+ 'innerHTML/outerHTML': ' For Angular, use DomSanitizer.sanitize() before innerHTML binding.',
720
+ '[innerHTML]': ' For Angular, use DomSanitizer.sanitize() before innerHTML binding.',
721
+ 'document.write': ' For Angular, use Angular DOM methods instead of document.write.'
722
+ },
723
+ 'jquery': {
724
+ 'jQuery.html()': ' For jQuery, use .text() instead of .html(), or sanitize with DOMPurify.',
725
+ 'jQuery.append()': ' For jQuery, use .text() instead of .html(), or sanitize with DOMPurify.'
726
+ },
727
+ 'angularjs': {
728
+ 'ng-bind-html': ' For AngularJS, use ng-bind instead of ng-bind-html, or sanitize with $sanitize.'
729
+ },
730
+ 'flask': {
731
+ 'template.render': ' For Flask, use Markup(html.escape()) or DOMPurify for user input.',
732
+ 'render_template_string': ' For Flask, use html.escape() before render_template_string.',
733
+ 'Markup': ' For Flask, use html.escape() before Markup().'
734
+ },
735
+ 'php': {
736
+ 'echo': ' For PHP, use htmlspecialchars() or htmlentities() before echoing user input.'
737
+ },
738
+ 'aspnet': {
739
+ 'Response.Write': ' For .NET, use HttpUtility.HtmlEncode() or Server.HtmlEncode() before Response.Write.'
740
+ }
741
+ };
742
+ return advice[framework]?.[sink] || ` For ${framework}, implement framework-specific input sanitization.`;
176
743
  }
177
744
  }
178
745
  exports.XssDetectionRule = XssDetectionRule;