@oculum/scanner 1.0.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 (281) hide show
  1. package/dist/formatters/cli-terminal.d.ts +27 -0
  2. package/dist/formatters/cli-terminal.d.ts.map +1 -0
  3. package/dist/formatters/cli-terminal.js +412 -0
  4. package/dist/formatters/cli-terminal.js.map +1 -0
  5. package/dist/formatters/github-comment.d.ts +41 -0
  6. package/dist/formatters/github-comment.d.ts.map +1 -0
  7. package/dist/formatters/github-comment.js +306 -0
  8. package/dist/formatters/github-comment.js.map +1 -0
  9. package/dist/formatters/grouping.d.ts +52 -0
  10. package/dist/formatters/grouping.d.ts.map +1 -0
  11. package/dist/formatters/grouping.js +152 -0
  12. package/dist/formatters/grouping.js.map +1 -0
  13. package/dist/formatters/index.d.ts +9 -0
  14. package/dist/formatters/index.d.ts.map +1 -0
  15. package/dist/formatters/index.js +35 -0
  16. package/dist/formatters/index.js.map +1 -0
  17. package/dist/formatters/vscode-diagnostic.d.ts +103 -0
  18. package/dist/formatters/vscode-diagnostic.d.ts.map +1 -0
  19. package/dist/formatters/vscode-diagnostic.js +151 -0
  20. package/dist/formatters/vscode-diagnostic.js.map +1 -0
  21. package/dist/index.d.ts +52 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +648 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/layer1/comments.d.ts +8 -0
  26. package/dist/layer1/comments.d.ts.map +1 -0
  27. package/dist/layer1/comments.js +203 -0
  28. package/dist/layer1/comments.js.map +1 -0
  29. package/dist/layer1/config-audit.d.ts +8 -0
  30. package/dist/layer1/config-audit.d.ts.map +1 -0
  31. package/dist/layer1/config-audit.js +252 -0
  32. package/dist/layer1/config-audit.js.map +1 -0
  33. package/dist/layer1/entropy.d.ts +8 -0
  34. package/dist/layer1/entropy.d.ts.map +1 -0
  35. package/dist/layer1/entropy.js +500 -0
  36. package/dist/layer1/entropy.js.map +1 -0
  37. package/dist/layer1/file-flags.d.ts +7 -0
  38. package/dist/layer1/file-flags.d.ts.map +1 -0
  39. package/dist/layer1/file-flags.js +112 -0
  40. package/dist/layer1/file-flags.js.map +1 -0
  41. package/dist/layer1/index.d.ts +36 -0
  42. package/dist/layer1/index.d.ts.map +1 -0
  43. package/dist/layer1/index.js +132 -0
  44. package/dist/layer1/index.js.map +1 -0
  45. package/dist/layer1/patterns.d.ts +8 -0
  46. package/dist/layer1/patterns.d.ts.map +1 -0
  47. package/dist/layer1/patterns.js +482 -0
  48. package/dist/layer1/patterns.js.map +1 -0
  49. package/dist/layer1/urls.d.ts +8 -0
  50. package/dist/layer1/urls.d.ts.map +1 -0
  51. package/dist/layer1/urls.js +296 -0
  52. package/dist/layer1/urls.js.map +1 -0
  53. package/dist/layer1/weak-crypto.d.ts +7 -0
  54. package/dist/layer1/weak-crypto.d.ts.map +1 -0
  55. package/dist/layer1/weak-crypto.js +291 -0
  56. package/dist/layer1/weak-crypto.js.map +1 -0
  57. package/dist/layer2/ai-agent-tools.d.ts +19 -0
  58. package/dist/layer2/ai-agent-tools.d.ts.map +1 -0
  59. package/dist/layer2/ai-agent-tools.js +528 -0
  60. package/dist/layer2/ai-agent-tools.js.map +1 -0
  61. package/dist/layer2/ai-endpoint-protection.d.ts +36 -0
  62. package/dist/layer2/ai-endpoint-protection.d.ts.map +1 -0
  63. package/dist/layer2/ai-endpoint-protection.js +332 -0
  64. package/dist/layer2/ai-endpoint-protection.js.map +1 -0
  65. package/dist/layer2/ai-execution-sinks.d.ts +18 -0
  66. package/dist/layer2/ai-execution-sinks.d.ts.map +1 -0
  67. package/dist/layer2/ai-execution-sinks.js +496 -0
  68. package/dist/layer2/ai-execution-sinks.js.map +1 -0
  69. package/dist/layer2/ai-fingerprinting.d.ts +7 -0
  70. package/dist/layer2/ai-fingerprinting.d.ts.map +1 -0
  71. package/dist/layer2/ai-fingerprinting.js +654 -0
  72. package/dist/layer2/ai-fingerprinting.js.map +1 -0
  73. package/dist/layer2/ai-prompt-hygiene.d.ts +19 -0
  74. package/dist/layer2/ai-prompt-hygiene.d.ts.map +1 -0
  75. package/dist/layer2/ai-prompt-hygiene.js +356 -0
  76. package/dist/layer2/ai-prompt-hygiene.js.map +1 -0
  77. package/dist/layer2/ai-rag-safety.d.ts +21 -0
  78. package/dist/layer2/ai-rag-safety.d.ts.map +1 -0
  79. package/dist/layer2/ai-rag-safety.js +459 -0
  80. package/dist/layer2/ai-rag-safety.js.map +1 -0
  81. package/dist/layer2/ai-schema-validation.d.ts +25 -0
  82. package/dist/layer2/ai-schema-validation.d.ts.map +1 -0
  83. package/dist/layer2/ai-schema-validation.js +375 -0
  84. package/dist/layer2/ai-schema-validation.js.map +1 -0
  85. package/dist/layer2/auth-antipatterns.d.ts +20 -0
  86. package/dist/layer2/auth-antipatterns.d.ts.map +1 -0
  87. package/dist/layer2/auth-antipatterns.js +333 -0
  88. package/dist/layer2/auth-antipatterns.js.map +1 -0
  89. package/dist/layer2/byok-patterns.d.ts +12 -0
  90. package/dist/layer2/byok-patterns.d.ts.map +1 -0
  91. package/dist/layer2/byok-patterns.js +299 -0
  92. package/dist/layer2/byok-patterns.js.map +1 -0
  93. package/dist/layer2/dangerous-functions.d.ts +7 -0
  94. package/dist/layer2/dangerous-functions.d.ts.map +1 -0
  95. package/dist/layer2/dangerous-functions.js +1375 -0
  96. package/dist/layer2/dangerous-functions.js.map +1 -0
  97. package/dist/layer2/data-exposure.d.ts +16 -0
  98. package/dist/layer2/data-exposure.d.ts.map +1 -0
  99. package/dist/layer2/data-exposure.js +279 -0
  100. package/dist/layer2/data-exposure.js.map +1 -0
  101. package/dist/layer2/framework-checks.d.ts +7 -0
  102. package/dist/layer2/framework-checks.d.ts.map +1 -0
  103. package/dist/layer2/framework-checks.js +388 -0
  104. package/dist/layer2/framework-checks.js.map +1 -0
  105. package/dist/layer2/index.d.ts +58 -0
  106. package/dist/layer2/index.d.ts.map +1 -0
  107. package/dist/layer2/index.js +380 -0
  108. package/dist/layer2/index.js.map +1 -0
  109. package/dist/layer2/logic-gates.d.ts +7 -0
  110. package/dist/layer2/logic-gates.d.ts.map +1 -0
  111. package/dist/layer2/logic-gates.js +182 -0
  112. package/dist/layer2/logic-gates.js.map +1 -0
  113. package/dist/layer2/risky-imports.d.ts +7 -0
  114. package/dist/layer2/risky-imports.d.ts.map +1 -0
  115. package/dist/layer2/risky-imports.js +161 -0
  116. package/dist/layer2/risky-imports.js.map +1 -0
  117. package/dist/layer2/variables.d.ts +8 -0
  118. package/dist/layer2/variables.d.ts.map +1 -0
  119. package/dist/layer2/variables.js +152 -0
  120. package/dist/layer2/variables.js.map +1 -0
  121. package/dist/layer3/anthropic.d.ts +83 -0
  122. package/dist/layer3/anthropic.d.ts.map +1 -0
  123. package/dist/layer3/anthropic.js +1745 -0
  124. package/dist/layer3/anthropic.js.map +1 -0
  125. package/dist/layer3/index.d.ts +24 -0
  126. package/dist/layer3/index.d.ts.map +1 -0
  127. package/dist/layer3/index.js +119 -0
  128. package/dist/layer3/index.js.map +1 -0
  129. package/dist/layer3/openai.d.ts +25 -0
  130. package/dist/layer3/openai.d.ts.map +1 -0
  131. package/dist/layer3/openai.js +238 -0
  132. package/dist/layer3/openai.js.map +1 -0
  133. package/dist/layer3/package-check.d.ts +63 -0
  134. package/dist/layer3/package-check.d.ts.map +1 -0
  135. package/dist/layer3/package-check.js +508 -0
  136. package/dist/layer3/package-check.js.map +1 -0
  137. package/dist/modes/incremental.d.ts +66 -0
  138. package/dist/modes/incremental.d.ts.map +1 -0
  139. package/dist/modes/incremental.js +200 -0
  140. package/dist/modes/incremental.js.map +1 -0
  141. package/dist/tiers.d.ts +125 -0
  142. package/dist/tiers.d.ts.map +1 -0
  143. package/dist/tiers.js +234 -0
  144. package/dist/tiers.js.map +1 -0
  145. package/dist/types.d.ts +175 -0
  146. package/dist/types.d.ts.map +1 -0
  147. package/dist/types.js +50 -0
  148. package/dist/types.js.map +1 -0
  149. package/dist/utils/auth-helper-detector.d.ts +56 -0
  150. package/dist/utils/auth-helper-detector.d.ts.map +1 -0
  151. package/dist/utils/auth-helper-detector.js +360 -0
  152. package/dist/utils/auth-helper-detector.js.map +1 -0
  153. package/dist/utils/context-helpers.d.ts +96 -0
  154. package/dist/utils/context-helpers.d.ts.map +1 -0
  155. package/dist/utils/context-helpers.js +493 -0
  156. package/dist/utils/context-helpers.js.map +1 -0
  157. package/dist/utils/diff-detector.d.ts +53 -0
  158. package/dist/utils/diff-detector.d.ts.map +1 -0
  159. package/dist/utils/diff-detector.js +104 -0
  160. package/dist/utils/diff-detector.js.map +1 -0
  161. package/dist/utils/diff-parser.d.ts +80 -0
  162. package/dist/utils/diff-parser.d.ts.map +1 -0
  163. package/dist/utils/diff-parser.js +202 -0
  164. package/dist/utils/diff-parser.js.map +1 -0
  165. package/dist/utils/imported-auth-detector.d.ts +37 -0
  166. package/dist/utils/imported-auth-detector.d.ts.map +1 -0
  167. package/dist/utils/imported-auth-detector.js +251 -0
  168. package/dist/utils/imported-auth-detector.js.map +1 -0
  169. package/dist/utils/middleware-detector.d.ts +55 -0
  170. package/dist/utils/middleware-detector.d.ts.map +1 -0
  171. package/dist/utils/middleware-detector.js +260 -0
  172. package/dist/utils/middleware-detector.js.map +1 -0
  173. package/dist/utils/oauth-flow-detector.d.ts +41 -0
  174. package/dist/utils/oauth-flow-detector.d.ts.map +1 -0
  175. package/dist/utils/oauth-flow-detector.js +202 -0
  176. package/dist/utils/oauth-flow-detector.js.map +1 -0
  177. package/dist/utils/path-exclusions.d.ts +55 -0
  178. package/dist/utils/path-exclusions.d.ts.map +1 -0
  179. package/dist/utils/path-exclusions.js +222 -0
  180. package/dist/utils/path-exclusions.js.map +1 -0
  181. package/dist/utils/project-context-builder.d.ts +119 -0
  182. package/dist/utils/project-context-builder.d.ts.map +1 -0
  183. package/dist/utils/project-context-builder.js +534 -0
  184. package/dist/utils/project-context-builder.js.map +1 -0
  185. package/dist/utils/registry-clients.d.ts +93 -0
  186. package/dist/utils/registry-clients.d.ts.map +1 -0
  187. package/dist/utils/registry-clients.js +273 -0
  188. package/dist/utils/registry-clients.js.map +1 -0
  189. package/dist/utils/trpc-analyzer.d.ts +78 -0
  190. package/dist/utils/trpc-analyzer.d.ts.map +1 -0
  191. package/dist/utils/trpc-analyzer.js +297 -0
  192. package/dist/utils/trpc-analyzer.js.map +1 -0
  193. package/package.json +45 -0
  194. package/src/__tests__/benchmark/fixtures/false-positives.ts +227 -0
  195. package/src/__tests__/benchmark/fixtures/index.ts +68 -0
  196. package/src/__tests__/benchmark/fixtures/layer1/config-audit.ts +364 -0
  197. package/src/__tests__/benchmark/fixtures/layer1/hardcoded-secrets.ts +173 -0
  198. package/src/__tests__/benchmark/fixtures/layer1/high-entropy.ts +234 -0
  199. package/src/__tests__/benchmark/fixtures/layer1/index.ts +31 -0
  200. package/src/__tests__/benchmark/fixtures/layer1/sensitive-urls.ts +90 -0
  201. package/src/__tests__/benchmark/fixtures/layer1/weak-crypto.ts +197 -0
  202. package/src/__tests__/benchmark/fixtures/layer2/ai-agent-tools.ts +170 -0
  203. package/src/__tests__/benchmark/fixtures/layer2/ai-endpoint-protection.ts +418 -0
  204. package/src/__tests__/benchmark/fixtures/layer2/ai-execution-sinks.ts +189 -0
  205. package/src/__tests__/benchmark/fixtures/layer2/ai-fingerprinting.ts +316 -0
  206. package/src/__tests__/benchmark/fixtures/layer2/ai-prompt-hygiene.ts +178 -0
  207. package/src/__tests__/benchmark/fixtures/layer2/ai-rag-safety.ts +184 -0
  208. package/src/__tests__/benchmark/fixtures/layer2/ai-schema-validation.ts +434 -0
  209. package/src/__tests__/benchmark/fixtures/layer2/auth-antipatterns.ts +159 -0
  210. package/src/__tests__/benchmark/fixtures/layer2/byok-patterns.ts +112 -0
  211. package/src/__tests__/benchmark/fixtures/layer2/dangerous-functions.ts +246 -0
  212. package/src/__tests__/benchmark/fixtures/layer2/data-exposure.ts +168 -0
  213. package/src/__tests__/benchmark/fixtures/layer2/framework-checks.ts +346 -0
  214. package/src/__tests__/benchmark/fixtures/layer2/index.ts +67 -0
  215. package/src/__tests__/benchmark/fixtures/layer2/injection-vulnerabilities.ts +239 -0
  216. package/src/__tests__/benchmark/fixtures/layer2/logic-gates.ts +246 -0
  217. package/src/__tests__/benchmark/fixtures/layer2/risky-imports.ts +231 -0
  218. package/src/__tests__/benchmark/fixtures/layer2/variables.ts +167 -0
  219. package/src/__tests__/benchmark/index.ts +29 -0
  220. package/src/__tests__/benchmark/run-benchmark.ts +144 -0
  221. package/src/__tests__/benchmark/run-depth-validation.ts +206 -0
  222. package/src/__tests__/benchmark/run-real-world-test.ts +243 -0
  223. package/src/__tests__/benchmark/security-benchmark-script.ts +1737 -0
  224. package/src/__tests__/benchmark/tier-integration-script.ts +177 -0
  225. package/src/__tests__/benchmark/types.ts +144 -0
  226. package/src/__tests__/benchmark/utils/test-runner.ts +475 -0
  227. package/src/__tests__/regression/known-false-positives.test.ts +467 -0
  228. package/src/__tests__/snapshots/__snapshots__/scan-depth.test.ts.snap +178 -0
  229. package/src/__tests__/snapshots/scan-depth.test.ts +258 -0
  230. package/src/__tests__/validation/analyze-results.ts +542 -0
  231. package/src/__tests__/validation/extract-for-triage.ts +146 -0
  232. package/src/__tests__/validation/fp-deep-analysis.ts +327 -0
  233. package/src/__tests__/validation/run-validation.ts +364 -0
  234. package/src/__tests__/validation/triage-template.md +132 -0
  235. package/src/formatters/cli-terminal.ts +446 -0
  236. package/src/formatters/github-comment.ts +382 -0
  237. package/src/formatters/grouping.ts +190 -0
  238. package/src/formatters/index.ts +47 -0
  239. package/src/formatters/vscode-diagnostic.ts +243 -0
  240. package/src/index.ts +823 -0
  241. package/src/layer1/comments.ts +218 -0
  242. package/src/layer1/config-audit.ts +289 -0
  243. package/src/layer1/entropy.ts +583 -0
  244. package/src/layer1/file-flags.ts +127 -0
  245. package/src/layer1/index.ts +181 -0
  246. package/src/layer1/patterns.ts +516 -0
  247. package/src/layer1/urls.ts +334 -0
  248. package/src/layer1/weak-crypto.ts +328 -0
  249. package/src/layer2/ai-agent-tools.ts +601 -0
  250. package/src/layer2/ai-endpoint-protection.ts +387 -0
  251. package/src/layer2/ai-execution-sinks.ts +580 -0
  252. package/src/layer2/ai-fingerprinting.ts +758 -0
  253. package/src/layer2/ai-prompt-hygiene.ts +411 -0
  254. package/src/layer2/ai-rag-safety.ts +511 -0
  255. package/src/layer2/ai-schema-validation.ts +421 -0
  256. package/src/layer2/auth-antipatterns.ts +394 -0
  257. package/src/layer2/byok-patterns.ts +336 -0
  258. package/src/layer2/dangerous-functions.ts +1563 -0
  259. package/src/layer2/data-exposure.ts +315 -0
  260. package/src/layer2/framework-checks.ts +433 -0
  261. package/src/layer2/index.ts +473 -0
  262. package/src/layer2/logic-gates.ts +206 -0
  263. package/src/layer2/risky-imports.ts +186 -0
  264. package/src/layer2/variables.ts +166 -0
  265. package/src/layer3/anthropic.ts +2030 -0
  266. package/src/layer3/index.ts +130 -0
  267. package/src/layer3/package-check.ts +604 -0
  268. package/src/modes/incremental.ts +293 -0
  269. package/src/tiers.ts +318 -0
  270. package/src/types.ts +284 -0
  271. package/src/utils/auth-helper-detector.ts +443 -0
  272. package/src/utils/context-helpers.ts +535 -0
  273. package/src/utils/diff-detector.ts +135 -0
  274. package/src/utils/diff-parser.ts +272 -0
  275. package/src/utils/imported-auth-detector.ts +320 -0
  276. package/src/utils/middleware-detector.ts +333 -0
  277. package/src/utils/oauth-flow-detector.ts +246 -0
  278. package/src/utils/path-exclusions.ts +266 -0
  279. package/src/utils/project-context-builder.ts +707 -0
  280. package/src/utils/registry-clients.ts +351 -0
  281. package/src/utils/trpc-analyzer.ts +382 -0
