@oculum/scanner 1.0.9 → 1.0.11

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 (365) hide show
  1. package/dist/baseline/diff.d.ts +32 -0
  2. package/dist/baseline/diff.d.ts.map +1 -0
  3. package/dist/baseline/diff.js +119 -0
  4. package/dist/baseline/diff.js.map +1 -0
  5. package/dist/baseline/index.d.ts +9 -0
  6. package/dist/baseline/index.d.ts.map +1 -0
  7. package/dist/baseline/index.js +19 -0
  8. package/dist/baseline/index.js.map +1 -0
  9. package/dist/baseline/manager.d.ts +67 -0
  10. package/dist/baseline/manager.d.ts.map +1 -0
  11. package/dist/baseline/manager.js +180 -0
  12. package/dist/baseline/manager.js.map +1 -0
  13. package/dist/baseline/types.d.ts +91 -0
  14. package/dist/baseline/types.d.ts.map +1 -0
  15. package/dist/baseline/types.js +12 -0
  16. package/dist/baseline/types.js.map +1 -0
  17. package/dist/formatters/cli-terminal.d.ts +38 -0
  18. package/dist/formatters/cli-terminal.d.ts.map +1 -1
  19. package/dist/formatters/cli-terminal.js +365 -42
  20. package/dist/formatters/cli-terminal.js.map +1 -1
  21. package/dist/formatters/github-comment.d.ts +1 -1
  22. package/dist/formatters/github-comment.d.ts.map +1 -1
  23. package/dist/formatters/github-comment.js +75 -11
  24. package/dist/formatters/github-comment.js.map +1 -1
  25. package/dist/formatters/index.d.ts +1 -1
  26. package/dist/formatters/index.d.ts.map +1 -1
  27. package/dist/formatters/index.js +4 -1
  28. package/dist/formatters/index.js.map +1 -1
  29. package/dist/index.d.ts +7 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +155 -16
  32. package/dist/index.js.map +1 -1
  33. package/dist/layer1/config-audit.d.ts.map +1 -1
  34. package/dist/layer1/config-audit.js +20 -3
  35. package/dist/layer1/config-audit.js.map +1 -1
  36. package/dist/layer1/config-mcp-audit.d.ts +20 -0
  37. package/dist/layer1/config-mcp-audit.d.ts.map +1 -0
  38. package/dist/layer1/config-mcp-audit.js +239 -0
  39. package/dist/layer1/config-mcp-audit.js.map +1 -0
  40. package/dist/layer1/index.d.ts +1 -0
  41. package/dist/layer1/index.d.ts.map +1 -1
  42. package/dist/layer1/index.js +9 -1
  43. package/dist/layer1/index.js.map +1 -1
  44. package/dist/layer2/ai-agent-tools.d.ts.map +1 -1
  45. package/dist/layer2/ai-agent-tools.js +303 -0
  46. package/dist/layer2/ai-agent-tools.js.map +1 -1
  47. package/dist/layer2/ai-endpoint-protection.d.ts.map +1 -1
  48. package/dist/layer2/ai-endpoint-protection.js +17 -3
  49. package/dist/layer2/ai-endpoint-protection.js.map +1 -1
  50. package/dist/layer2/ai-execution-sinks.d.ts.map +1 -1
  51. package/dist/layer2/ai-execution-sinks.js +462 -12
  52. package/dist/layer2/ai-execution-sinks.js.map +1 -1
  53. package/dist/layer2/ai-fingerprinting.d.ts.map +1 -1
  54. package/dist/layer2/ai-fingerprinting.js +3 -0
  55. package/dist/layer2/ai-fingerprinting.js.map +1 -1
  56. package/dist/layer2/ai-mcp-security.d.ts +17 -0
  57. package/dist/layer2/ai-mcp-security.d.ts.map +1 -0
  58. package/dist/layer2/ai-mcp-security.js +679 -0
  59. package/dist/layer2/ai-mcp-security.js.map +1 -0
  60. package/dist/layer2/ai-package-hallucination.d.ts +19 -0
  61. package/dist/layer2/ai-package-hallucination.d.ts.map +1 -0
  62. package/dist/layer2/ai-package-hallucination.js +696 -0
  63. package/dist/layer2/ai-package-hallucination.js.map +1 -0
  64. package/dist/layer2/ai-prompt-hygiene.d.ts.map +1 -1
  65. package/dist/layer2/ai-prompt-hygiene.js +495 -9
  66. package/dist/layer2/ai-prompt-hygiene.js.map +1 -1
  67. package/dist/layer2/ai-rag-safety.d.ts.map +1 -1
  68. package/dist/layer2/ai-rag-safety.js +372 -1
  69. package/dist/layer2/ai-rag-safety.js.map +1 -1
  70. package/dist/layer2/auth-antipatterns.d.ts.map +1 -1
  71. package/dist/layer2/auth-antipatterns.js +4 -0
  72. package/dist/layer2/auth-antipatterns.js.map +1 -1
  73. package/dist/layer2/byok-patterns.d.ts.map +1 -1
  74. package/dist/layer2/byok-patterns.js +3 -0
  75. package/dist/layer2/byok-patterns.js.map +1 -1
  76. package/dist/layer2/dangerous-functions/child-process.d.ts +16 -0
  77. package/dist/layer2/dangerous-functions/child-process.d.ts.map +1 -0
  78. package/dist/layer2/dangerous-functions/child-process.js +74 -0
  79. package/dist/layer2/dangerous-functions/child-process.js.map +1 -0
  80. package/dist/layer2/dangerous-functions/dom-xss.d.ts +29 -0
  81. package/dist/layer2/dangerous-functions/dom-xss.d.ts.map +1 -0
  82. package/dist/layer2/dangerous-functions/dom-xss.js +179 -0
  83. package/dist/layer2/dangerous-functions/dom-xss.js.map +1 -0
  84. package/dist/layer2/dangerous-functions/index.d.ts +13 -0
  85. package/dist/layer2/dangerous-functions/index.d.ts.map +1 -0
  86. package/dist/layer2/dangerous-functions/index.js +621 -0
  87. package/dist/layer2/dangerous-functions/index.js.map +1 -0
  88. package/dist/layer2/dangerous-functions/json-parse.d.ts +31 -0
  89. package/dist/layer2/dangerous-functions/json-parse.d.ts.map +1 -0
  90. package/dist/layer2/dangerous-functions/json-parse.js +319 -0
  91. package/dist/layer2/dangerous-functions/json-parse.js.map +1 -0
  92. package/dist/layer2/dangerous-functions/math-random.d.ts +61 -0
  93. package/dist/layer2/dangerous-functions/math-random.d.ts.map +1 -0
  94. package/dist/layer2/dangerous-functions/math-random.js +459 -0
  95. package/dist/layer2/dangerous-functions/math-random.js.map +1 -0
  96. package/dist/layer2/dangerous-functions/patterns.d.ts +21 -0
  97. package/dist/layer2/dangerous-functions/patterns.d.ts.map +1 -0
  98. package/dist/layer2/dangerous-functions/patterns.js +161 -0
  99. package/dist/layer2/dangerous-functions/patterns.js.map +1 -0
  100. package/dist/layer2/dangerous-functions/request-validation.d.ts +13 -0
  101. package/dist/layer2/dangerous-functions/request-validation.d.ts.map +1 -0
  102. package/dist/layer2/dangerous-functions/request-validation.js +119 -0
  103. package/dist/layer2/dangerous-functions/request-validation.js.map +1 -0
  104. package/dist/layer2/dangerous-functions/utils/control-flow.d.ts +23 -0
  105. package/dist/layer2/dangerous-functions/utils/control-flow.d.ts.map +1 -0
  106. package/dist/layer2/dangerous-functions/utils/control-flow.js +149 -0
  107. package/dist/layer2/dangerous-functions/utils/control-flow.js.map +1 -0
  108. package/dist/layer2/dangerous-functions/utils/helpers.d.ts +31 -0
  109. package/dist/layer2/dangerous-functions/utils/helpers.d.ts.map +1 -0
  110. package/dist/layer2/dangerous-functions/utils/helpers.js +124 -0
  111. package/dist/layer2/dangerous-functions/utils/helpers.js.map +1 -0
  112. package/dist/layer2/dangerous-functions/utils/index.d.ts +9 -0
  113. package/dist/layer2/dangerous-functions/utils/index.d.ts.map +1 -0
  114. package/dist/layer2/dangerous-functions/utils/index.js +23 -0
  115. package/dist/layer2/dangerous-functions/utils/index.js.map +1 -0
  116. package/dist/layer2/dangerous-functions/utils/schema-validation.d.ts +22 -0
  117. package/dist/layer2/dangerous-functions/utils/schema-validation.d.ts.map +1 -0
  118. package/dist/layer2/dangerous-functions/utils/schema-validation.js +89 -0
  119. package/dist/layer2/dangerous-functions/utils/schema-validation.js.map +1 -0
  120. package/dist/layer2/data-exposure.d.ts.map +1 -1
  121. package/dist/layer2/data-exposure.js +3 -0
  122. package/dist/layer2/data-exposure.js.map +1 -1
  123. package/dist/layer2/framework-checks.d.ts.map +1 -1
  124. package/dist/layer2/framework-checks.js +3 -0
  125. package/dist/layer2/framework-checks.js.map +1 -1
  126. package/dist/layer2/index.d.ts +3 -0
  127. package/dist/layer2/index.d.ts.map +1 -1
  128. package/dist/layer2/index.js +61 -2
  129. package/dist/layer2/index.js.map +1 -1
  130. package/dist/layer2/logic-gates.d.ts.map +1 -1
  131. package/dist/layer2/logic-gates.js +4 -0
  132. package/dist/layer2/logic-gates.js.map +1 -1
  133. package/dist/layer2/model-supply-chain.d.ts +20 -0
  134. package/dist/layer2/model-supply-chain.d.ts.map +1 -0
  135. package/dist/layer2/model-supply-chain.js +376 -0
  136. package/dist/layer2/model-supply-chain.js.map +1 -0
  137. package/dist/layer2/risky-imports.d.ts.map +1 -1
  138. package/dist/layer2/risky-imports.js +4 -0
  139. package/dist/layer2/risky-imports.js.map +1 -1
  140. package/dist/layer2/variables.d.ts.map +1 -1
  141. package/dist/layer2/variables.js +4 -0
  142. package/dist/layer2/variables.js.map +1 -1
  143. package/dist/layer3/anthropic/auto-dismiss.d.ts +24 -0
  144. package/dist/layer3/anthropic/auto-dismiss.d.ts.map +1 -0
  145. package/dist/layer3/anthropic/auto-dismiss.js +188 -0
  146. package/dist/layer3/anthropic/auto-dismiss.js.map +1 -0
  147. package/dist/layer3/anthropic/clients.d.ts +44 -0
  148. package/dist/layer3/anthropic/clients.d.ts.map +1 -0
  149. package/dist/layer3/anthropic/clients.js +81 -0
  150. package/dist/layer3/anthropic/clients.js.map +1 -0
  151. package/dist/layer3/anthropic/index.d.ts +41 -0
  152. package/dist/layer3/anthropic/index.d.ts.map +1 -0
  153. package/dist/layer3/anthropic/index.js +141 -0
  154. package/dist/layer3/anthropic/index.js.map +1 -0
  155. package/dist/layer3/anthropic/prompts/index.d.ts +8 -0
  156. package/dist/layer3/anthropic/prompts/index.d.ts.map +1 -0
  157. package/dist/layer3/anthropic/prompts/index.js +14 -0
  158. package/dist/layer3/anthropic/prompts/index.js.map +1 -0
  159. package/dist/layer3/anthropic/prompts/semantic-analysis.d.ts +15 -0
  160. package/dist/layer3/anthropic/prompts/semantic-analysis.d.ts.map +1 -0
  161. package/dist/layer3/anthropic/prompts/semantic-analysis.js +169 -0
  162. package/dist/layer3/anthropic/prompts/semantic-analysis.js.map +1 -0
  163. package/dist/layer3/anthropic/prompts/validation.d.ts +12 -0
  164. package/dist/layer3/anthropic/prompts/validation.d.ts.map +1 -0
  165. package/dist/layer3/anthropic/prompts/validation.js +421 -0
  166. package/dist/layer3/anthropic/prompts/validation.js.map +1 -0
  167. package/dist/layer3/anthropic/providers/anthropic.d.ts +21 -0
  168. package/dist/layer3/anthropic/providers/anthropic.d.ts.map +1 -0
  169. package/dist/layer3/anthropic/providers/anthropic.js +266 -0
  170. package/dist/layer3/anthropic/providers/anthropic.js.map +1 -0
  171. package/dist/layer3/anthropic/providers/index.d.ts +8 -0
  172. package/dist/layer3/anthropic/providers/index.d.ts.map +1 -0
  173. package/dist/layer3/anthropic/providers/index.js +15 -0
  174. package/dist/layer3/anthropic/providers/index.js.map +1 -0
  175. package/dist/layer3/anthropic/providers/openai.d.ts +18 -0
  176. package/dist/layer3/anthropic/providers/openai.d.ts.map +1 -0
  177. package/dist/layer3/anthropic/providers/openai.js +340 -0
  178. package/dist/layer3/anthropic/providers/openai.js.map +1 -0
  179. package/dist/layer3/anthropic/request-builder.d.ts +20 -0
  180. package/dist/layer3/anthropic/request-builder.d.ts.map +1 -0
  181. package/dist/layer3/anthropic/request-builder.js +134 -0
  182. package/dist/layer3/anthropic/request-builder.js.map +1 -0
  183. package/dist/layer3/anthropic/types.d.ts +88 -0
  184. package/dist/layer3/anthropic/types.d.ts.map +1 -0
  185. package/dist/layer3/anthropic/types.js +38 -0
  186. package/dist/layer3/anthropic/types.js.map +1 -0
  187. package/dist/layer3/anthropic/utils/index.d.ts +9 -0
  188. package/dist/layer3/anthropic/utils/index.d.ts.map +1 -0
  189. package/dist/layer3/anthropic/utils/index.js +24 -0
  190. package/dist/layer3/anthropic/utils/index.js.map +1 -0
  191. package/dist/layer3/anthropic/utils/path-helpers.d.ts +21 -0
  192. package/dist/layer3/anthropic/utils/path-helpers.d.ts.map +1 -0
  193. package/dist/layer3/anthropic/utils/path-helpers.js +69 -0
  194. package/dist/layer3/anthropic/utils/path-helpers.js.map +1 -0
  195. package/dist/layer3/anthropic/utils/response-parser.d.ts +40 -0
  196. package/dist/layer3/anthropic/utils/response-parser.d.ts.map +1 -0
  197. package/dist/layer3/anthropic/utils/response-parser.js +285 -0
  198. package/dist/layer3/anthropic/utils/response-parser.js.map +1 -0
  199. package/dist/layer3/anthropic/utils/retry.d.ts +15 -0
  200. package/dist/layer3/anthropic/utils/retry.d.ts.map +1 -0
  201. package/dist/layer3/anthropic/utils/retry.js +62 -0
  202. package/dist/layer3/anthropic/utils/retry.js.map +1 -0
  203. package/dist/layer3/index.d.ts +1 -0
  204. package/dist/layer3/index.d.ts.map +1 -1
  205. package/dist/layer3/index.js +16 -6
  206. package/dist/layer3/index.js.map +1 -1
  207. package/dist/layer3/osv-check.d.ts +75 -0
  208. package/dist/layer3/osv-check.d.ts.map +1 -0
  209. package/dist/layer3/osv-check.js +308 -0
  210. package/dist/layer3/osv-check.js.map +1 -0
  211. package/dist/rules/framework-fixes.d.ts +48 -0
  212. package/dist/rules/framework-fixes.d.ts.map +1 -0
  213. package/dist/rules/framework-fixes.js +439 -0
  214. package/dist/rules/framework-fixes.js.map +1 -0
  215. package/dist/rules/index.d.ts +8 -0
  216. package/dist/rules/index.d.ts.map +1 -0
  217. package/dist/rules/index.js +18 -0
  218. package/dist/rules/index.js.map +1 -0
  219. package/dist/rules/metadata.d.ts +43 -0
  220. package/dist/rules/metadata.d.ts.map +1 -0
  221. package/dist/rules/metadata.js +734 -0
  222. package/dist/rules/metadata.js.map +1 -0
  223. package/dist/suppression/config-loader.d.ts +74 -0
  224. package/dist/suppression/config-loader.d.ts.map +1 -0
  225. package/dist/suppression/config-loader.js +424 -0
  226. package/dist/suppression/config-loader.js.map +1 -0
  227. package/dist/suppression/hash.d.ts +48 -0
  228. package/dist/suppression/hash.d.ts.map +1 -0
  229. package/dist/suppression/hash.js +88 -0
  230. package/dist/suppression/hash.js.map +1 -0
  231. package/dist/suppression/index.d.ts +11 -0
  232. package/dist/suppression/index.d.ts.map +1 -0
  233. package/dist/suppression/index.js +39 -0
  234. package/dist/suppression/index.js.map +1 -0
  235. package/dist/suppression/inline-parser.d.ts +39 -0
  236. package/dist/suppression/inline-parser.d.ts.map +1 -0
  237. package/dist/suppression/inline-parser.js +218 -0
  238. package/dist/suppression/inline-parser.js.map +1 -0
  239. package/dist/suppression/manager.d.ts +94 -0
  240. package/dist/suppression/manager.d.ts.map +1 -0
  241. package/dist/suppression/manager.js +292 -0
  242. package/dist/suppression/manager.js.map +1 -0
  243. package/dist/suppression/types.d.ts +151 -0
  244. package/dist/suppression/types.d.ts.map +1 -0
  245. package/dist/suppression/types.js +28 -0
  246. package/dist/suppression/types.js.map +1 -0
  247. package/dist/tiers.d.ts +1 -1
  248. package/dist/tiers.d.ts.map +1 -1
  249. package/dist/tiers.js +27 -0
  250. package/dist/tiers.js.map +1 -1
  251. package/dist/types.d.ts +62 -1
  252. package/dist/types.d.ts.map +1 -1
  253. package/dist/types.js.map +1 -1
  254. package/dist/utils/context-helpers.d.ts +4 -0
  255. package/dist/utils/context-helpers.d.ts.map +1 -1
  256. package/dist/utils/context-helpers.js +13 -9
  257. package/dist/utils/context-helpers.js.map +1 -1
  258. package/package.json +4 -2
  259. package/src/__tests__/benchmark/fixtures/layer1/mcp-config-audit.json +31 -0
  260. package/src/__tests__/benchmark/fixtures/layer2/ai-execution-sinks.ts +1489 -82
  261. package/src/__tests__/benchmark/fixtures/layer2/ai-mcp-security.ts +495 -0
  262. package/src/__tests__/benchmark/fixtures/layer2/ai-package-hallucination.ts +255 -0
  263. package/src/__tests__/benchmark/fixtures/layer2/ai-prompt-hygiene.ts +300 -1
  264. package/src/__tests__/benchmark/fixtures/layer2/ai-rag-safety.ts +139 -0
  265. package/src/__tests__/benchmark/fixtures/layer2/byok-patterns.ts +7 -0
  266. package/src/__tests__/benchmark/fixtures/layer2/data-exposure.ts +63 -0
  267. package/src/__tests__/benchmark/fixtures/layer2/excessive-agency.ts +221 -0
  268. package/src/__tests__/benchmark/fixtures/layer2/index.ts +18 -0
  269. package/src/__tests__/benchmark/fixtures/layer2/model-supply-chain.ts +204 -0
  270. package/src/__tests__/benchmark/fixtures/layer2/phase1-enhancements.ts +157 -0
  271. package/src/__tests__/snapshots/__snapshots__/anthropic-validation-refactor.test.ts.snap +758 -0
  272. package/src/__tests__/snapshots/__snapshots__/dangerous-functions-refactor.test.ts.snap +503 -0
  273. package/src/__tests__/snapshots/anthropic-validation-refactor.test.ts +321 -0
  274. package/src/__tests__/snapshots/dangerous-functions-refactor.test.ts +439 -0
  275. package/src/baseline/__tests__/diff.test.ts +261 -0
  276. package/src/baseline/__tests__/manager.test.ts +225 -0
  277. package/src/baseline/diff.ts +135 -0
  278. package/src/baseline/index.ts +29 -0
  279. package/src/baseline/manager.ts +230 -0
  280. package/src/baseline/types.ts +97 -0
  281. package/src/formatters/cli-terminal.ts +444 -41
  282. package/src/formatters/github-comment.ts +79 -11
  283. package/src/formatters/index.ts +4 -0
  284. package/src/index.ts +197 -14
  285. package/src/layer1/config-audit.ts +24 -3
  286. package/src/layer1/config-mcp-audit.ts +276 -0
  287. package/src/layer1/index.ts +16 -6
  288. package/src/layer2/ai-agent-tools.ts +336 -0
  289. package/src/layer2/ai-endpoint-protection.ts +16 -3
  290. package/src/layer2/ai-execution-sinks.ts +516 -12
  291. package/src/layer2/ai-fingerprinting.ts +5 -1
  292. package/src/layer2/ai-mcp-security.ts +730 -0
  293. package/src/layer2/ai-package-hallucination.ts +791 -0
  294. package/src/layer2/ai-prompt-hygiene.ts +547 -9
  295. package/src/layer2/ai-rag-safety.ts +382 -3
  296. package/src/layer2/auth-antipatterns.ts +5 -0
  297. package/src/layer2/byok-patterns.ts +5 -1
  298. package/src/layer2/dangerous-functions/child-process.ts +98 -0
  299. package/src/layer2/dangerous-functions/dom-xss.ts +220 -0
  300. package/src/layer2/dangerous-functions/index.ts +949 -0
  301. package/src/layer2/dangerous-functions/json-parse.ts +385 -0
  302. package/src/layer2/dangerous-functions/math-random.ts +537 -0
  303. package/src/layer2/dangerous-functions/patterns.ts +174 -0
  304. package/src/layer2/dangerous-functions/request-validation.ts +145 -0
  305. package/src/layer2/dangerous-functions/utils/control-flow.ts +162 -0
  306. package/src/layer2/dangerous-functions/utils/helpers.ts +170 -0
  307. package/src/layer2/dangerous-functions/utils/index.ts +25 -0
  308. package/src/layer2/dangerous-functions/utils/schema-validation.ts +91 -0
  309. package/src/layer2/data-exposure.ts +5 -1
  310. package/src/layer2/framework-checks.ts +5 -0
  311. package/src/layer2/index.ts +63 -1
  312. package/src/layer2/logic-gates.ts +5 -0
  313. package/src/layer2/model-supply-chain.ts +456 -0
  314. package/src/layer2/risky-imports.ts +5 -0
  315. package/src/layer2/variables.ts +5 -0
  316. package/src/layer3/__tests__/osv-check.test.ts +384 -0
  317. package/src/layer3/anthropic/auto-dismiss.ts +212 -0
  318. package/src/layer3/anthropic/clients.ts +84 -0
  319. package/src/layer3/anthropic/index.ts +170 -0
  320. package/src/layer3/anthropic/prompts/index.ts +14 -0
  321. package/src/layer3/anthropic/prompts/semantic-analysis.ts +173 -0
  322. package/src/layer3/anthropic/prompts/validation.ts +419 -0
  323. package/src/layer3/anthropic/providers/anthropic.ts +310 -0
  324. package/src/layer3/anthropic/providers/index.ts +8 -0
  325. package/src/layer3/anthropic/providers/openai.ts +384 -0
  326. package/src/layer3/anthropic/request-builder.ts +150 -0
  327. package/src/layer3/anthropic/types.ts +148 -0
  328. package/src/layer3/anthropic/utils/index.ts +26 -0
  329. package/src/layer3/anthropic/utils/path-helpers.ts +68 -0
  330. package/src/layer3/anthropic/utils/response-parser.ts +322 -0
  331. package/src/layer3/anthropic/utils/retry.ts +75 -0
  332. package/src/layer3/index.ts +18 -5
  333. package/src/layer3/osv-check.ts +420 -0
  334. package/src/rules/__tests__/framework-fixes.test.ts +689 -0
  335. package/src/rules/__tests__/metadata.test.ts +218 -0
  336. package/src/rules/framework-fixes.ts +470 -0
  337. package/src/rules/index.ts +21 -0
  338. package/src/rules/metadata.ts +831 -0
  339. package/src/suppression/__tests__/config-loader.test.ts +382 -0
  340. package/src/suppression/__tests__/hash.test.ts +166 -0
  341. package/src/suppression/__tests__/inline-parser.test.ts +212 -0
  342. package/src/suppression/__tests__/manager.test.ts +415 -0
  343. package/src/suppression/config-loader.ts +462 -0
  344. package/src/suppression/hash.ts +95 -0
  345. package/src/suppression/index.ts +51 -0
  346. package/src/suppression/inline-parser.ts +273 -0
  347. package/src/suppression/manager.ts +379 -0
  348. package/src/suppression/types.ts +174 -0
  349. package/src/tiers.ts +36 -0
  350. package/src/types.ts +90 -0
  351. package/src/utils/context-helpers.ts +13 -9
  352. package/dist/layer2/dangerous-functions.d.ts +0 -7
  353. package/dist/layer2/dangerous-functions.d.ts.map +0 -1
  354. package/dist/layer2/dangerous-functions.js +0 -1701
  355. package/dist/layer2/dangerous-functions.js.map +0 -1
  356. package/dist/layer3/anthropic.d.ts +0 -87
  357. package/dist/layer3/anthropic.d.ts.map +0 -1
  358. package/dist/layer3/anthropic.js +0 -1948
  359. package/dist/layer3/anthropic.js.map +0 -1
  360. package/dist/layer3/openai.d.ts +0 -25
  361. package/dist/layer3/openai.d.ts.map +0 -1
  362. package/dist/layer3/openai.js +0 -238
  363. package/dist/layer3/openai.js.map +0 -1
  364. package/src/layer2/dangerous-functions.ts +0 -1940
  365. package/src/layer3/anthropic.ts +0 -2257
