shield360 1.1.0 → 1.2.1

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 (400) hide show
  1. package/README.md +330 -3
  2. package/dist/__tests__/build-info.test.js +8 -1
  3. package/dist/__tests__/build-info.test.js.map +1 -1
  4. package/dist/__tests__/code-location.test.js +1 -1
  5. package/dist/__tests__/destination.test.js +15 -0
  6. package/dist/__tests__/destination.test.js.map +1 -1
  7. package/dist/__tests__/masking.test.d.ts +1 -0
  8. package/dist/__tests__/masking.test.js +66 -0
  9. package/dist/__tests__/masking.test.js.map +1 -0
  10. package/dist/__tests__/register.e2e.test.d.ts +1 -0
  11. package/dist/__tests__/register.e2e.test.js +279 -0
  12. package/dist/__tests__/register.e2e.test.js.map +1 -0
  13. package/dist/__tests__/register.test.js +60 -0
  14. package/dist/__tests__/register.test.js.map +1 -1
  15. package/dist/agents/__tests__/agents.test.d.ts +1 -0
  16. package/dist/agents/__tests__/agents.test.js +529 -0
  17. package/dist/agents/__tests__/agents.test.js.map +1 -0
  18. package/dist/agents/index.d.ts +15 -0
  19. package/dist/agents/index.js +25 -0
  20. package/dist/agents/index.js.map +1 -0
  21. package/dist/agents/passport.d.ts +92 -0
  22. package/dist/agents/passport.js +301 -0
  23. package/dist/agents/passport.js.map +1 -0
  24. package/dist/agents/policy.d.ts +24 -0
  25. package/dist/agents/policy.js +93 -0
  26. package/dist/agents/policy.js.map +1 -0
  27. package/dist/agents/replay.d.ts +20 -0
  28. package/dist/agents/replay.js +47 -0
  29. package/dist/agents/replay.js.map +1 -0
  30. package/dist/agents/report.d.ts +30 -0
  31. package/dist/agents/report.js +93 -0
  32. package/dist/agents/report.js.map +1 -0
  33. package/dist/agents/types.d.ts +148 -0
  34. package/dist/agents/types.js +37 -0
  35. package/dist/agents/types.js.map +1 -0
  36. package/dist/agents/verifier.d.ts +33 -0
  37. package/dist/agents/verifier.js +276 -0
  38. package/dist/agents/verifier.js.map +1 -0
  39. package/dist/ai-security/__tests__/bench.test.d.ts +1 -0
  40. package/dist/ai-security/__tests__/bench.test.js +50 -0
  41. package/dist/ai-security/__tests__/bench.test.js.map +1 -0
  42. package/dist/ai-security/__tests__/checks.test.d.ts +1 -0
  43. package/dist/ai-security/__tests__/checks.test.js +248 -0
  44. package/dist/ai-security/__tests__/checks.test.js.map +1 -0
  45. package/dist/ai-security/__tests__/config.test.d.ts +1 -0
  46. package/dist/ai-security/__tests__/config.test.js +164 -0
  47. package/dist/ai-security/__tests__/config.test.js.map +1 -0
  48. package/dist/ai-security/__tests__/detection.test.d.ts +1 -0
  49. package/dist/ai-security/__tests__/detection.test.js +114 -0
  50. package/dist/ai-security/__tests__/detection.test.js.map +1 -0
  51. package/dist/ai-security/__tests__/fixtures.d.ts +8 -0
  52. package/dist/ai-security/__tests__/fixtures.js +30 -0
  53. package/dist/ai-security/__tests__/fixtures.js.map +1 -0
  54. package/dist/ai-security/__tests__/hooks.test.d.ts +1 -0
  55. package/dist/ai-security/__tests__/hooks.test.js +174 -0
  56. package/dist/ai-security/__tests__/hooks.test.js.map +1 -0
  57. package/dist/ai-security/__tests__/stream.test.d.ts +1 -0
  58. package/dist/ai-security/__tests__/stream.test.js +85 -0
  59. package/dist/ai-security/__tests__/stream.test.js.map +1 -0
  60. package/dist/ai-security/config.d.ts +94 -0
  61. package/dist/ai-security/config.js +241 -0
  62. package/dist/ai-security/config.js.map +1 -0
  63. package/dist/ai-security/context.d.ts +45 -0
  64. package/dist/ai-security/context.js +108 -0
  65. package/dist/ai-security/context.js.map +1 -0
  66. package/dist/ai-security/custom-kinds.d.ts +23 -0
  67. package/dist/ai-security/custom-kinds.js +97 -0
  68. package/dist/ai-security/custom-kinds.js.map +1 -0
  69. package/dist/ai-security/events.d.ts +77 -0
  70. package/dist/ai-security/events.js +153 -0
  71. package/dist/ai-security/events.js.map +1 -0
  72. package/dist/ai-security/hooks.d.ts +48 -0
  73. package/dist/ai-security/hooks.js +461 -0
  74. package/dist/ai-security/hooks.js.map +1 -0
  75. package/dist/ai-security/index.d.ts +209 -0
  76. package/dist/ai-security/index.js +587 -0
  77. package/dist/ai-security/index.js.map +1 -0
  78. package/dist/ai-security/injection-rules.json +1024 -0
  79. package/dist/ai-security/injection.d.ts +46 -0
  80. package/dist/ai-security/injection.js +635 -0
  81. package/dist/ai-security/injection.js.map +1 -0
  82. package/dist/ai-security/jailbreak.d.ts +38 -0
  83. package/dist/ai-security/jailbreak.js +73 -0
  84. package/dist/ai-security/jailbreak.js.map +1 -0
  85. package/dist/ai-security/limits.d.ts +84 -0
  86. package/dist/ai-security/limits.js +195 -0
  87. package/dist/ai-security/limits.js.map +1 -0
  88. package/dist/ai-security/mcp.d.ts +82 -0
  89. package/dist/ai-security/mcp.js +150 -0
  90. package/dist/ai-security/mcp.js.map +1 -0
  91. package/dist/ai-security/output.d.ts +107 -0
  92. package/dist/ai-security/output.js +390 -0
  93. package/dist/ai-security/output.js.map +1 -0
  94. package/dist/ai-security/policy.d.ts +125 -0
  95. package/dist/ai-security/policy.js +196 -0
  96. package/dist/ai-security/policy.js.map +1 -0
  97. package/dist/ai-security/rag.d.ts +70 -0
  98. package/dist/ai-security/rag.js +174 -0
  99. package/dist/ai-security/rag.js.map +1 -0
  100. package/dist/ai-security/tool-rules.json +203 -0
  101. package/dist/ai-security/tools.d.ts +46 -0
  102. package/dist/ai-security/tools.js +62 -0
  103. package/dist/ai-security/tools.js.map +1 -0
  104. package/dist/budgets/__tests__/budgets.test.d.ts +1 -0
  105. package/dist/budgets/__tests__/budgets.test.js +134 -0
  106. package/dist/budgets/__tests__/budgets.test.js.map +1 -0
  107. package/dist/budgets/auto.d.ts +25 -0
  108. package/dist/budgets/auto.js +63 -0
  109. package/dist/budgets/auto.js.map +1 -0
  110. package/dist/budgets/index.d.ts +110 -0
  111. package/dist/budgets/index.js +239 -0
  112. package/dist/budgets/index.js.map +1 -0
  113. package/dist/customer/__tests__/customer.test.d.ts +1 -0
  114. package/dist/customer/__tests__/customer.test.js +155 -0
  115. package/dist/customer/__tests__/customer.test.js.map +1 -0
  116. package/dist/customer/index.d.ts +48 -0
  117. package/dist/customer/index.js +132 -0
  118. package/dist/customer/index.js.map +1 -0
  119. package/dist/destination.d.ts +14 -0
  120. package/dist/destination.js +16 -0
  121. package/dist/destination.js.map +1 -1
  122. package/dist/feedback/__tests__/feedback.test.d.ts +1 -0
  123. package/dist/feedback/__tests__/feedback.test.js +80 -0
  124. package/dist/feedback/__tests__/feedback.test.js.map +1 -0
  125. package/dist/feedback/index.d.ts +48 -0
  126. package/dist/feedback/index.js +97 -0
  127. package/dist/feedback/index.js.map +1 -0
  128. package/dist/flags/__tests__/flags.test.d.ts +1 -0
  129. package/dist/flags/__tests__/flags.test.js +301 -0
  130. package/dist/flags/__tests__/flags.test.js.map +1 -0
  131. package/dist/flags/client.d.ts +131 -0
  132. package/dist/flags/client.js +301 -0
  133. package/dist/flags/client.js.map +1 -0
  134. package/dist/flags/engine.d.ts +200 -0
  135. package/dist/flags/engine.js +677 -0
  136. package/dist/flags/engine.js.map +1 -0
  137. package/dist/flags/index.d.ts +4 -0
  138. package/dist/flags/index.js +16 -0
  139. package/dist/flags/index.js.map +1 -0
  140. package/dist/guard/__tests__/findings.test.js +1 -1
  141. package/dist/guard/__tests__/report.test.js +67 -0
  142. package/dist/guard/__tests__/report.test.js.map +1 -1
  143. package/dist/guard/heartbeat.d.ts +34 -0
  144. package/dist/guard/heartbeat.js +83 -0
  145. package/dist/guard/heartbeat.js.map +1 -0
  146. package/dist/guard/integration.d.ts +9 -0
  147. package/dist/guard/integration.js +4 -2
  148. package/dist/guard/integration.js.map +1 -1
  149. package/dist/guard/report.d.ts +24 -1
  150. package/dist/guard/report.js +67 -18
  151. package/dist/guard/report.js.map +1 -1
  152. package/dist/index.d.ts +88 -0
  153. package/dist/index.js +203 -2
  154. package/dist/index.js.map +1 -1
  155. package/dist/instrumentation/__tests__/langchain-wrapper.test.js +1 -1
  156. package/dist/instrumentation/__tests__/langchain-wrapper.test.js.map +1 -1
  157. package/dist/instrumentation/anthropic/wrapper.js +4 -0
  158. package/dist/instrumentation/anthropic/wrapper.js.map +1 -1
  159. package/dist/instrumentation/openai/wrapper.js +6 -0
  160. package/dist/instrumentation/openai/wrapper.js.map +1 -1
  161. package/dist/masking.d.ts +42 -0
  162. package/dist/masking.js +197 -0
  163. package/dist/masking.js.map +1 -0
  164. package/dist/otel/__tests__/app-logs-safety.test.d.ts +1 -0
  165. package/dist/otel/__tests__/app-logs-safety.test.js +129 -0
  166. package/dist/otel/__tests__/app-logs-safety.test.js.map +1 -0
  167. package/dist/otel/__tests__/app-logs.test.d.ts +1 -0
  168. package/dist/otel/__tests__/app-logs.test.js +269 -0
  169. package/dist/otel/__tests__/app-logs.test.js.map +1 -0
  170. package/dist/otel/__tests__/log-auto.test.d.ts +1 -0
  171. package/dist/otel/__tests__/log-auto.test.js +125 -0
  172. package/dist/otel/__tests__/log-auto.test.js.map +1 -0
  173. package/dist/otel/__tests__/log-bridges.test.d.ts +1 -0
  174. package/dist/otel/__tests__/log-bridges.test.js +170 -0
  175. package/dist/otel/__tests__/log-bridges.test.js.map +1 -0
  176. package/dist/otel/__tests__/system-metrics.test.d.ts +1 -0
  177. package/dist/otel/__tests__/system-metrics.test.js +79 -0
  178. package/dist/otel/__tests__/system-metrics.test.js.map +1 -0
  179. package/dist/otel/app-logs.d.ts +80 -0
  180. package/dist/otel/app-logs.js +195 -0
  181. package/dist/otel/app-logs.js.map +1 -0
  182. package/dist/otel/build-info.d.ts +2 -1
  183. package/dist/otel/build-info.js +3 -2
  184. package/dist/otel/build-info.js.map +1 -1
  185. package/dist/otel/events.d.ts +1 -0
  186. package/dist/otel/events.js +22 -13
  187. package/dist/otel/events.js.map +1 -1
  188. package/dist/otel/log-auto.d.ts +44 -0
  189. package/dist/otel/log-auto.js +200 -0
  190. package/dist/otel/log-auto.js.map +1 -0
  191. package/dist/otel/log-bridges.d.ts +54 -0
  192. package/dist/otel/log-bridges.js +307 -0
  193. package/dist/otel/log-bridges.js.map +1 -0
  194. package/dist/otel/metrics.js +1 -1
  195. package/dist/otel/metrics.js.map +1 -1
  196. package/dist/otel/system-metrics.d.ts +39 -0
  197. package/dist/otel/system-metrics.js +166 -0
  198. package/dist/otel/system-metrics.js.map +1 -0
  199. package/dist/otel/tracing.js +6 -2
  200. package/dist/otel/tracing.js.map +1 -1
  201. package/dist/protect/__tests__/protect.test.js +4 -0
  202. package/dist/protect/__tests__/protect.test.js.map +1 -1
  203. package/dist/protect/index.js +9 -4
  204. package/dist/protect/index.js.map +1 -1
  205. package/dist/rasp/__tests__/auto-http.test.d.ts +1 -0
  206. package/dist/rasp/__tests__/auto-http.test.js +136 -0
  207. package/dist/rasp/__tests__/auto-http.test.js.map +1 -0
  208. package/dist/rasp/__tests__/baseline.test.d.ts +1 -0
  209. package/dist/rasp/__tests__/baseline.test.js +86 -0
  210. package/dist/rasp/__tests__/baseline.test.js.map +1 -0
  211. package/dist/rasp/__tests__/benign-corpus.test.d.ts +1 -0
  212. package/dist/rasp/__tests__/benign-corpus.test.js +68 -0
  213. package/dist/rasp/__tests__/benign-corpus.test.js.map +1 -0
  214. package/dist/rasp/__tests__/capture-context.test.d.ts +1 -0
  215. package/dist/rasp/__tests__/capture-context.test.js +135 -0
  216. package/dist/rasp/__tests__/capture-context.test.js.map +1 -0
  217. package/dist/rasp/__tests__/code-hook.test.d.ts +1 -0
  218. package/dist/rasp/__tests__/code-hook.test.js +218 -0
  219. package/dist/rasp/__tests__/code-hook.test.js.map +1 -0
  220. package/dist/rasp/__tests__/config-client.test.d.ts +1 -0
  221. package/dist/rasp/__tests__/config-client.test.js +283 -0
  222. package/dist/rasp/__tests__/config-client.test.js.map +1 -0
  223. package/dist/rasp/__tests__/corpus.d.ts +13 -0
  224. package/dist/rasp/__tests__/corpus.js +111 -0
  225. package/dist/rasp/__tests__/corpus.js.map +1 -0
  226. package/dist/rasp/__tests__/custom-rules.test.d.ts +1 -0
  227. package/dist/rasp/__tests__/custom-rules.test.js +276 -0
  228. package/dist/rasp/__tests__/custom-rules.test.js.map +1 -0
  229. package/dist/rasp/__tests__/db-hook.test.d.ts +1 -0
  230. package/dist/rasp/__tests__/db-hook.test.js +438 -0
  231. package/dist/rasp/__tests__/db-hook.test.js.map +1 -0
  232. package/dist/rasp/__tests__/deception.test.d.ts +1 -0
  233. package/dist/rasp/__tests__/deception.test.js +567 -0
  234. package/dist/rasp/__tests__/deception.test.js.map +1 -0
  235. package/dist/rasp/__tests__/detect.test.d.ts +1 -0
  236. package/dist/rasp/__tests__/detect.test.js +276 -0
  237. package/dist/rasp/__tests__/detect.test.js.map +1 -0
  238. package/dist/rasp/__tests__/esm-exports.test.d.ts +1 -0
  239. package/dist/rasp/__tests__/esm-exports.test.js +20 -0
  240. package/dist/rasp/__tests__/esm-exports.test.js.map +1 -0
  241. package/dist/rasp/__tests__/fs-hook.test.d.ts +1 -0
  242. package/dist/rasp/__tests__/fs-hook.test.js +241 -0
  243. package/dist/rasp/__tests__/fs-hook.test.js.map +1 -0
  244. package/dist/rasp/__tests__/hook-contracts.test.d.ts +1 -0
  245. package/dist/rasp/__tests__/hook-contracts.test.js +201 -0
  246. package/dist/rasp/__tests__/hook-contracts.test.js.map +1 -0
  247. package/dist/rasp/__tests__/hook-kit.d.ts +42 -0
  248. package/dist/rasp/__tests__/hook-kit.js +139 -0
  249. package/dist/rasp/__tests__/hook-kit.js.map +1 -0
  250. package/dist/rasp/__tests__/http-hook.test.d.ts +1 -0
  251. package/dist/rasp/__tests__/http-hook.test.js +250 -0
  252. package/dist/rasp/__tests__/http-hook.test.js.map +1 -0
  253. package/dist/rasp/__tests__/iast.test.d.ts +1 -0
  254. package/dist/rasp/__tests__/iast.test.js +361 -0
  255. package/dist/rasp/__tests__/iast.test.js.map +1 -0
  256. package/dist/rasp/__tests__/include-hook.test.d.ts +1 -0
  257. package/dist/rasp/__tests__/include-hook.test.js +122 -0
  258. package/dist/rasp/__tests__/include-hook.test.js.map +1 -0
  259. package/dist/rasp/__tests__/middleware.test.d.ts +1 -0
  260. package/dist/rasp/__tests__/middleware.test.js +302 -0
  261. package/dist/rasp/__tests__/middleware.test.js.map +1 -0
  262. package/dist/rasp/__tests__/process-hook.test.d.ts +1 -0
  263. package/dist/rasp/__tests__/process-hook.test.js +238 -0
  264. package/dist/rasp/__tests__/process-hook.test.js.map +1 -0
  265. package/dist/rasp/__tests__/reporter.test.d.ts +1 -0
  266. package/dist/rasp/__tests__/reporter.test.js +114 -0
  267. package/dist/rasp/__tests__/reporter.test.js.map +1 -0
  268. package/dist/rasp/__tests__/route.test.d.ts +1 -0
  269. package/dist/rasp/__tests__/route.test.js +46 -0
  270. package/dist/rasp/__tests__/route.test.js.map +1 -0
  271. package/dist/rasp/__tests__/rule-expr.test.d.ts +1 -0
  272. package/dist/rasp/__tests__/rule-expr.test.js +151 -0
  273. package/dist/rasp/__tests__/rule-expr.test.js.map +1 -0
  274. package/dist/rasp/__tests__/rule-phases.test.d.ts +1 -0
  275. package/dist/rasp/__tests__/rule-phases.test.js +271 -0
  276. package/dist/rasp/__tests__/rule-phases.test.js.map +1 -0
  277. package/dist/rasp/__tests__/sinks-hook.test.d.ts +1 -0
  278. package/dist/rasp/__tests__/sinks-hook.test.js +177 -0
  279. package/dist/rasp/__tests__/sinks-hook.test.js.map +1 -0
  280. package/dist/rasp/__tests__/targets.test.d.ts +1 -0
  281. package/dist/rasp/__tests__/targets.test.js +82 -0
  282. package/dist/rasp/__tests__/targets.test.js.map +1 -0
  283. package/dist/rasp/__tests__/template-hook.test.d.ts +1 -0
  284. package/dist/rasp/__tests__/template-hook.test.js +254 -0
  285. package/dist/rasp/__tests__/template-hook.test.js.map +1 -0
  286. package/dist/rasp/__tests__/upload.test.d.ts +1 -0
  287. package/dist/rasp/__tests__/upload.test.js +81 -0
  288. package/dist/rasp/__tests__/upload.test.js.map +1 -0
  289. package/dist/rasp/__tests__/vpatch-engine.test.d.ts +1 -0
  290. package/dist/rasp/__tests__/vpatch-engine.test.js +177 -0
  291. package/dist/rasp/__tests__/vpatch-engine.test.js.map +1 -0
  292. package/dist/rasp/auto-http.d.ts +6 -0
  293. package/dist/rasp/auto-http.js +194 -0
  294. package/dist/rasp/auto-http.js.map +1 -0
  295. package/dist/rasp/baseline.d.ts +35 -0
  296. package/dist/rasp/baseline.js +91 -0
  297. package/dist/rasp/baseline.js.map +1 -0
  298. package/dist/rasp/capture.d.ts +76 -0
  299. package/dist/rasp/capture.js +304 -0
  300. package/dist/rasp/capture.js.map +1 -0
  301. package/dist/rasp/config-client.d.ts +122 -0
  302. package/dist/rasp/config-client.js +337 -0
  303. package/dist/rasp/config-client.js.map +1 -0
  304. package/dist/rasp/context.d.ts +65 -0
  305. package/dist/rasp/context.js +68 -0
  306. package/dist/rasp/context.js.map +1 -0
  307. package/dist/rasp/custom-rules.d.ts +68 -0
  308. package/dist/rasp/custom-rules.js +222 -0
  309. package/dist/rasp/custom-rules.js.map +1 -0
  310. package/dist/rasp/data/default-rules.json +199 -0
  311. package/dist/rasp/data/default-sinks.json +4 -0
  312. package/dist/rasp/data/dnslog-domains.json +11 -0
  313. package/dist/rasp/deception.d.ts +70 -0
  314. package/dist/rasp/deception.js +220 -0
  315. package/dist/rasp/deception.js.map +1 -0
  316. package/dist/rasp/detect.d.ts +68 -0
  317. package/dist/rasp/detect.js +671 -0
  318. package/dist/rasp/detect.js.map +1 -0
  319. package/dist/rasp/engine.d.ts +107 -0
  320. package/dist/rasp/engine.js +330 -0
  321. package/dist/rasp/engine.js.map +1 -0
  322. package/dist/rasp/hooks/code.d.ts +20 -0
  323. package/dist/rasp/hooks/code.js +334 -0
  324. package/dist/rasp/hooks/code.js.map +1 -0
  325. package/dist/rasp/hooks/db.d.ts +48 -0
  326. package/dist/rasp/hooks/db.js +322 -0
  327. package/dist/rasp/hooks/db.js.map +1 -0
  328. package/dist/rasp/hooks/esm.d.ts +7 -0
  329. package/dist/rasp/hooks/esm.js +18 -0
  330. package/dist/rasp/hooks/esm.js.map +1 -0
  331. package/dist/rasp/hooks/fs.d.ts +3 -0
  332. package/dist/rasp/hooks/fs.js +206 -0
  333. package/dist/rasp/hooks/fs.js.map +1 -0
  334. package/dist/rasp/hooks/http.d.ts +4 -0
  335. package/dist/rasp/hooks/http.js +213 -0
  336. package/dist/rasp/hooks/http.js.map +1 -0
  337. package/dist/rasp/hooks/include.d.ts +9 -0
  338. package/dist/rasp/hooks/include.js +79 -0
  339. package/dist/rasp/hooks/include.js.map +1 -0
  340. package/dist/rasp/hooks/marks.d.ts +2 -0
  341. package/dist/rasp/hooks/marks.js +16 -0
  342. package/dist/rasp/hooks/marks.js.map +1 -0
  343. package/dist/rasp/hooks/process.d.ts +22 -0
  344. package/dist/rasp/hooks/process.js +191 -0
  345. package/dist/rasp/hooks/process.js.map +1 -0
  346. package/dist/rasp/hooks/sinks.d.ts +54 -0
  347. package/dist/rasp/hooks/sinks.js +329 -0
  348. package/dist/rasp/hooks/sinks.js.map +1 -0
  349. package/dist/rasp/hooks/template.d.ts +21 -0
  350. package/dist/rasp/hooks/template.js +152 -0
  351. package/dist/rasp/hooks/template.js.map +1 -0
  352. package/dist/rasp/iast-rules.d.ts +82 -0
  353. package/dist/rasp/iast-rules.js +240 -0
  354. package/dist/rasp/iast-rules.js.map +1 -0
  355. package/dist/rasp/iast-scope.d.ts +29 -0
  356. package/dist/rasp/iast-scope.js +54 -0
  357. package/dist/rasp/iast-scope.js.map +1 -0
  358. package/dist/rasp/iast.d.ts +81 -0
  359. package/dist/rasp/iast.js +272 -0
  360. package/dist/rasp/iast.js.map +1 -0
  361. package/dist/rasp/index.d.ts +52 -0
  362. package/dist/rasp/index.js +280 -0
  363. package/dist/rasp/index.js.map +1 -0
  364. package/dist/rasp/lexers.d.ts +32 -0
  365. package/dist/rasp/lexers.js +444 -0
  366. package/dist/rasp/lexers.js.map +1 -0
  367. package/dist/rasp/middleware.d.ts +155 -0
  368. package/dist/rasp/middleware.js +568 -0
  369. package/dist/rasp/middleware.js.map +1 -0
  370. package/dist/rasp/model-output.d.ts +14 -0
  371. package/dist/rasp/model-output.js +107 -0
  372. package/dist/rasp/model-output.js.map +1 -0
  373. package/dist/rasp/normalize.d.ts +23 -0
  374. package/dist/rasp/normalize.js +140 -0
  375. package/dist/rasp/normalize.js.map +1 -0
  376. package/dist/rasp/reporter.d.ts +60 -0
  377. package/dist/rasp/reporter.js +230 -0
  378. package/dist/rasp/reporter.js.map +1 -0
  379. package/dist/rasp/rule-expr.d.ts +236 -0
  380. package/dist/rasp/rule-expr.js +1253 -0
  381. package/dist/rasp/rule-expr.js.map +1 -0
  382. package/dist/rasp/template.d.ts +53 -0
  383. package/dist/rasp/template.js +336 -0
  384. package/dist/rasp/template.js.map +1 -0
  385. package/dist/rasp/types.d.ts +110 -0
  386. package/dist/rasp/types.js +51 -0
  387. package/dist/rasp/types.js.map +1 -0
  388. package/dist/rasp/vpatch.d.ts +55 -0
  389. package/dist/rasp/vpatch.js +120 -0
  390. package/dist/rasp/vpatch.js.map +1 -0
  391. package/dist/register.js +52 -11
  392. package/dist/register.js.map +1 -1
  393. package/dist/semantic-convention.d.ts +2 -0
  394. package/dist/semantic-convention.js +5 -0
  395. package/dist/semantic-convention.js.map +1 -1
  396. package/dist/types.d.ts +77 -1
  397. package/dist/zero-code.d.ts +8 -0
  398. package/dist/zero-code.js +38 -0
  399. package/dist/zero-code.js.map +1 -0
  400. package/package.json +18 -2
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.installAutoHttpCapture = installAutoHttpCapture;
4
+ exports.uninstallAutoHttpCapture = uninstallAutoHttpCapture;
5
+ exports.autoHttpCaptureInstalled = autoHttpCaptureInstalled;
6
+ /**
7
+ * Zero-code request capture for RASP: every `http` and `https` server's
8
+ * `request` event runs inside a RASP request context, so sinks see the
9
+ * request's input without any framework middleware. `shield360/register`
10
+ * installs it when RASP is on.
11
+ *
12
+ * It patches `Server.prototype.emit` once, which covers Express, Fastify,
13
+ * Koa, Nest and raw `http` alike (they all serve through `http.Server`).
14
+ * A body a parser sets later on `req.body` is picked up when a sink first
15
+ * reads the inputs. Framework middleware added on top (`raspExpress()` and
16
+ * the others) replaces this context with its richer one and does not judge
17
+ * a phase this capture already judged (a custom rule matches at most once).
18
+ * A request with no body (no `Content-Length` or `Transfer-Encoding`) has a
19
+ * known, empty body here, so the body phase runs at once.
20
+ *
21
+ * Deception (deception.ts) runs here only for plain listeners, where the
22
+ * socket's peer is the client address and a plain `404 Not Found` is the
23
+ * normal answer: a decoy gets that 404 before the listener, and middleware
24
+ * added on top does not run deception again. When the listener is a framework
25
+ * app (Express 4/5, Koa, Fastify, and Nest on them), this capture never
26
+ * marks, judges or answers for deception: the framework knows the trusted
27
+ * client address (`trust proxy`) and has its own not-found, so its adapter
28
+ * (`raspExpress()`, `raspKoa()`, `raspFastify`) runs deception, and without
29
+ * the adapter such an app gets none.
30
+ *
31
+ * Fail open: when capture fails the request is served as before. A block
32
+ * thrown from a `request` listener, synchronously or as the rejection of an
33
+ * async listener (`http.createServer(async (req, res) => ...)`), becomes the
34
+ * contract's 403 instead of an unhandled rejection. Frameworks catch errors
35
+ * from their own route handlers, so a block raised there is the framework's to
36
+ * map (Express without `raspExpressErrorHandler()` answers a 500).
37
+ */
38
+ const events_1 = require("events");
39
+ const http = require("http");
40
+ const https = require("https");
41
+ const capture_1 = require("./capture");
42
+ const context_1 = require("./context");
43
+ const engine_1 = require("./engine");
44
+ const deception_1 = require("./deception");
45
+ const middleware_1 = require("./middleware");
46
+ const types_1 = require("./types");
47
+ const PATCHED = Symbol.for('shield360.rasp.autoHttp');
48
+ let patched = [];
49
+ const contentTypeOf = (req) => {
50
+ const v = req.headers?.['content-type'];
51
+ return typeof v === 'string' ? v : undefined;
52
+ };
53
+ /** The client address `request.ip` uses: the socket's peer (no framework is in the picture yet). */
54
+ const peerOf = (req) => {
55
+ const v = req.socket?.remoteAddress;
56
+ return typeof v === 'string' && v ? v : undefined;
57
+ };
58
+ /** The request's context, or `blocked` when a virtual patch blocks, or nothing when capture failed. */
59
+ function capture(req, deceptionDone) {
60
+ try {
61
+ const ctx = (0, capture_1.captureRequest)({ framework: 'http', method: req.method || 'GET', url: req.url || '/', headers: req.headers, ip: peerOf(req) });
62
+ ctx.auto = true;
63
+ if (deceptionDone)
64
+ ctx.deception = true;
65
+ const withBody = req;
66
+ const read = () => {
67
+ const files = withBody.files ?? withBody.file;
68
+ if (withBody.body === undefined && files === undefined)
69
+ return undefined;
70
+ return { body: withBody.body ?? {}, contentType: contentTypeOf(req), files };
71
+ };
72
+ const now = read();
73
+ if (now)
74
+ (0, capture_1.captureBody)(ctx, now);
75
+ else {
76
+ (0, capture_1.captureLater)(ctx, read);
77
+ if ((0, capture_1.bodyAbsent)(req.headers, req.httpVersionMajor))
78
+ (0, capture_1.captureNoBody)(ctx);
79
+ }
80
+ (0, capture_1.runVirtualPatches)(ctx);
81
+ return { ctx };
82
+ }
83
+ catch (e) {
84
+ if (e instanceof types_1.RaspBlockedError)
85
+ return { blocked: e };
86
+ return {};
87
+ }
88
+ }
89
+ const CAPTURE_REJECTION = events_1.EventEmitter.captureRejectionSymbol;
90
+ /** What a rejected async listener's error would have met without the capture: the server's rejection handler, or an unhandled rejection. */
91
+ function passOn(server, e, req, res) {
92
+ const s = server;
93
+ const kCapture = Object.getOwnPropertySymbols(s).find((k) => k.description === 'kCapture');
94
+ const handler = s[CAPTURE_REJECTION];
95
+ if (kCapture && s[kCapture] === true && typeof handler === 'function') {
96
+ handler.call(server, e, 'request', req, res);
97
+ return;
98
+ }
99
+ void Promise.reject(e);
100
+ }
101
+ /** Calls the `request` listeners as `emit` would, and maps a block from any of them, sync or async, to the 403. */
102
+ function serve(server, req, res) {
103
+ const listeners = server.rawListeners('request');
104
+ if (listeners.length === 0)
105
+ return false;
106
+ for (const listener of listeners) {
107
+ let out;
108
+ try {
109
+ out = listener.call(server, req, res);
110
+ }
111
+ catch (e) {
112
+ if (e instanceof types_1.RaspBlockedError) {
113
+ (0, middleware_1.sendBlocked)(res, e);
114
+ return true;
115
+ }
116
+ throw e;
117
+ }
118
+ if (out && typeof out.then === 'function') {
119
+ out.then(undefined, (e) => {
120
+ if (e instanceof types_1.RaspBlockedError)
121
+ (0, middleware_1.sendBlocked)(res, e);
122
+ else
123
+ passOn(server, e, req, res);
124
+ });
125
+ }
126
+ }
127
+ return true;
128
+ }
129
+ function wrap(original) {
130
+ return function shield360Emit(event, ...args) {
131
+ if (event !== 'request' || !(0, engine_1.isActive)())
132
+ return original.call(this, event, ...args);
133
+ const req = args[0];
134
+ const res = args[1];
135
+ // A framework app's adapter runs deception with its own client address and not-found.
136
+ const plain = !(0, middleware_1.frameworkServes)(this);
137
+ if (plain) {
138
+ const d = (0, deception_1.checkDeception)({ framework: 'http', method: req.method || 'GET', url: req.url || '/', ip: peerOf(req) });
139
+ if (d.notFound) {
140
+ (0, middleware_1.sendNotFound)(res);
141
+ return true;
142
+ }
143
+ if (d.blocked) {
144
+ (0, middleware_1.sendBlocked)(res, d.blocked);
145
+ return true;
146
+ }
147
+ }
148
+ const r = capture(req, plain);
149
+ if (r.blocked) {
150
+ (0, middleware_1.sendBlocked)(res, r.blocked);
151
+ return true;
152
+ }
153
+ if (!r.ctx)
154
+ return original.call(this, event, ...args);
155
+ return context_1.storage.run(r.ctx, () => serve(this, req, res));
156
+ };
157
+ }
158
+ /** Installs the capture on `http.Server` and `https.Server`. Idempotent; returns whether it is in place. */
159
+ function installAutoHttpCapture() {
160
+ try {
161
+ for (const S of [http.Server, https.Server]) {
162
+ const proto = S.prototype;
163
+ if (proto[PATCHED])
164
+ continue;
165
+ const own = Object.prototype.hasOwnProperty.call(proto, 'emit');
166
+ const original = proto.emit;
167
+ if (typeof original !== 'function')
168
+ continue;
169
+ proto.emit = wrap(original);
170
+ Object.defineProperty(proto, PATCHED, { value: true, configurable: true });
171
+ patched.push({ proto, own, original });
172
+ }
173
+ return true;
174
+ }
175
+ catch {
176
+ return false;
177
+ }
178
+ }
179
+ /** Removes the capture (tests). */
180
+ function uninstallAutoHttpCapture() {
181
+ for (const p of patched) {
182
+ if (p.own)
183
+ p.proto.emit = p.original;
184
+ else
185
+ delete p.proto.emit;
186
+ delete p.proto[PATCHED];
187
+ }
188
+ patched = [];
189
+ }
190
+ /** Whether the capture is installed. */
191
+ function autoHttpCaptureInstalled() {
192
+ return Boolean(http.Server.prototype[PATCHED]);
193
+ }
194
+ //# sourceMappingURL=auto-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-http.js","sourceRoot":"","sources":["../../src/rasp/auto-http.ts"],"names":[],"mappings":";;AA2JA,wDAgBC;AAGD,4DAOC;AAGD,4DAEC;AA1LD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,mCAAsC;AACtC,6BAA8B;AAC9B,+BAAgC;AAEhC,uCAAoH;AACpH,uCAAsD;AACtD,qCAAoC;AACpC,2CAA6C;AAC7C,6CAA0E;AAC1E,mCAA2C;AAE3C,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAKtD,IAAI,OAAO,GAAc,EAAE,CAAC;AAE5B,MAAM,aAAa,GAAG,CAAC,GAAoB,EAAsB,EAAE;IACjE,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,cAAc,CAAC,CAAC;IACxC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/C,CAAC,CAAC;AAEF,oGAAoG;AACpG,MAAM,MAAM,GAAG,CAAC,GAAoB,EAAsB,EAAE;IAC1D,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC;IACpC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC,CAAC;AAEF,uGAAuG;AACvG,SAAS,OAAO,CAAC,GAAoB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AC7C,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3E,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,mCAAmC;AACnC,SAAgB,wBAAwB;IACtC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,GAAG;YAAE,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC;;YAChC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QACzB,OAAO,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED,wCAAwC;AACxC,SAAgB,wBAAwB;IACtC,OAAO,OAAO,CAAE,IAAI,CAAC,MAAM,CAAC,SAAgD,CAAC,OAAO,CAAC,CAAC,CAAC;AACzF,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { Finding } from './types';
2
+ /**
3
+ * End of life of each Node.js release line (the last day it gets security
4
+ * fixes). Odd lines end six months after their release; only the long-term
5
+ * lines an app is likely to run are listed.
6
+ */
7
+ export declare const NODE_END_OF_LIFE: Readonly<Record<number, string>>;
8
+ export type BaselineInput = {
9
+ env: NodeJS.ProcessEnv;
10
+ /** The SDK's own environment name (init option). */
11
+ environment?: string;
12
+ /** A signed config was expected (URL and API key set, remote on). */
13
+ remoteWanted: boolean;
14
+ /** A config public key is pinned. */
15
+ pinned: boolean;
16
+ execArgv: readonly string[];
17
+ nodeVersion: string;
18
+ /** POSIX user id, when the platform has one. */
19
+ uid?: number;
20
+ /** Whether the inspector is listening. */
21
+ inspectorOpen: boolean;
22
+ now: Date;
23
+ };
24
+ export declare function isProduction(env: NodeJS.ProcessEnv, environment?: string): boolean;
25
+ /** The baseline rules that fire for this process, in a fixed order. Pure. */
26
+ export declare function baselineFindings(i: BaselineInput): Finding[];
27
+ /** Runs the baseline once per process and reports what it finds. Never throws. */
28
+ export declare function runBaseline(opts: {
29
+ environment?: string;
30
+ remoteWanted: boolean;
31
+ pinned: boolean;
32
+ env?: NodeJS.ProcessEnv;
33
+ }): void;
34
+ /** Tests only: lets the baseline run again. */
35
+ export declare function resetBaseline(): void;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NODE_END_OF_LIFE = void 0;
4
+ exports.isProduction = isProduction;
5
+ exports.baselineFindings = baselineFindings;
6
+ exports.runBaseline = runBaseline;
7
+ exports.resetBaseline = resetBaseline;
8
+ /**
9
+ * Security baseline (README "Security baseline"): a one-time look, when RASP
10
+ * starts, at how the running process is set up, reported as `baseline`
11
+ * events (monitor only, never blocks). Each rule reads a flag, a version or
12
+ * an id, never a secret value, and reports only that a setting is risky.
13
+ * Adapted from the idea of OpenRASP's start-up security policy checks.
14
+ */
15
+ const inspector = require("inspector");
16
+ const engine_1 = require("./engine");
17
+ const PRODUCTION = /^prod(uction)?$/i;
18
+ const INSPECT_FLAG = /(^|\s)--inspect(-brk|-port|-wait)?(=|\s|$)/;
19
+ /**
20
+ * End of life of each Node.js release line (the last day it gets security
21
+ * fixes). Odd lines end six months after their release; only the long-term
22
+ * lines an app is likely to run are listed.
23
+ */
24
+ exports.NODE_END_OF_LIFE = Object.freeze({
25
+ 14: '2023-04-30',
26
+ 16: '2023-09-11',
27
+ 18: '2025-04-30',
28
+ 20: '2026-04-30',
29
+ 22: '2027-04-30',
30
+ 24: '2028-04-30',
31
+ });
32
+ function isProduction(env, environment) {
33
+ return [env.NODE_ENV, env.ENVIRONMENT, environment].some((v) => PRODUCTION.test((v || '').trim()));
34
+ }
35
+ /** The baseline rules that fire for this process, in a fixed order. Pure. */
36
+ function baselineFindings(i) {
37
+ const out = [];
38
+ const production = isProduction(i.env, i.environment);
39
+ const hit = (rule) => out.push({ attack: 'baseline', rule });
40
+ // TLS certificate checks switched off for every outbound connection.
41
+ if ((i.env.NODE_TLS_REJECT_UNAUTHORIZED || '').trim() === '0')
42
+ hit('baseline.tls_verify_off');
43
+ // A debugger port open in production lets anyone who reaches it run code.
44
+ if (production && (i.inspectorOpen || i.execArgv.some((a) => INSPECT_FLAG.test(a)) || INSPECT_FLAG.test(i.env.NODE_OPTIONS || ''))) {
45
+ hit('baseline.inspector_in_production');
46
+ }
47
+ // The SDK says production while NODE_ENV says development: frameworks then run in development mode.
48
+ if (PRODUCTION.test((i.environment || i.env.ENVIRONMENT || '').trim()) && (i.env.NODE_ENV || '').trim().toLowerCase() === 'development') {
49
+ hit('baseline.development_mode_in_production');
50
+ }
51
+ if (i.uid === 0)
52
+ hit('baseline.running_as_root');
53
+ // In production the signed config must be verified against a pinned key.
54
+ if (production && i.remoteWanted && !i.pinned)
55
+ hit('baseline.config_key_unpinned');
56
+ const major = Number(i.nodeVersion.replace(/^v/, '').split('.')[0]);
57
+ const eol = exports.NODE_END_OF_LIFE[major] ?? (major % 2 === 1 || major < 14 ? '1970-01-01' : undefined);
58
+ if (eol && i.now.toISOString().slice(0, 10) > eol)
59
+ hit('baseline.runtime_end_of_life');
60
+ return out;
61
+ }
62
+ let ran = false;
63
+ /** Runs the baseline once per process and reports what it finds. Never throws. */
64
+ function runBaseline(opts) {
65
+ if (ran)
66
+ return;
67
+ ran = true;
68
+ try {
69
+ const findings = baselineFindings({
70
+ env: opts.env ?? process.env,
71
+ environment: opts.environment,
72
+ remoteWanted: opts.remoteWanted,
73
+ pinned: opts.pinned,
74
+ execArgv: process.execArgv,
75
+ nodeVersion: process.versions.node,
76
+ uid: typeof process.getuid === 'function' ? process.getuid() : undefined,
77
+ inspectorOpen: Boolean(inspector.url()),
78
+ now: new Date(),
79
+ });
80
+ for (const f of findings)
81
+ (0, engine_1.check)('startup', () => f);
82
+ }
83
+ catch {
84
+ // fail open
85
+ }
86
+ }
87
+ /** Tests only: lets the baseline run again. */
88
+ function resetBaseline() {
89
+ ran = false;
90
+ }
91
+ //# sourceMappingURL=baseline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseline.js","sourceRoot":"","sources":["../../src/rasp/baseline.ts"],"names":[],"mappings":";;;AA6CA,oCAEC;AAGD,4CAsBC;AAKD,kCAmBC;AAGD,sCAEC;AArGD;;;;;;GAMG;AACH,uCAAwC;AACxC,qCAAiC;AAGjC,MAAM,UAAU,GAAG,kBAAkB,CAAC;AACtC,MAAM,YAAY,GAAG,4CAA4C,CAAC;AAElE;;;;GAIG;AACU,QAAA,gBAAgB,GAAqC,MAAM,CAAC,MAAM,CAAC;IAC9E,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,YAAY;CACjB,CAAC,CAAC;AAmBH,SAAgB,YAAY,CAAC,GAAsB,EAAE,WAAoB;IACvE,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACrG,CAAC;AAED,6EAA6E;AAC7E,SAAgB,gBAAgB,CAAC,CAAgB;IAC/C,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IACtD,MAAM,GAAG,GAAG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,CAAC;QACP,YAAY;IACd,CAAC;AACH,CAAC;AAED,+CAA+C;AAC/C,SAAgB,aAAa;IAC3B,GAAG,GAAG,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Request capture shared by every framework middleware: turns a request into
3
+ * the context's inputs (README "Sources of untrusted input") and runs the
4
+ * virtual patches. Inputs stay in memory, in the request's context only.
5
+ */
6
+ import { type RaspContext } from './context';
7
+ /** Headers the contract treats as input (OpenRASP's headerInjection). */
8
+ export declare const INPUT_HEADERS: readonly ["user-agent", "referer", "x-forwarded-for"];
9
+ export declare const VP_SINK = "server.request";
10
+ export type Headers = Record<string, string | string[] | undefined>;
11
+ /** A request, framework-neutral. */
12
+ export type RequestShape = {
13
+ framework: string;
14
+ method: string;
15
+ /** Path and query as received (`/a/b?x=1`). */
16
+ url: string;
17
+ /** Lower-case header names. */
18
+ headers: Headers;
19
+ /** The parsed query, when the framework has one (else parsed from `url`). */
20
+ query?: unknown;
21
+ /** Route or path parameters. */
22
+ params?: unknown;
23
+ /** The route template, when known. */
24
+ route?: string;
25
+ /** The client address as the framework reports it (custom rules' `request.ip`). */
26
+ ip?: string;
27
+ };
28
+ /** What is known about the body. */
29
+ export type BodyShape = {
30
+ /** A parsed body (object), or raw text / bytes. */
31
+ body?: unknown;
32
+ contentType?: string;
33
+ /** Uploaded files a multipart parser set aside (multer's `req.file` / `req.files`). */
34
+ files?: unknown;
35
+ };
36
+ /** The names of uploaded files: from raw multipart part headers, or a parser's file objects. */
37
+ export declare function uploadNames(b: BodyShape, raw: string): {
38
+ field: string;
39
+ name: string;
40
+ }[];
41
+ /** Lower-cases header names (Node already does; other sources may not). */
42
+ export declare function lowerHeaders(h: unknown): Headers;
43
+ /** Builds the request's context: query, params, cookies, the input headers. */
44
+ export declare function captureRequest(shape: RequestShape): RaspContext;
45
+ /**
46
+ * Whether the request has no body, by its headers: neither `Transfer-Encoding`
47
+ * nor a non-zero `Content-Length` (HTTP/1.x; body parsers use the same test).
48
+ * Over HTTP/2 a body needs no length, so only `Content-Length: 0` says so.
49
+ */
50
+ export declare function bodyAbsent(h: Headers, httpVersionMajor?: number): boolean;
51
+ /** Records that the request has no body: the body is known and empty, so the body phase runs. */
52
+ export declare function captureNoBody(ctx: RaspContext): void;
53
+ /**
54
+ * Adds the body to the context: string leaves of a parsed body (`body.a.b`),
55
+ * form fields, or the raw text when it is text, unparsed and at most 8 KiB.
56
+ * Also gives the virtual patches the body text.
57
+ */
58
+ export declare function captureBody(ctx: RaspContext, b: BodyShape): void;
59
+ /**
60
+ * Runs the virtual patches the request can be judged by so far: rules that
61
+ * do not read the body at once, rules that do once the body is known. Each
62
+ * rule set runs once. Throws the block error when a blocking rule matches;
63
+ * any other failure lets the request through.
64
+ */
65
+ export declare function runVirtualPatches(ctx: RaspContext): void;
66
+ /**
67
+ * Custom request rules (README "Custom rules"): each match is reported in
68
+ * order; the first that blocks throws the block error. Any other failure
69
+ * lets the request through.
70
+ */
71
+ export declare function runRequestRules(ctx: RaspContext, phase: 'head' | 'body'): void;
72
+ /**
73
+ * Sets up late body capture: when a sink first reads the inputs, a body a
74
+ * parser set after the middleware ran is captured and judged.
75
+ */
76
+ export declare function captureLater(ctx: RaspContext, read: () => BodyShape | undefined): void;