@@ -0,0 +1,528 @@
1
+ "use strict";
2
+ /**
3
+ * Layer 2: AI Agent Tool Permission Detection
4
+ * Detects overly permissive agent tools and missing authorization checks
5
+ *
6
+ * Covers B4: Agent/tool orchestration logic
7
+ *
8
+ * Issues detected:
9
+ * - Tools with unrestricted file system access
10
+ * - Tools with unrestricted network access
11
+ * - Tools with shell/code execution capability
12
+ * - Tools without user/tenant context verification
13
+ * - Database tools without proper scoping
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.detectAIAgentTools = detectAIAgentTools;
17
+ const context_helpers_1 = require("../utils/context-helpers");
18
+ // ============================================================================
19
+ // Agent/Tool Context Detection
20
+ // ============================================================================
21
+ /**
22
+ * Check if file contains agent or tool definitions
23
+ */
24
+ function isAgentOrToolFile(filePath, content) {
25
+ // File path indicators
26
+ const agentPathPatterns = [
27
+ /\/(agents?|tools?|functions?|actions?)\//i,
28
+ /\/(mcp|langchain|llamaindex|autogen)\//i,
29
+ /(agent|tool|function|action).*\.(ts|js|py)$/i,
30
+ ];
31
+ if (agentPathPatterns.some(p => p.test(filePath))) {
32
+ return true;
33
+ }
34
+ // Content patterns indicating tool/agent definitions
35
+ const toolDefinitionPatterns = [
36
+ /@tool/i, // Python decorator
37
+ /def\s+\w+_tool\s*\(/i, // Python tool function
38
+ /defineTool\s*\(/i, // JS/TS tool definition
39
+ /createTool\s*\(/i, // Tool creation
40
+ /\.registerTool\s*\(/i, // Tool registration
41
+ /\.addTool\s*\(/i, // Adding tool to agent
42
+ /tools\s*:\s*\[/i, // Tools array
43
+ /FunctionTool|StructuredTool/i, // LangChain tools
44
+ /tool_choice|function_call/i, // OpenAI function calling
45
+ /Tool\s*\(\s*\{/i, // Tool configuration object
46
+ /type:\s*['"`]function['"`]/i, // OpenAI function type
47
+ /mcpServer|McpServer/i, // MCP server
48
+ ];
49
+ return toolDefinitionPatterns.some(p => p.test(content));
50
+ }
51
+ /**
52
+ * Find tool definition boundaries (start and end lines)
53
+ */
54
+ function findToolDefinitionContext(content, lineNumber, windowSize = 30) {
55
+ const lines = content.split('\n');
56
+ const startLine = Math.max(0, lineNumber - windowSize);
57
+ const endLine = Math.min(lines.length, lineNumber + windowSize);
58
+ return {
59
+ context: lines.slice(startLine, endLine).join('\n'),
60
+ startLine,
61
+ endLine,
62
+ };
63
+ }
64
+ // ============================================================================
65
+ // Authorization Detection
66
+ // ============================================================================
67
+ /**
68
+ * Check if user context is verified in tool
69
+ */
70
+ function hasUserContextVerification(context) {
71
+ const userContextPatterns = [
72
+ /user[_.]?id/i,
73
+ /userId/i,
74
+ /currentUser/i,
75
+ /req\.user/i,
76
+ /request\.user/i,
77
+ /session\.user/i,
78
+ /getUser\s*\(/i,
79
+ /getCurrentUser\s*\(/i,
80
+ /authenticatedUser/i,
81
+ /ctx\.user/i,
82
+ /context\.user/i,
83
+ ];
84
+ return userContextPatterns.some(p => p.test(context));
85
+ }
86
+ /**
87
+ * Check if tenant/organization context is verified
88
+ */
89
+ function hasTenantContextVerification(context) {
90
+ const tenantContextPatterns = [
91
+ /tenant[_.]?id/i,
92
+ /tenantId/i,
93
+ /org[_.]?id/i,
94
+ /orgId/i,
95
+ /organization[_.]?id/i,
96
+ /workspace[_.]?id/i,
97
+ /workspaceId/i,
98
+ /team[_.]?id/i,
99
+ /teamId/i,
100
+ /account[_.]?id/i,
101
+ /accountId/i,
102
+ ];
103
+ return tenantContextPatterns.some(p => p.test(context));
104
+ }
105
+ /**
106
+ * Patterns indicating strong/verified restrictions (actual implementation)
107
+ */
108
+ const STRONG_RESTRICTION_PATTERNS = [
109
+ // Sandboxing libraries and environments
110
+ /\bvm2\b/i,
111
+ /\bisolated-vm\b/i,
112
+ /\bquickjs\b/i,
113
+ /\bsandboxed\b/i,
114
+ /\bRestrictedPython\b/i,
115
+ /\bnsjail\b/i,
116
+ /\bfirejail\b/i,
117
+ /\bgvisor\b/i,
118
+ // Explicit path/resource restrictions with arrays
119
+ /allowed(?:Paths|Files|Dirs|Hosts|Urls|Commands)\s*[=:]\s*\[/i,
120
+ /(?:white|allow)list\s*[=:]\s*\[/i,
121
+ /(?:blocked|denied|forbidden)(?:Paths|Hosts|Commands)\s*[=:]\s*\[/i,
122
+ // Path validation functions
123
+ /validatePath\s*\(/i,
124
+ /isAllowedPath\s*\(/i,
125
+ /checkPathAccess\s*\(/i,
126
+ /resolvePath.*allowed/i,
127
+ /path\.resolve.*includes/i,
128
+ // Sandbox configuration objects
129
+ /sandbox\s*[=:]\s*(?:true|\{)/i,
130
+ /readonly\s*[=:]\s*true/i,
131
+ /readOnly\s*[=:]\s*true/i,
132
+ // Container/isolation patterns
133
+ /\b(?:docker|podman)\s+run\b.*--read-only/i,
134
+ /seccomp/i,
135
+ /capabilities\s*[=:]\s*\[\s*\]/i, // Empty capabilities = restricted
136
+ // Permission checking code
137
+ /if\s*\(\s*!?\s*(?:allowed|permitted|authorized)/i,
138
+ /(?:check|verify|validate)(?:Access|Permission|Capability)\s*\(/i,
139
+ ];
140
+ /**
141
+ * Patterns indicating weak/unverified restriction mentions (comments, TODOs)
142
+ */
143
+ const WEAK_RESTRICTION_PATTERNS = [
144
+ // Comments mentioning restrictions without implementation
145
+ /\/\/.*(?:sandbox|restrict|allowlist|whitelist|todo)/i,
146
+ /\/\*.*(?:sandbox|restrict|allowlist|whitelist|todo).*\*\//i,
147
+ /#.*(?:sandbox|restrict|allowlist|whitelist|todo)/i,
148
+ // TODOs and FIXMEs
149
+ /TODO.*(?:add|implement|enable).*(?:sandbox|restrict|allowlist)/i,
150
+ /FIXME.*(?:sandbox|restrict|security)/i,
151
+ // Variable names without assignment
152
+ /const\s+(?:sandbox|allowlist|whitelist)\s*;/i,
153
+ ];
154
+ /**
155
+ * Check if tool has strong/verified access restrictions
156
+ * These are actual implementations, not just mentions
157
+ */
158
+ function hasStrongRestrictions(context) {
159
+ // Check for strong patterns
160
+ const hasStrong = STRONG_RESTRICTION_PATTERNS.some(p => p.test(context));
161
+ if (!hasStrong)
162
+ return false;
163
+ // Verify it's not just a weak mention
164
+ const isWeak = WEAK_RESTRICTION_PATTERNS.some(p => p.test(context));
165
+ return !isWeak;
166
+ }
167
+ /**
168
+ * Check if tool has any access restrictions/allowlists (including weak mentions)
169
+ */
170
+ function hasAccessRestrictions(context) {
171
+ const restrictionPatterns = [
172
+ /allowedPaths/i,
173
+ /allowedFiles/i,
174
+ /allowedDirs/i,
175
+ /allowedHosts/i,
176
+ /allowedUrls/i,
177
+ /allowedCommands/i,
178
+ /allowedOperations/i,
179
+ /whitelist/i,
180
+ /allowlist/i,
181
+ /permissions?:/i,
182
+ /capabilities:/i,
183
+ /restrictions?:/i,
184
+ /constraints?:/i,
185
+ /sandbox/i,
186
+ /readonly/i,
187
+ /readOnly/i,
188
+ ];
189
+ return restrictionPatterns.some(p => p.test(context));
190
+ }
191
+ const OVERPERMISSIVE_TOOL_PATTERNS = [
192
+ // ========== Filesystem Access Tools ==========
193
+ {
194
+ name: 'Unrestricted file read tool',
195
+ pattern: /(?:@tool|defineTool|createTool|Tool\s*\()[^)]*(?:read|get).*file|(?:fs|filesystem).*(?:read|get)/gi,
196
+ riskType: 'filesystem',
197
+ baseSeverity: 'high',
198
+ description: 'Tool provides file system read access. Without restrictions, agents can access any file the process can read.',
199
+ suggestedFix: 'Add allowedPaths restriction. Example: { allowedPaths: ["/data/user-uploads"] }. Validate paths stay within allowed directories.',
200
+ requiresRestrictions: true,
201
+ },
202
+ {
203
+ name: 'Unrestricted file write tool',
204
+ pattern: /(?:@tool|defineTool|createTool|Tool\s*\()[^)]*(?:write|create|save).*file|(?:fs|filesystem).*(?:write|create)/gi,
205
+ riskType: 'filesystem',
206
+ baseSeverity: 'high',
207
+ description: 'Tool provides file system write access. Agents could overwrite critical files or create malicious files.',
208
+ suggestedFix: 'Restrict to specific directories. Validate file extensions. Implement size limits. Consider using signed URLs instead of direct file access.',
209
+ requiresRestrictions: true,
210
+ },
211
+ {
212
+ name: 'File deletion tool',
213
+ pattern: /(?:@tool|defineTool|createTool|Tool\s*\()[^)]*(?:delete|remove).*file|(?:fs|filesystem).*(?:delete|unlink|remove)/gi,
214
+ riskType: 'filesystem',
215
+ baseSeverity: 'high',
216
+ description: 'Tool provides file deletion capability. High risk of data loss if misused.',
217
+ suggestedFix: 'Implement soft-delete instead of hard delete. Require confirmation. Restrict to user-owned files only.',
218
+ requiresRestrictions: true,
219
+ requiresUserContext: true,
220
+ },
221
+ // ========== Network Access Tools ==========
222
+ {
223
+ name: 'Unrestricted HTTP/fetch tool',
224
+ pattern: /(?:@tool|defineTool|createTool|Tool\s*\()[^)]*(?:http|fetch|request|api)|tool.*(?:fetch|request)\s*\(/gi,
225
+ riskType: 'network',
226
+ baseSeverity: 'medium',
227
+ description: 'Tool provides network/HTTP access. Without restrictions, agents could make requests to internal services (SSRF) or exfiltrate data.',
228
+ suggestedFix: 'Add allowedHosts configuration. Block internal/private IP ranges. Implement request signing for sensitive operations.',
229
+ requiresRestrictions: true,
230
+ },
231
+ {
232
+ name: 'Web scraping tool',
233
+ pattern: /(?:@tool|defineTool|createTool|Tool\s*\()[^)]*(?:scrape|crawl|browse)/gi,
234
+ riskType: 'network',
235
+ baseSeverity: 'medium',
236
+ description: 'Tool provides web scraping capability. Could be used for SSRF or accessing internal resources.',
237
+ suggestedFix: 'Restrict to allowed domains. Block internal IP ranges. Implement rate limiting.',
238
+ requiresRestrictions: true,
239
+ },
240
+ // ========== Code Execution Tools ==========
241
+ {
242
+ name: 'Code execution tool',
243
+ pattern: /(?:@tool|defineTool|createTool|Tool\s*\()[^)]*(?:execute|run|eval).*(?:code|script)|tool.*(?:eval|exec)\s*\(/gi,
244
+ riskType: 'code_execution',
245
+ baseSeverity: 'critical',
246
+ description: 'Tool provides code execution capability. This is extremely dangerous without sandboxing.',
247
+ suggestedFix: 'Use vm2, isolated-vm, or similar sandboxing. Implement timeout and memory limits. Restrict available APIs/modules.',
248
+ requiresRestrictions: true,
249
+ },
250
+ {
251
+ name: 'Python interpreter tool',
252
+ pattern: /(?:@tool|defineTool|createTool|Tool\s*\()[^)]*python.*(?:exec|run|interpret)|PythonREPL|python_repl/gi,
253
+ riskType: 'code_execution',
254
+ baseSeverity: 'critical',
255
+ description: 'Tool provides Python execution capability. Can execute arbitrary system commands.',
256
+ suggestedFix: 'Use RestrictedPython or sandboxed environments. Block dangerous modules (os, subprocess, socket). Implement resource limits.',
257
+ requiresRestrictions: true,
258
+ },
259
+ // ========== Shell/Command Tools ==========
260
+ {
261
+ name: 'Shell command tool',
262
+ pattern: /(?:@tool|defineTool|createTool|Tool\s*\()[^)]*(?:shell|command|terminal|bash)|ShellTool|BashTool/gi,
263
+ riskType: 'shell',
264
+ baseSeverity: 'critical',
265
+ description: 'Tool provides shell command execution. Allows arbitrary system commands.',
266
+ suggestedFix: 'Implement strict command allowlisting. Use parameterized commands (execFile, not exec). Consider removing this capability entirely.',
267
+ requiresRestrictions: true,
268
+ },
269
+ {
270
+ name: 'System command tool',
271
+ pattern: /(?:@tool|defineTool|createTool)[^)]*(?:system|exec|spawn|subprocess)/gi,
272
+ riskType: 'shell',
273
+ baseSeverity: 'critical',
274
+ description: 'Tool with system command execution capability.',
275
+ suggestedFix: 'Restrict to specific commands via allowlist. Validate all arguments. Log all command executions.',
276
+ requiresRestrictions: true,
277
+ },
278
+ // ========== Database Tools ==========
279
+ {
280
+ name: 'Database query tool',
281
+ pattern: /(?:@tool|defineTool|createTool|Tool\s*\()[^)]*(?:query|sql|database)|tool.*(?:query|execute)\s*\(/gi,
282
+ riskType: 'database',
283
+ baseSeverity: 'high',
284
+ description: 'Tool provides database query access. Without scoping, agents could access any data.',
285
+ suggestedFix: 'Always scope queries to current user/tenant. Use row-level security (RLS). Implement read-only mode for most operations.',
286
+ requiresUserContext: true,
287
+ requiresTenantContext: true,
288
+ },
289
+ {
290
+ name: 'Raw SQL tool',
291
+ pattern: /(?:@tool|defineTool|createTool)[^)]*(?:raw.*sql|execute.*sql)/gi,
292
+ riskType: 'database',
293
+ baseSeverity: 'critical',
294
+ description: 'Tool allows raw SQL execution. High risk of SQL injection and unauthorized data access.',
295
+ suggestedFix: 'Use parameterized queries only. Implement query validation. Consider using an ORM instead of raw SQL.',
296
+ requiresUserContext: true,
297
+ requiresTenantContext: true,
298
+ },
299
+ // ========== M5: MCP Server Tools ==========
300
+ {
301
+ name: 'MCP server tool registration',
302
+ pattern: /(?:McpServer|Server)\s*\([^)]*\).*(?:setRequestHandler|tool|registerTool)|server\.tool\s*\(/gi,
303
+ riskType: 'code_execution',
304
+ baseSeverity: 'high',
305
+ description: 'MCP (Model Context Protocol) server registering tools. Verify tool capabilities are appropriately restricted.',
306
+ suggestedFix: 'Add capability restrictions to MCP server. Implement allowlists for file paths, network hosts, and commands.',
307
+ requiresRestrictions: true,
308
+ },
309
+ {
310
+ name: 'MCP tool with shell access',
311
+ pattern: /server\.tool\s*\([^)]*(?:name:\s*['"`](?:run|exec|shell|command)[^)]*|(?:exec|spawn|shell)\s*\()/gi,
312
+ riskType: 'shell',
313
+ baseSeverity: 'critical',
314
+ description: 'MCP tool with shell command execution capability. Extremely dangerous without restrictions.',
315
+ suggestedFix: 'Use allowlist of permitted commands. Never allow arbitrary command execution. Consider read-only alternatives.',
316
+ requiresRestrictions: true,
317
+ },
318
+ {
319
+ name: 'MCP file system tool',
320
+ pattern: /server\.tool\s*\([^)]*(?:name:\s*['"`](?:read|write|create|delete|list).*(?:file|dir)[^)]*|fs\.|readFile|writeFile)/gi,
321
+ riskType: 'filesystem',
322
+ baseSeverity: 'high',
323
+ description: 'MCP tool with file system access. Agents could access or modify arbitrary files.',
324
+ suggestedFix: 'Restrict to specific directories with allowedPaths. Implement path validation. Consider read-only access.',
325
+ requiresRestrictions: true,
326
+ },
327
+ // ========== M5: Vercel AI SDK Tools ==========
328
+ {
329
+ name: 'Vercel AI SDK tool definition',
330
+ pattern: /tool\s*\(\s*\{[^}]*(?:execute|parameters)/gi,
331
+ riskType: 'code_execution',
332
+ baseSeverity: 'medium',
333
+ description: 'Vercel AI SDK tool definition. Review the execute function for dangerous operations.',
334
+ suggestedFix: 'Validate tool parameters against expected schema. Implement proper access controls within execute function.',
335
+ requiresUserContext: true,
336
+ },
337
+ {
338
+ name: 'AI SDK tool with dangerous execute',
339
+ pattern: /tool\s*\(\s*\{[^}]*execute\s*:\s*async[^}]*(?:exec|spawn|eval|fs\.|fetch\s*\()[^}]*\}/gi,
340
+ riskType: 'code_execution',
341
+ baseSeverity: 'high',
342
+ description: 'Vercel AI SDK tool with potentially dangerous execute function (shell, eval, fs, or network access).',
343
+ suggestedFix: 'Add validation and restrictions in execute function. Implement allowlists for external operations.',
344
+ requiresRestrictions: true,
345
+ },
346
+ {
347
+ name: 'StreamableUI tool action',
348
+ pattern: /createStreamableUI.*tool.*\{.*action/gi,
349
+ riskType: 'code_execution',
350
+ baseSeverity: 'medium',
351
+ description: 'Streamable UI tool with server action. Ensure proper authorization before state mutations.',
352
+ suggestedFix: 'Verify user authentication and authorization before executing actions. Validate all inputs.',
353
+ requiresUserContext: true,
354
+ },
355
+ ];
356
+ /**
357
+ * Patterns for missing authorization in tools
358
+ */
359
+ const MISSING_AUTH_PATTERNS = [
360
+ {
361
+ name: 'Tool without user context',
362
+ pattern: /(?:@tool|defineTool|createTool|\.registerTool|\.addTool)\s*\([^)]*(?:async\s+)?(?:function|\().*(?:create|update|delete|modify|write|send)/gi,
363
+ riskType: 'database',
364
+ baseSeverity: 'medium',
365
+ description: 'Tool performs write operations but may not verify user context. Actions could be performed as wrong user.',
366
+ suggestedFix: 'Pass userId as required parameter. Verify user owns/can access the resource before modification.',
367
+ requiresUserContext: true,
368
+ },
369
+ ];
370
+ // ============================================================================
371
+ // Main Detection Function
372
+ // ============================================================================
373
+ /**
374
+ * Main detection function for AI agent tool permission issues
375
+ */
376
+ function detectAIAgentTools(content, filePath) {
377
+ const vulnerabilities = [];
378
+ // Skip non-applicable files
379
+ if ((0, context_helpers_1.isScannerOrFixtureFile)(filePath))
380
+ return vulnerabilities;
381
+ // Only scan files that appear to have agent/tool definitions
382
+ if (!isAgentOrToolFile(filePath, content)) {
383
+ return vulnerabilities;
384
+ }
385
+ const lines = content.split('\n');
386
+ const isTestFile = (0, context_helpers_1.isTestOrMockFile)(filePath);
387
+ const isExample = (0, context_helpers_1.isExampleDirectory)(filePath);
388
+ const isLibrary = (0, context_helpers_1.isLibraryCode)(filePath);
389
+ // Scan for overly permissive tool patterns
390
+ for (const pattern of OVERPERMISSIVE_TOOL_PATTERNS) {
391
+ const regex = new RegExp(pattern.pattern.source, pattern.pattern.flags);
392
+ let match;
393
+ while ((match = regex.exec(content)) !== null) {
394
+ const lineNumber = content.substring(0, match.index).split('\n').length;
395
+ const lineContent = lines[lineNumber - 1]?.trim() || '';
396
+ // Skip comments
397
+ if ((0, context_helpers_1.isComment)(lineContent))
398
+ continue;
399
+ // Get tool context
400
+ const { context } = findToolDefinitionContext(content, lineNumber);
401
+ // Check for mitigations (strong vs weak)
402
+ const hasStrong = hasStrongRestrictions(context);
403
+ const hasWeak = hasAccessRestrictions(context);
404
+ const hasUserContext = hasUserContextVerification(context);
405
+ const hasTenantContext = hasTenantContextVerification(context);
406
+ // Determine if issue is fully mitigated
407
+ let isMitigated = true;
408
+ let hasPartialMitigation = false;
409
+ const missingMitigations = [];
410
+ if (pattern.requiresRestrictions) {
411
+ if (hasStrong) {
412
+ // Strong restrictions = fully mitigated for this requirement
413
+ }
414
+ else if (hasWeak) {
415
+ // Weak restrictions = partial mitigation
416
+ hasPartialMitigation = true;
417
+ missingMitigations.push('verified access restrictions (found mentions but not implementation)');
418
+ isMitigated = false;
419
+ }
420
+ else {
421
+ isMitigated = false;
422
+ missingMitigations.push('access restrictions');
423
+ }
424
+ }
425
+ if (pattern.requiresUserContext && !hasUserContext) {
426
+ isMitigated = false;
427
+ missingMitigations.push('user context verification');
428
+ }
429
+ if (pattern.requiresTenantContext && !hasTenantContext) {
430
+ isMitigated = false;
431
+ missingMitigations.push('tenant/org context verification');
432
+ }
433
+ // Skip if all required mitigations are present with strong verification
434
+ if (isMitigated)
435
+ continue;
436
+ // Calculate severity
437
+ let severity = pattern.baseSeverity;
438
+ if (isTestFile) {
439
+ severity = 'info';
440
+ }
441
+ else if (isExample) {
442
+ // Example/demo code - downgrade to info
443
+ severity = 'info';
444
+ }
445
+ else if (isLibrary) {
446
+ // Library code - tool definitions are intentionally flexible
447
+ // Consumers add restrictions when they use the tools
448
+ severity = 'info';
449
+ }
450
+ else if (hasPartialMitigation || hasUserContext || hasTenantContext) {
451
+ // Partial mitigation - downgrade
452
+ if (severity === 'critical')
453
+ severity = 'high';
454
+ else if (severity === 'high')
455
+ severity = 'medium';
456
+ }
457
+ // Build description
458
+ let description = pattern.description;
459
+ if (missingMitigations.length > 0) {
460
+ description += ` Missing: ${missingMitigations.join(', ')}.`;
461
+ }
462
+ if (isTestFile) {
463
+ description += ' (In test file.)';
464
+ }
465
+ else if (isExample) {
466
+ description += ' (In example/demo directory - not production code.)';
467
+ }
468
+ else if (isLibrary) {
469
+ description += ' (Library code - tool definitions are generic; consumers add restrictions.)';
470
+ }
471
+ vulnerabilities.push({
472
+ id: `ai-tool-${filePath}-${lineNumber}-${pattern.riskType}`,
473
+ filePath,
474
+ lineNumber,
475
+ lineContent,
476
+ severity,
477
+ category: 'ai_overpermissive_tool',
478
+ title: pattern.name,
479
+ description,
480
+ suggestedFix: pattern.suggestedFix,
481
+ confidence: 'medium',
482
+ layer: 2,
483
+ requiresAIValidation: true, // Always validate - context dependent
484
+ });
485
+ }
486
+ }
487
+ // Scan for missing authorization patterns
488
+ for (const pattern of MISSING_AUTH_PATTERNS) {
489
+ const regex = new RegExp(pattern.pattern.source, pattern.pattern.flags);
490
+ let match;
491
+ while ((match = regex.exec(content)) !== null) {
492
+ const lineNumber = content.substring(0, match.index).split('\n').length;
493
+ const lineContent = lines[lineNumber - 1]?.trim() || '';
494
+ // Skip comments
495
+ if ((0, context_helpers_1.isComment)(lineContent))
496
+ continue;
497
+ // Get tool context
498
+ const { context } = findToolDefinitionContext(content, lineNumber);
499
+ // Check if user context is verified
500
+ const hasUserContext = hasUserContextVerification(context);
501
+ // Skip if user context is present
502
+ if (hasUserContext)
503
+ continue;
504
+ let severity = pattern.baseSeverity;
505
+ let description = pattern.description;
506
+ if (isTestFile) {
507
+ severity = 'info';
508
+ description += ' (In test file.)';
509
+ }
510
+ vulnerabilities.push({
511
+ id: `ai-tool-auth-${filePath}-${lineNumber}`,
512
+ filePath,
513
+ lineNumber,
514
+ lineContent,
515
+ severity,
516
+ category: 'ai_overpermissive_tool',
517
+ title: pattern.name,
518
+ description,
519
+ suggestedFix: pattern.suggestedFix,
520
+ confidence: 'low', // Lower confidence - needs context
521
+ layer: 2,
522
+ requiresAIValidation: true,
523
+ });
524
+ }
525
+ }
526
+ return vulnerabilities;
527
+ }
528
+ //# sourceMappingURL=ai-agent-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-agent-tools.js","sourceRoot":"","sources":["../../src/layer2/ai-agent-tools.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAwaH,gDAoKC;AAzkBD,8DAMiC;AAEjC,+EAA+E;AAC/E,+BAA+B;AAC/B,+EAA+E;AAE/E;;GAEG;AACH,SAAS,iBAAiB,CAAC,QAAgB,EAAE,OAAe;IAC1D,uBAAuB;IACvB,MAAM,iBAAiB,GAAG;QACxB,2CAA2C;QAC3C,yCAAyC;QACzC,8CAA8C;KAC/C,CAAA;IAED,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QAClD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,qDAAqD;IACrD,MAAM,sBAAsB,GAAG;QAC7B,QAAQ,EAA8B,mBAAmB;QACzD,sBAAsB,EAAe,uBAAuB;QAC5D,kBAAkB,EAAoB,wBAAwB;QAC9D,kBAAkB,EAAoB,gBAAgB;QACtD,sBAAsB,EAAgB,oBAAoB;QAC1D,iBAAiB,EAAqB,uBAAuB;QAC7D,iBAAiB,EAAqB,cAAc;QACpD,8BAA8B,EAAQ,kBAAkB;QACxD,4BAA4B,EAAU,0BAA0B;QAChE,iBAAiB,EAAqB,4BAA4B;QAClE,6BAA6B,EAAS,uBAAuB;QAC7D,sBAAsB,EAAgB,aAAa;KACpD,CAAA;IAED,OAAO,sBAAsB,CAAC,IAAI,CAAC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B;YACnB,MAAM,EAAE,OAAO,EAAE,GAAG,yBAAyB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;YAElE,oCAAoC;YACpC,MAAM,cAAc,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAA;YAE1D,kCAAkC;YAClC,IAAI,cAAc;gBAAE,SAAQ;YAE5B,IAAI,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAA;YACnC,IAAI,WAAW,GAAG,OAAO,CAAC,WAAW,CAAA;YAErC,IAAI,UAAU,EAAE,CAAC;gBACf,QAAQ,GAAG,MAAM,CAAA;gBACjB,WAAW,IAAI,kBAAkB,CAAA;YACnC,CAAC;YAED,eAAe,CAAC,IAAI,CAAC;gBACnB,EAAE,EAAE,gBAAgB,QAAQ,IAAI,UAAU,EAAE;gBAC5C,QAAQ;gBACR,UAAU;gBACV,WAAW;gBACX,QAAQ;gBACR,QAAQ,EAAE,wBAAwB;gBAClC,KAAK,EAAE,OAAO,CAAC,IAAI;gBACnB,WAAW;gBACX,YAAY,EAAE,OAAO,CAAC,YAAY;gBAClC,UAAU,EAAE,KAAK,EAAE,mCAAmC;gBACtD,KAAK,EAAE,CAAC;gBACR,oBAAoB,EAAE,IAAI;aAC3B,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Layer 2: AI Endpoint Protection Detection
3
+ * Detects AI/LLM endpoints without proper authentication or rate limiting
4
+ *
5
+ * Covers:
6
+ * - M5.2: AI endpoints without auth/rate limiting
7
+ * - Cost-bearing AI endpoints exposed publicly
8
+ * - Missing rate limiting on AI routes
9
+ */
10
+ import type { Vulnerability } from '../types';
11
+ import type { MiddlewareAuthConfig } from '../utils/middleware-detector';
12
+ /**
13
+ * Check if file is a route/API handler
14
+ */
15
+ declare function isRouteFile(filePath: string): boolean;
16
+ /**
17
+ * Check if content contains AI/LLM API calls
18
+ */
19
+ declare function hasAIApiCalls(content: string): boolean;
20
+ /**
21
+ * Check if there's authentication in the route
22
+ */
23
+ declare function hasAuthentication(content: string): boolean;
24
+ /**
25
+ * Check if there's rate limiting
26
+ */
27
+ declare function hasRateLimiting(content: string): boolean;
28
+ export interface EndpointProtectionOptions {
29
+ middlewareConfig?: MiddlewareAuthConfig;
30
+ }
31
+ /**
32
+ * Main detection function for AI endpoint protection issues
33
+ */
34
+ export declare function detectAIEndpointProtection(content: string, filePath: string, options?: EndpointProtectionOptions): Vulnerability[];
35
+ export { isRouteFile, hasAIApiCalls, hasAuthentication, hasRateLimiting };
36
+ //# sourceMappingURL=ai-endpoint-protection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-endpoint-protection.d.ts","sourceRoot":"","sources":["../../src/layer2/ai-endpoint-protection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAyB,MAAM,UAAU,CAAA;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAaxE;;GAEG;AACH,iBAAS,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAU9C;AAED;;GAEG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CA0B/C;AAED;;GAEG;AACH,iBAAS,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAwBnD;AAED;;GAEG;AACH,iBAAS,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAqBjD;AA8HD,MAAM,WAAW,yBAAyB;IACxC,gBAAgB,CAAC,EAAE,oBAAoB,CAAA;CACxC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,yBAA8B,GACtC,aAAa,EAAE,CA2HjB;AAGD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,CAAA"}