@@ -0,0 +1,31 @@
1
+ /**
2
+ * JSON.parse Detection
3
+ *
4
+ * Source-aware detection of JSON.parse usage with severity classification
5
+ * based on the data source and error handling context.
6
+ */
7
+ import type { Vulnerability } from '../../types';
8
+ /**
9
+ * JSON.parse source classification
10
+ * Determines if the input is user-controlled or internal data
11
+ */
12
+ export type JSONParseSource = 'user_input' | 'local_storage' | 'database' | 'config' | 'migration' | 'internal' | 'test_fixture' | 'ui_state' | 'unknown';
13
+ /**
14
+ * Check if file path indicates a low-risk context for JSON.parse
15
+ */
16
+ export declare function isLowRiskJSONParseFile(filePath: string): JSONParseSource | null;
17
+ /**
18
+ * Check if JSON.parse is parsing a trusted SDK response
19
+ * These are well-defined responses from known APIs and are safe to parse
20
+ */
21
+ export declare function isTrustedSDKResponse(lineContent: string, content: string): boolean;
22
+ /**
23
+ * Classify the source of data being passed to JSON.parse
24
+ */
25
+ export declare function classifyJSONParseSource(lineContent: string, filePath: string): JSONParseSource;
26
+ /**
27
+ * Detect JSON.parse usage with source-aware severity
28
+ * Much smarter than simple pattern matching - considers try/catch and data source
29
+ */
30
+ export declare function detectJSONParseSafe(content: string, filePath: string, isTestFile: boolean, vulnerabilities: Vulnerability[]): void;
31
+ //# sourceMappingURL=json-parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-parse.d.ts","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/json-parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAA;AAKvE;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ,eAAe,GACf,UAAU,GACV,QAAQ,GACR,WAAW,GACX,UAAU,GACV,cAAc,GACd,UAAU,GACV,SAAS,CAAA;AAEb;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA+C/E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CA0BlF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,eAAe,CAoEjB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,OAAO,EACnB,eAAe,EAAE,aAAa,EAAE,GAC/B,IAAI,CA4LN"}
@@ -0,0 +1,319 @@
1
+ "use strict";
2
+ /**
3
+ * JSON.parse Detection
4
+ *
5
+ * Source-aware detection of JSON.parse usage with severity classification
6
+ * based on the data source and error handling context.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isLowRiskJSONParseFile = isLowRiskJSONParseFile;
10
+ exports.isTrustedSDKResponse = isTrustedSDKResponse;
11
+ exports.classifyJSONParseSource = classifyJSONParseSource;
12
+ exports.detectJSONParseSafe = detectJSONParseSafe;
13
+ const context_helpers_1 = require("../../utils/context-helpers");
14
+ const control_flow_1 = require("./utils/control-flow");
15
+ const schema_validation_1 = require("./utils/schema-validation");
16
+ /**
17
+ * Check if file path indicates a low-risk context for JSON.parse
18
+ */
19
+ function isLowRiskJSONParseFile(filePath) {
20
+ // Test/mock files - skip or info only
21
+ if ((0, context_helpers_1.isTestOrMockFile)(filePath)) {
22
+ return 'test_fixture';
23
+ }
24
+ // Settings/preferences components - internal UI state
25
+ if (/\/(components|pages)\/(settings|preferences|config)/i.test(filePath)) {
26
+ return 'ui_state';
27
+ }
28
+ // Provider/context files - typically storing state in localStorage
29
+ if (/Provider\.(ts|tsx|js|jsx)$/i.test(filePath)) {
30
+ return 'ui_state';
31
+ }
32
+ // Modal/Dialog components - typically internal state
33
+ if (/(Modal|Dialog|Settings|Preferences)\.(ts|tsx|js|jsx)$/i.test(filePath)) {
34
+ return 'ui_state';
35
+ }
36
+ // __mocks__ directory
37
+ if (/__mocks__/i.test(filePath)) {
38
+ return 'test_fixture';
39
+ }
40
+ // fixtures directory
41
+ if (/\/(fixtures?|stubs?|mocks?)\//i.test(filePath)) {
42
+ return 'test_fixture';
43
+ }
44
+ // scripts/tools directories (internal tooling)
45
+ if (/\/(scripts?|tools?|cli)\//i.test(filePath)) {
46
+ return 'internal';
47
+ }
48
+ // Migration files
49
+ if (/migration/i.test(filePath)) {
50
+ return 'migration';
51
+ }
52
+ // Config files
53
+ if (/\/(config|settings|constants)\.(ts|js)/i.test(filePath)) {
54
+ return 'config';
55
+ }
56
+ return null;
57
+ }
58
+ /**
59
+ * Check if JSON.parse is parsing a trusted SDK response
60
+ * These are well-defined responses from known APIs and are safe to parse
61
+ */
62
+ function isTrustedSDKResponse(lineContent, content) {
63
+ const trustedPatterns = [
64
+ // OpenAI SDK responses
65
+ /JSON\.parse\s*\(\s*(?:response|completion|result|message)\.(?:content|text|data)/i,
66
+ /JSON\.parse\s*\(\s*(?:openai|anthropic|client)\./i,
67
+ // Fetch response.json() result (already parsed by fetch)
68
+ /JSON\.parse\s*\(\s*await\s+.*\.json\s*\(\s*\)\s*\)/i,
69
+ // SDK method results
70
+ /JSON\.parse\s*\(\s*(?:result|response)\.(?:choices|content|data|body)\[/i,
71
+ // AI SDK streaming results
72
+ /JSON\.parse\s*\(\s*(?:chunk|delta|part)\.(?:content|text)/i,
73
+ ];
74
+ if (trustedPatterns.some(p => p.test(lineContent))) {
75
+ return true;
76
+ }
77
+ // Check surrounding context for SDK usage
78
+ const sdkContextPatterns = [
79
+ /openai\..*\.create/i,
80
+ /anthropic\..*\.create/i,
81
+ /\.chat\.completions/i,
82
+ /\.messages\.create/i,
83
+ ];
84
+ return sdkContextPatterns.some(p => p.test(content));
85
+ }
86
+ /**
87
+ * Classify the source of data being passed to JSON.parse
88
+ */
89
+ function classifyJSONParseSource(lineContent, filePath) {
90
+ // First check file path for low-risk contexts
91
+ const fileBasedSource = isLowRiskJSONParseFile(filePath);
92
+ if (fileBasedSource) {
93
+ return fileBasedSource;
94
+ }
95
+ // User input - potentially dangerous
96
+ const userInputPatterns = [
97
+ /JSON\.parse\s*\(\s*(req|request)\.(body|query|params)/i,
98
+ /JSON\.parse\s*\(\s*event\.(body|queryStringParameters)/i, // AWS Lambda
99
+ /JSON\.parse\s*\(\s*ctx\.(request|body|query)/i, // Koa
100
+ /JSON\.parse\s*\(\s*(input|userInput|rawInput|payload)/i,
101
+ /JSON\.parse\s*\(\s*body\b/i, // Generic 'body' often means request body
102
+ ];
103
+ if (userInputPatterns.some(p => p.test(lineContent))) {
104
+ return 'user_input';
105
+ }
106
+ // localStorage/sessionStorage - client-side storage
107
+ const storagePatterns = [
108
+ /JSON\.parse\s*\(\s*localStorage\.getItem/i,
109
+ /JSON\.parse\s*\(\s*sessionStorage\.getItem/i,
110
+ /JSON\.parse\s*\(\s*window\.localStorage/i,
111
+ /JSON\.parse\s*\(\s*storage\.get/i,
112
+ /JSON\.parse\s*\(\s*saved\b/i, // Common pattern: const saved = localStorage.getItem(...); JSON.parse(saved)
113
+ /JSON\.parse\s*\(\s*stored\b/i,
114
+ ];
115
+ if (storagePatterns.some(p => p.test(lineContent))) {
116
+ return 'local_storage';
117
+ }
118
+ // Database results - internal data
119
+ const databasePatterns = [
120
+ /JSON\.parse\s*\(\s*(row|result|record|doc|document)\./i,
121
+ /JSON\.parse\s*\(\s*\w+\.(data|json|metadata|embedding)\)/i,
122
+ /JSON\.parse\s*\(\s*\w+\[['"]?\w+['"]?\]\.(data|json|embedding)/i,
123
+ /JSON\.parse\s*\(\s*item\.\w+\)/i, // ORM iteration: items.map(item => JSON.parse(item.field))
124
+ /JSON\.parse\s*\(\s*\w+\.content\)/i, // Parsing content field from DB
125
+ ];
126
+ if (databasePatterns.some(p => p.test(lineContent))) {
127
+ return 'database';
128
+ }
129
+ // Editor state, internal caches, UI state
130
+ const internalPatterns = [
131
+ /JSON\.parse\s*\(\s*(state|cache|stored|saved|cached)/i,
132
+ /JSON\.parse\s*\(\s*this\.(state|cache|data)/i,
133
+ /JSON\.parse\s*\(\s*\w+State\)/i,
134
+ /JSON\.parse\s*\(\s*editorState/i,
135
+ /JSON\.parse\s*\(\s*parsed\b/i, // JSON.parse(parsed) - likely already validated
136
+ /JSON\.parse\s*\(\s*settings\b/i, // Settings data
137
+ /JSON\.parse\s*\(\s*preferences\b/i,
138
+ ];
139
+ if (internalPatterns.some(p => p.test(lineContent))) {
140
+ return 'internal';
141
+ }
142
+ // Node content in editor apps (e.g., noda-os nodes have JSON content)
143
+ if (/JSON\.parse\s*\(\s*(node|note|document|entry)\.(content|body|data)\)/i.test(lineContent)) {
144
+ return 'database';
145
+ }
146
+ return 'unknown';
147
+ }
148
+ /**
149
+ * Detect JSON.parse usage with source-aware severity
150
+ * Much smarter than simple pattern matching - considers try/catch and data source
151
+ */
152
+ function detectJSONParseSafe(content, filePath, isTestFile, vulnerabilities) {
153
+ const lines = content.split('\n');
154
+ const jsonParsePattern = /JSON\.parse\s*\(/gi;
155
+ // Track instances per file to aggregate noisy patterns
156
+ const instances = [];
157
+ lines.forEach((line, index) => {
158
+ if ((0, context_helpers_1.isComment)(line))
159
+ return;
160
+ jsonParsePattern.lastIndex = 0;
161
+ if (!jsonParsePattern.test(line))
162
+ return;
163
+ const jsonSource = classifyJSONParseSource(line, filePath);
164
+ // Skip migration files entirely - they're internal tooling
165
+ if (jsonSource === 'migration')
166
+ return;
167
+ // Skip test fixtures entirely - they're intentionally parsing test data
168
+ if (jsonSource === 'test_fixture')
169
+ return;
170
+ // Skip trusted SDK responses - these are well-defined and safe to parse
171
+ if (isTrustedSDKResponse(line, content))
172
+ return;
173
+ // Check if JSON.parse is inside a try-catch block
174
+ const insideTryCatch = (0, control_flow_1.isInsideTryCatch)(content, index) || (0, control_flow_1.hasTryCatchNearby)(content, index);
175
+ // Check if schema validation is applied after JSON.parse
176
+ const hasSchemaValidation = (0, schema_validation_1.hasSchemaValidationNearby)(content, index);
177
+ // If inside try-catch with safe source, suppress entirely - this is perfectly fine
178
+ if (insideTryCatch &&
179
+ ['local_storage', 'database', 'config', 'internal', 'ui_state'].includes(jsonSource)) {
180
+ return;
181
+ }
182
+ // If schema validation is present, this is properly handled
183
+ if (hasSchemaValidation) {
184
+ return;
185
+ }
186
+ // UI state (settings, providers, modals) - very low risk, aggregate or skip
187
+ if (jsonSource === 'ui_state') {
188
+ // Only track for aggregation, don't report individually
189
+ instances.push({
190
+ lineNumber: index + 1,
191
+ lineContent: line.trim(),
192
+ source: jsonSource,
193
+ });
194
+ return;
195
+ }
196
+ // Determine severity based on source and error handling
197
+ let severity;
198
+ let description;
199
+ let suggestedFix;
200
+ let confidence = 'medium';
201
+ if (insideTryCatch) {
202
+ // Already has error handling
203
+ switch (jsonSource) {
204
+ case 'user_input':
205
+ severity = 'low';
206
+ description =
207
+ 'JSON.parse on user input is wrapped in try-catch. Consider adding schema validation (zod/yup) to validate the parsed structure.';
208
+ suggestedFix =
209
+ 'Add schema validation after parsing: const validated = schema.parse(JSON.parse(input))';
210
+ confidence = 'low';
211
+ break;
212
+ default:
213
+ // With try-catch and non-user source, this is fine - don't report
214
+ return;
215
+ }
216
+ }
217
+ else {
218
+ // No try-catch
219
+ switch (jsonSource) {
220
+ case 'user_input':
221
+ severity = 'medium';
222
+ description =
223
+ 'JSON.parse on user input without schema validation. Malformed input will crash; malicious input may have unexpected shape.';
224
+ suggestedFix =
225
+ 'Use a schema validation library (zod, yup, joi): try { const data = schema.parse(JSON.parse(body)) } catch (e) { return 400 }';
226
+ confidence = 'high';
227
+ break;
228
+ case 'local_storage':
229
+ severity = 'info';
230
+ description =
231
+ 'JSON.parse on localStorage data. Consider adding try-catch for robustness against corrupted data.';
232
+ suggestedFix =
233
+ 'Wrap in try-catch to handle corrupted localStorage gracefully.';
234
+ confidence = 'low';
235
+ break;
236
+ case 'database':
237
+ // Database content parsing is very common and low-risk
238
+ instances.push({
239
+ lineNumber: index + 1,
240
+ lineContent: line.trim(),
241
+ source: jsonSource,
242
+ });
243
+ return; // Will be aggregated below
244
+ case 'config':
245
+ case 'internal':
246
+ severity = 'info';
247
+ description = `JSON.parse on ${jsonSource.replace('_', ' ')} data without error handling. Low risk but consider defensive coding.`;
248
+ suggestedFix = 'Consider adding try-catch for robustness.';
249
+ confidence = 'low';
250
+ break;
251
+ default:
252
+ // Unknown source - track for potential aggregation
253
+ instances.push({
254
+ lineNumber: index + 1,
255
+ lineContent: line.trim(),
256
+ source: jsonSource,
257
+ });
258
+ return; // Will be evaluated below based on aggregation
259
+ }
260
+ }
261
+ // Downgrade test files
262
+ if (isTestFile) {
263
+ severity = 'info';
264
+ confidence = 'low';
265
+ description += ' (in test file)';
266
+ }
267
+ vulnerabilities.push({
268
+ id: `json-parse-${filePath}-${index + 1}`,
269
+ filePath,
270
+ lineNumber: index + 1,
271
+ lineContent: line.trim(),
272
+ severity,
273
+ category: 'dangerous_function',
274
+ title: 'JSON.parse usage',
275
+ description,
276
+ suggestedFix,
277
+ confidence,
278
+ layer: 2,
279
+ });
280
+ });
281
+ // Aggregate low-risk JSON.parse instances if there are many
282
+ if (instances.length >= 3) {
283
+ // Create single aggregated finding instead of N individual findings
284
+ const lineNumbers = instances.map(i => i.lineNumber).slice(0, 5);
285
+ const moreText = instances.length > 5 ? `... (${instances.length} total)` : '';
286
+ vulnerabilities.push({
287
+ id: `json-parse-aggregated-${filePath}`,
288
+ filePath,
289
+ lineNumber: instances[0].lineNumber,
290
+ lineContent: `${instances.length} instances across this file`,
291
+ severity: 'info',
292
+ category: 'dangerous_function',
293
+ title: `JSON.parse usage (${instances.length} instances)`,
294
+ description: `JSON.parse detected. Consider adding error handling and schema validation if parsing user input.${isTestFile ? ' (in test file)' : ''}\n\nFound ${instances.length} occurrences at lines: ${lineNumbers.join(', ')}${moreText}`,
295
+ suggestedFix: 'Add try-catch for error handling. If parsing user input, add schema validation.',
296
+ confidence: 'low',
297
+ layer: 2,
298
+ });
299
+ }
300
+ else if (instances.length > 0 && instances.length < 3) {
301
+ // Report individually for small counts
302
+ for (const instance of instances) {
303
+ vulnerabilities.push({
304
+ id: `json-parse-${filePath}-${instance.lineNumber}`,
305
+ filePath,
306
+ lineNumber: instance.lineNumber,
307
+ lineContent: instance.lineContent,
308
+ severity: 'info',
309
+ category: 'dangerous_function',
310
+ title: 'JSON.parse usage',
311
+ description: `JSON.parse on ${instance.source.replace('_', ' ')} data without error handling. Low risk but consider defensive coding.${isTestFile ? ' (in test file)' : ''}`,
312
+ suggestedFix: 'Consider adding try-catch for robustness.',
313
+ confidence: 'low',
314
+ layer: 2,
315
+ });
316
+ }
317
+ }
318
+ }
319
+ //# sourceMappingURL=json-parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-parse.js","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/json-parse.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAyBH,wDA+CC;AAMD,oDA0BC;AAKD,0DAuEC;AAMD,kDAiMC;AA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EAAE,oBAAoB;YAC9B,KAAK,EAAE,qBAAqB,SAAS,CAAC,MAAM,aAAa;YACzD,WAAW,EAAE,mGAAmG,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,aAAa,SAAS,CAAC,MAAM,0BAA0B,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,EAAE;YAC7O,YAAY,EACV,iFAAiF;YACnF,UAAU,EAAE,KAAK;YACjB,KAAK,EAAE,CAAC;SACT,CAAC,CAAA;IACJ,CAAC;SAAM,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxD,uCAAuC;QACvC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,eAAe,CAAC,IAAI,CAAC;gBACnB,EAAE,EAAE,cAAc,QAAQ,IAAI,QAAQ,CAAC,UAAU,EAAE;gBACnD,QAAQ;gBACR,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,WAAW,EAAE,QAAQ,CAAC,WAAW;gBACjC,QAAQ,EAAE,MAAM;gBAChB,QAAQ,EAAE,oBAAoB;gBAC9B,KAAK,EAAE,kBAAkB;gBACzB,WAAW,EAAE,iBAAiB,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,wEAAwE,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC5K,YAAY,EAAE,2CAA2C;gBACzD,UAAU,EAAE,KAAK;gBACjB,KAAK,EAAE,CAAC;aACT,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Math.random() Detection
3
+ *
4
+ * Context-aware detection of Math.random() usage with intelligent severity
5
+ * classification based on usage context, variable names, and function intent.
6
+ */
7
+ /**
8
+ * Check if Math.random() is used for cosmetic/UI purposes (not security)
9
+ * Cosmetic uses: CSS values, animations, UI variations, demo data
10
+ * Security uses: tokens, IDs, cryptographic operations, session management
11
+ */
12
+ export declare function isCosmeticMathRandom(lineContent: string, content: string, lineNumber: number): boolean;
13
+ /**
14
+ * Classify function intent based on function name
15
+ * Used to determine if Math.random() usage is legitimate
16
+ */
17
+ export declare function classifyFunctionIntent(functionName: string | null): 'uuid' | 'captcha' | 'demo' | 'security' | 'unknown';
18
+ /**
19
+ * Analyze toString() pattern in Math.random() usage
20
+ * Determines intent based on base and truncation length
21
+ */
22
+ export declare function analyzeToStringPattern(lineContent: string): {
23
+ hasToString: boolean;
24
+ base: number | null;
25
+ isTruncated: boolean;
26
+ truncationLength: number | null;
27
+ intent: 'short-ui-id' | 'business-id' | 'full-token' | 'unknown';
28
+ };
29
+ /**
30
+ * Extract variable name from Math.random() assignment
31
+ * Examples:
32
+ * const token = Math.random() -> "token"
33
+ * const businessId = Math.random().toString(36) -> "businessId"
34
+ * return Math.random() -> null (no variable)
35
+ */
36
+ export declare function extractMathRandomVariableName(lineContent: string): string | null;
37
+ /**
38
+ * Classify variable name security risk based on naming patterns
39
+ *
40
+ * High risk: Security-sensitive names (token, secret, key, etc.)
41
+ * Medium risk: Unclear context
42
+ * Low risk: Non-security names (id, businessId, orderId, etc.)
43
+ */
44
+ export declare function classifyVariableNameRisk(varName: string | null): 'high' | 'medium' | 'low';
45
+ /**
46
+ * Analyze surrounding code context for security signals
47
+ * Returns context type and description for severity classification
48
+ */
49
+ export declare function analyzeMathRandomContext(content: string, filePath: string, lineNumber: number): {
50
+ inSecurityContext: boolean;
51
+ inTestContext: boolean;
52
+ inUIContext: boolean;
53
+ inBusinessLogicContext: boolean;
54
+ contextDescription: string;
55
+ };
56
+ /**
57
+ * Check if Math.random() should be skipped entirely
58
+ * Returns true for seed files, test fixtures, captcha/puzzle, uuid, and pure cosmetic uses
59
+ */
60
+ export declare function shouldSkipMathRandom(content: string, filePath: string, lineNumber: number): boolean;
61
+ //# sourceMappingURL=math-random.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math-random.d.ts","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/math-random.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CA8FT;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,GAAG,IAAI,GAC1B,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,CA+CtD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG;IAC3D,WAAW,EAAE,OAAO,CAAA;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,WAAW,EAAE,OAAO,CAAA;IACpB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,MAAM,EAAE,aAAa,GAAG,aAAa,GAAG,YAAY,GAAG,SAAS,CAAA;CACjE,CA0EA;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,IAAI,CAgBf;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,MAAM,GAAG,QAAQ,GAAG,KAAK,CAmG3B;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB;IACD,iBAAiB,EAAE,OAAO,CAAA;IAC1B,aAAa,EAAE,OAAO,CAAA;IACtB,WAAW,EAAE,OAAO,CAAA;IACpB,sBAAsB,EAAE,OAAO,CAAA;IAC/B,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CA8DA;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAA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