@contrast/agent-bundle 5.39.1 → 5.41.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 (279) hide show
  1. package/node_modules/@contrast/agent/lib/start-agent.js +50 -40
  2. package/node_modules/@contrast/agent/package.json +11 -11
  3. package/node_modules/@contrast/agent-swc-plugin/index.js +9 -3
  4. package/node_modules/@contrast/agent-swc-plugin/methods.js +15 -1
  5. package/node_modules/@contrast/agent-swc-plugin/package.json +5 -8
  6. package/node_modules/@contrast/agent-swc-plugin/rewriter.wasm +0 -0
  7. package/node_modules/@contrast/agentify/lib/index.js +2 -2
  8. package/node_modules/@contrast/agentify/package.json +15 -14
  9. package/node_modules/@contrast/architecture-components/package.json +5 -5
  10. package/node_modules/@contrast/assess/lib/dataflow/propagation/install/string/replace.js +6 -3
  11. package/node_modules/@contrast/assess/lib/dataflow/propagation/install/util-format.js +44 -21
  12. package/node_modules/@contrast/assess/lib/dataflow/sources/index.js +1 -1
  13. package/node_modules/@contrast/assess/lib/dataflow/sources/install/{body-parser1.js → body-parser.js} +2 -2
  14. package/node_modules/@contrast/assess/lib/dataflow/sources/install/koa/koa-bodyparsers.js +3 -1
  15. package/node_modules/@contrast/assess/lib/dataflow/sources/install/qs6.js +5 -5
  16. package/node_modules/@contrast/assess/lib/dataflow/sources/install/querystring.js +2 -1
  17. package/node_modules/@contrast/assess/lib/index.d.ts +0 -1
  18. package/node_modules/@contrast/assess/lib/make-source-context.js +7 -37
  19. package/node_modules/@contrast/assess/lib/sampler/common.js +7 -11
  20. package/node_modules/@contrast/assess/package.json +12 -11
  21. package/node_modules/@contrast/common/lib/constants.d.ts +6 -0
  22. package/node_modules/@contrast/common/lib/constants.js +8 -1
  23. package/node_modules/@contrast/common/lib/types.d.ts +7 -1
  24. package/node_modules/@contrast/common/package.json +1 -1
  25. package/node_modules/@contrast/config/lib/common.js +1 -1
  26. package/node_modules/@contrast/config/lib/config.js +49 -27
  27. package/node_modules/@contrast/config/lib/index.d.ts +3 -2
  28. package/node_modules/@contrast/config/lib/options.js +4 -4
  29. package/node_modules/@contrast/config/package.json +4 -3
  30. package/node_modules/@contrast/core/lib/sensitive-data-masking/protect-listener.js +15 -15
  31. package/node_modules/@contrast/core/package.json +6 -6
  32. package/node_modules/@contrast/deadzones/package.json +5 -5
  33. package/node_modules/@contrast/dep-hooks/package.json +3 -3
  34. package/node_modules/@contrast/esm-hooks/package.json +6 -6
  35. package/node_modules/@contrast/instrumentation/lib/index.js +0 -1
  36. package/node_modules/@contrast/instrumentation/package.json +5 -5
  37. package/node_modules/@contrast/library-analysis/lib/install/library-reporting/dep.json +300 -152
  38. package/node_modules/@contrast/library-analysis/lib/install/library-reporting/index.js +9 -2
  39. package/node_modules/@contrast/library-analysis/lib/install/library-reporting/utils.js +54 -43
  40. package/node_modules/@contrast/library-analysis/package.json +4 -4
  41. package/node_modules/@contrast/logger/lib/serializers.js +2 -2
  42. package/node_modules/@contrast/logger/package.json +3 -3
  43. package/node_modules/@contrast/metrics/package.json +6 -6
  44. package/node_modules/@contrast/patcher/package.json +2 -2
  45. package/node_modules/@contrast/protect/lib/get-source-context.js +3 -1
  46. package/node_modules/@contrast/protect/lib/index.js +6 -1
  47. package/node_modules/@contrast/protect/lib/input-analysis/handlers.js +7 -9
  48. package/node_modules/@contrast/protect/lib/input-analysis/index.js +1 -1
  49. package/node_modules/@contrast/protect/lib/input-analysis/install/{body-parser1.js → body-parser.js} +1 -1
  50. package/node_modules/@contrast/protect/lib/input-analysis/install/http.js +18 -19
  51. package/node_modules/@contrast/protect/lib/input-analysis/install/qs6.js +18 -17
  52. package/node_modules/@contrast/protect/lib/input-analysis/install/universal-cookie4.js +2 -3
  53. package/node_modules/@contrast/protect/lib/make-source-context.js +22 -66
  54. package/node_modules/@contrast/protect/lib/semantic-analysis/handlers.js +73 -72
  55. package/node_modules/@contrast/protect/package.json +11 -11
  56. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/index.js +7 -7
  57. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/translations.d.ts +3 -3
  58. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/translations.js +24 -21
  59. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/routes-observed.js +2 -1
  60. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/index.js +1 -1
  61. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/translations.d.ts +1 -2
  62. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/translations.js +8 -2
  63. package/node_modules/@contrast/reporter/lib/reporters/security-logger/index.d.ts +2 -2
  64. package/node_modules/@contrast/reporter/lib/reporters/security-logger/index.js +22 -20
  65. package/node_modules/@contrast/reporter/package.json +7 -7
  66. package/node_modules/@contrast/rewriter/lib/index.js +2 -2
  67. package/node_modules/@contrast/rewriter/package.json +6 -6
  68. package/node_modules/@contrast/route-coverage/lib/index.d.ts +2 -0
  69. package/node_modules/@contrast/route-coverage/lib/index.js +15 -17
  70. package/node_modules/@contrast/route-coverage/lib/install/express/express5.js +489 -202
  71. package/node_modules/@contrast/route-coverage/package.json +9 -9
  72. package/node_modules/@contrast/scopes/package.json +5 -5
  73. package/node_modules/@contrast/sec-obs/lib/traces/http.js +2 -2
  74. package/node_modules/@contrast/sec-obs/lib/traces/http.test.js +17 -0
  75. package/node_modules/@contrast/sec-obs/lib/traces/outbound-service-call.js +2 -2
  76. package/node_modules/@contrast/sec-obs/lib/traces/outbound-service-call.test.js +17 -0
  77. package/node_modules/@contrast/sec-obs/package.json +9 -9
  78. package/node_modules/@contrast/sources/lib/index.js +109 -0
  79. package/node_modules/@contrast/sources/lib/index.test.js +120 -0
  80. package/node_modules/@contrast/{route-coverage/lib/normalized-url-mapper.js → sources/lib/normalized-uri-mapper.js} +10 -3
  81. package/node_modules/@contrast/sources/lib/normalized-uri-mapper.test.js +59 -0
  82. package/node_modules/@contrast/{sec-obs/node_modules/@contrast/core/lib/sensitive-data-masking/constants.js → sources/lib/req-data.js} +0 -6
  83. package/node_modules/@contrast/sources/lib/source-info.js +183 -0
  84. package/node_modules/@contrast/sources/lib/source-info.test.js +68 -0
  85. package/node_modules/@contrast/sources/package.json +16 -0
  86. package/node_modules/@contrast/telemetry/package.json +6 -6
  87. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.d.ts +2831 -77
  88. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.js +2831 -77
  89. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.js.map +1 -1
  90. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.d.ts +415 -98
  91. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.js +415 -98
  92. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.js.map +1 -1
  93. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.d.ts +106 -0
  94. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js +106 -0
  95. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js.map +1 -1
  96. package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.d.ts +1 -1
  97. package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.js +1 -1
  98. package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.js.map +1 -1
  99. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.d.ts +2831 -77
  100. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.js +2831 -77
  101. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.js.map +1 -1
  102. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.d.ts +415 -98
  103. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.js +415 -98
  104. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.js.map +1 -1
  105. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.d.ts +106 -0
  106. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.js +106 -0
  107. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.js.map +1 -1
  108. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.d.ts +1 -1
  109. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.js +1 -1
  110. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.js.map +1 -1
  111. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.d.ts +2831 -77
  112. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.js +2858 -103
  113. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.js.map +1 -1
  114. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.d.ts +415 -98
  115. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.js +420 -102
  116. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.js.map +1 -1
  117. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.d.ts +106 -0
  118. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.js +106 -0
  119. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.js.map +1 -1
  120. package/node_modules/@opentelemetry/semantic-conventions/build/src/version.d.ts +1 -1
  121. package/node_modules/@opentelemetry/semantic-conventions/build/src/version.js +1 -1
  122. package/node_modules/@opentelemetry/semantic-conventions/build/src/version.js.map +1 -1
  123. package/node_modules/@opentelemetry/semantic-conventions/package.json +3 -3
  124. package/node_modules/@types/node/README.md +2 -2
  125. package/node_modules/@types/node/buffer.d.ts +5 -0
  126. package/node_modules/@types/node/dns/promises.d.ts +11 -10
  127. package/node_modules/@types/node/dns.d.ts +18 -19
  128. package/node_modules/@types/node/fs.d.ts +13 -1
  129. package/node_modules/@types/node/http.d.ts +4 -19
  130. package/node_modules/@types/node/inspector.d.ts +53 -0
  131. package/node_modules/@types/node/package.json +2 -82
  132. package/node_modules/@types/node/stream/web.d.ts +4 -0
  133. package/node_modules/axios/CHANGELOG.md +17 -0
  134. package/node_modules/axios/README.md +1 -4
  135. package/node_modules/axios/dist/axios.js +39 -5
  136. package/node_modules/axios/dist/axios.js.map +1 -1
  137. package/node_modules/axios/dist/axios.min.js +2 -2
  138. package/node_modules/axios/dist/axios.min.js.map +1 -1
  139. package/node_modules/axios/dist/browser/axios.cjs +46 -9
  140. package/node_modules/axios/dist/browser/axios.cjs.map +1 -1
  141. package/node_modules/axios/dist/esm/axios.js +46 -9
  142. package/node_modules/axios/dist/esm/axios.js.map +1 -1
  143. package/node_modules/axios/dist/esm/axios.min.js +2 -2
  144. package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
  145. package/node_modules/axios/dist/node/axios.cjs +46 -9
  146. package/node_modules/axios/dist/node/axios.cjs.map +1 -1
  147. package/node_modules/axios/index.d.cts +13 -2
  148. package/node_modules/axios/lib/core/Axios.js +2 -2
  149. package/node_modules/axios/lib/core/mergeConfig.js +1 -1
  150. package/node_modules/axios/lib/env/data.js +1 -1
  151. package/node_modules/axios/lib/helpers/throttle.js +1 -1
  152. package/node_modules/axios/lib/helpers/toURLEncodedForm.js +4 -3
  153. package/node_modules/axios/lib/utils.js +36 -0
  154. package/node_modules/axios/package.json +5 -5
  155. package/node_modules/deepmerge/.editorconfig +7 -0
  156. package/node_modules/deepmerge/.eslintcache +1 -0
  157. package/node_modules/deepmerge/changelog.md +167 -0
  158. package/node_modules/deepmerge/dist/cjs.js +133 -0
  159. package/node_modules/deepmerge/dist/umd.js +139 -0
  160. package/node_modules/deepmerge/index.d.ts +20 -0
  161. package/node_modules/deepmerge/index.js +106 -0
  162. package/node_modules/{path-to-regexp/LICENSE → deepmerge/license.txt} +1 -1
  163. package/node_modules/deepmerge/package.json +42 -0
  164. package/node_modules/deepmerge/readme.md +264 -0
  165. package/node_modules/deepmerge/rollup.config.js +22 -0
  166. package/node_modules/follow-redirects/package.json +1 -1
  167. package/node_modules/form-data/CHANGELOG.md +601 -0
  168. package/node_modules/form-data/{Readme.md → README.md} +4 -4
  169. package/node_modules/form-data/lib/form_data.js +2 -6
  170. package/node_modules/form-data/package.json +22 -6
  171. package/node_modules/nan/.github/workflows/ci.yml +8 -10
  172. package/node_modules/nan/.pre-commit-config.yaml +8 -0
  173. package/node_modules/nan/CHANGELOG.md +5 -1
  174. package/node_modules/nan/README.md +4 -4
  175. package/node_modules/nan/nan.h +16 -12
  176. package/node_modules/nan/nan_callbacks.h +13 -0
  177. package/node_modules/nan/nan_callbacks_12_inl.h +16 -2
  178. package/node_modules/nan/nan_callbacks_pre_12_inl.h +6 -2
  179. package/node_modules/nan/nan_maybe_43_inl.h +1 -1
  180. package/node_modules/nan/nan_maybe_pre_43_inl.h +1 -1
  181. package/node_modules/nan/nan_scriptorigin.h +11 -9
  182. package/node_modules/nan/nan_typedarray_contents.h +1 -1
  183. package/node_modules/nan/package.json +2 -2
  184. package/package.json +5 -3
  185. package/node_modules/@contrast/agentify/lib/sources.js +0 -94
  186. package/node_modules/@contrast/route-coverage/lib/install/http.js +0 -44
  187. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/LICENSE +0 -12
  188. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/constants.d.ts +0 -385
  189. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/constants.js +0 -270
  190. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/index.d.ts +0 -40
  191. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/index.js +0 -228
  192. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/primordials.d.ts +0 -65
  193. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/primordials.js +0 -66
  194. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/types.d.ts +0 -383
  195. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/types.js +0 -30
  196. package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/package.json +0 -23
  197. package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/LICENSE +0 -12
  198. package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/README.md +0 -44
  199. package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/common.js +0 -131
  200. package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/config.js +0 -290
  201. package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/index.d.ts +0 -328
  202. package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/index.js +0 -29
  203. package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/options.js +0 -836
  204. package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/validators.js +0 -23
  205. package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/package.json +0 -27
  206. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/LICENSE +0 -12
  207. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/README.md +0 -98
  208. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/agent-info.js +0 -36
  209. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/app-info.js +0 -233
  210. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/build-id.js +0 -51
  211. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/capture-stacktrace.js +0 -256
  212. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/contrast-methods.js +0 -155
  213. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/index.d.ts +0 -52
  214. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/ioc/core.js +0 -95
  215. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/is-agent-path.js +0 -37
  216. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/messages.js +0 -28
  217. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/sensitive-data-masking/index.js +0 -63
  218. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/sensitive-data-masking/protect-listener.js +0 -111
  219. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/sensitive-data-masking/server-settings-listener.js +0 -44
  220. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/system-info/cloud-provider-metadata.js +0 -146
  221. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/system-info/index.js +0 -225
  222. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/system-info/linux-os-info.js +0 -137
  223. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/system-info/utils.js +0 -35
  224. package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/package.json +0 -33
  225. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/LICENSE +0 -12
  226. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/README.md +0 -94
  227. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/export-handler-registry.d.ts +0 -121
  228. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/export-handler-registry.js +0 -206
  229. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/export-hook-descriptor.d.ts +0 -72
  230. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/export-hook-descriptor.js +0 -88
  231. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/handler-invoker.d.ts +0 -46
  232. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/handler-invoker.js +0 -106
  233. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/helpers.d.ts +0 -28
  234. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/helpers.js +0 -66
  235. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/index.d.ts +0 -115
  236. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/index.js +0 -208
  237. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/package-finder.d.ts +0 -43
  238. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/package-finder.js +0 -79
  239. package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/package.json +0 -29
  240. package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/LICENSE +0 -12
  241. package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/README.md +0 -270
  242. package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/index.d.ts +0 -16
  243. package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/index.js +0 -132
  244. package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/serializers.d.ts +0 -33
  245. package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/serializers.js +0 -75
  246. package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/utils.d.ts +0 -15
  247. package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/utils.js +0 -34
  248. package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/package.json +0 -28
  249. package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/LICENSE +0 -12
  250. package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/README.md +0 -51
  251. package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/lib/index.d.ts +0 -101
  252. package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/lib/index.js +0 -544
  253. package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/package.json +0 -25
  254. package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/LICENSE +0 -12
  255. package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/README.md +0 -6
  256. package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/lib/cache.js +0 -318
  257. package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/lib/index.js +0 -216
  258. package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/lib/rewrite-is-deadzoned.js +0 -143
  259. package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/package.json +0 -30
  260. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/LICENSE +0 -12
  261. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/constants.js +0 -26
  262. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/index.d.ts +0 -46
  263. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/index.js +0 -70
  264. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/bluebird.js +0 -128
  265. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/index.js +0 -34
  266. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mongodb-core.js +0 -83
  267. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mongodb3.js +0 -89
  268. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mongodb4.js +0 -80
  269. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mongodb6.js +0 -46
  270. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mysql.js +0 -151
  271. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/redis.js +0 -79
  272. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/utils.js +0 -35
  273. package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/package.json +0 -28
  274. package/node_modules/form-data/README.md.bak +0 -355
  275. package/node_modules/path-to-regexp/Readme.md +0 -216
  276. package/node_modules/path-to-regexp/dist/index.d.ts +0 -136
  277. package/node_modules/path-to-regexp/dist/index.js +0 -403
  278. package/node_modules/path-to-regexp/dist/index.js.map +0 -1
  279. package/node_modules/path-to-regexp/package.json +0 -62
@@ -73,7 +73,6 @@ module.exports = function init(core) {
73
73
  } = core;
74
74
 
75
75
  const libPathHashMap = new Map();
76
-
77
76
  /**
78
77
  * @returns {Promise<string | undefined>}
79
78
  */
@@ -100,6 +99,14 @@ module.exports = function init(core) {
100
99
 
101
100
  const libraryReporting = core.libraryAnalysis.libraryReporting = {
102
101
  async install() {
102
+ const topLevelPkgInfo = core.appInfo.pkg;
103
+ if (!topLevelPkgInfo) {
104
+ logger.warn('Unable to get top-level package.json; aborting library analysis. Ensure the `agent.node.app_root` configuration variable is set to the directory containing your `node_modules` folder.');
105
+ return;
106
+ }
107
+
108
+ const { dependencies: topLevelDependencies } = topLevelPkgInfo;
109
+
103
110
  const nodeModulesPath = await getNodeModulesPath();
104
111
  if (!nodeModulesPath) {
105
112
  logger.warn('Unable to determine the location of the `node_modules` directory; aborting library analysis. Ensure the `agent.node.app_root` configuration variable is set to the directory containing your `node_modules` folder.');
@@ -108,7 +115,7 @@ module.exports = function init(core) {
108
115
 
109
116
  try {
110
117
  const flatAgentDeps = flattenDeps(agentDeps);
111
- const npmData = listInstalled(nodeModulesPath, flatAgentDeps, logger);
118
+ const npmData = listInstalled(topLevelDependencies, nodeModulesPath, flatAgentDeps, logger);
112
119
  processDependencies(npmData, libPathHashMap, logger);
113
120
  } catch (err) {
114
121
  logger.warn({ err }, 'Unable to perform library analysis.');
@@ -19,6 +19,27 @@ const path = require('path');
19
19
 
20
20
  const { primordials: { JSONParse } } = require('@contrast/common');
21
21
 
22
+ function parsePackage(filePath, logger) {
23
+ const pkgPath = path.join(filePath, 'package.json');
24
+ if (!fs.existsSync(pkgPath)) return;
25
+
26
+ const pkg = fs.readFileSync(pkgPath, 'utf-8');
27
+ if (!pkg) {
28
+ logger.warn('Error reading package.json for %s', pkgPath);
29
+ return;
30
+ }
31
+
32
+ if (typeof pkg !== 'string') return;
33
+
34
+ let pkgInfo;
35
+ try {
36
+ pkgInfo = JSONParse(pkg);
37
+ } catch (err) {
38
+ logger.warn({ err }, 'Error parsing package.json for %s', pkgPath);
39
+ }
40
+ return pkgInfo;
41
+ }
42
+
22
43
  // Just used, for now, to flatten the agent dependencies stored in dep.json
23
44
  function flattenDeps(deps, flatDeps = {}) {
24
45
  Object.entries(deps.dependencies).forEach(([key, val]) => {
@@ -31,59 +52,48 @@ function flattenDeps(deps, flatDeps = {}) {
31
52
  return flatDeps;
32
53
  }
33
54
 
34
- function listInstalled(nodeModulesPath, agentDeps, logger, installed = new Map()) {
55
+ function listInstalled(topLevelDeps, nodeModulesPath, agentDeps, logger, installed = new Map()) {
35
56
 
36
57
  if (!fs.existsSync(nodeModulesPath)) return;
37
58
 
38
59
  function traversePackage(filePath, checkingAgentDeps = false) {
39
- const pkgPath = path.join(filePath, 'package.json');
40
- if (!fs.existsSync(pkgPath)) return;
41
-
42
- const pkg = fs.readFileSync(pkgPath, 'utf-8');
43
- try {
44
- if (typeof pkg === 'string') {
45
- const pkgInfo = JSONParse(pkg);
46
- pkgInfo.path = filePath;
47
-
48
- const { name } = pkgInfo;
49
- const pkgId = `${name}:${pkgInfo?.version}`;
50
- if (installed.has(pkgId)) return;
51
-
52
- // The library we are checking is a known agent dependency
53
- // store its path so if it turns out to also be an app
54
- // dependency we can go back and traverse it later
55
- if (!checkingAgentDeps && agentDeps[name]) {
56
- agentDeps[name] = { filePath };
57
- return;
58
- }
59
-
60
- installed.set(pkgId, pkgInfo);
61
-
62
- // Looks in a library's package.json for dependencies shared by the agent
63
- // if one is found, go back and traverse it
64
- ['dependencies', 'peerDependencies', 'optionalDependencies'].forEach((deps) => {
65
- if (pkgInfo?.[deps]) {
66
- Object.entries(pkgInfo[deps]).forEach(([key]) => {
67
- if (agentDeps[key]) {
68
- const { filePath } = agentDeps[key];
69
- agentDeps[key] = false;
70
- if (filePath) traversePackage(filePath, true);
71
- }
72
- });
60
+ const pkgInfo = parsePackage(filePath, logger);
61
+ if (!pkgInfo) return;
62
+
63
+ pkgInfo.path = filePath;
64
+
65
+ const { name } = pkgInfo;
66
+ const pkgId = `${name}:${pkgInfo?.version}`;
67
+ if (installed.has(pkgId)) return;
68
+
69
+ // The library we are checking is a known agent dependency
70
+ // store its path so if it turns out to also be an app
71
+ // dependency we can go back and traverse it later
72
+ if (!checkingAgentDeps && agentDeps[name] && !topLevelDeps[name]) {
73
+ agentDeps[name] = { filePath };
74
+ return;
75
+ }
76
+
77
+ installed.set(pkgId, pkgInfo);
78
+
79
+ // Looks in a library's package.json for dependencies shared by the agent
80
+ // if one is found, go back and traverse it
81
+ ['dependencies', 'peerDependencies', 'optionalDependencies'].forEach((deps) => {
82
+ if (pkgInfo?.[deps]) {
83
+ Object.entries(pkgInfo[deps]).forEach(([key]) => {
84
+ if (agentDeps[key]) {
85
+ const { filePath } = agentDeps[key];
86
+ agentDeps[key] = false;
87
+ if (filePath) traversePackage(filePath, true);
73
88
  }
74
89
  });
75
- } else {
76
- logger.warn('Error reading package.json for %s', pkgPath);
77
90
  }
78
- } catch (err) {
79
- logger.warn(err);
80
- logger.warn('Error parsing package.json for %s', pkgPath);
81
- }
91
+ });
82
92
 
83
93
  // If a library contains its own node_modules directory
84
94
  const filePathNodeModulesPath = path.join(filePath, 'node_modules');
85
95
  if (fs.existsSync(filePathNodeModulesPath)) {
86
- listInstalled(filePathNodeModulesPath, agentDeps, logger, installed);
96
+ listInstalled(topLevelDeps, filePathNodeModulesPath, agentDeps, logger, installed);
87
97
  }
88
98
  }
89
99
 
@@ -110,6 +120,7 @@ function listInstalled(nodeModulesPath, agentDeps, logger, installed = new Map()
110
120
  }
111
121
 
112
122
  module.exports = {
123
+ parsePackage,
113
124
  flattenDeps,
114
- listInstalled
125
+ listInstalled,
115
126
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/library-analysis",
3
- "version": "1.44.1",
3
+ "version": "1.45.0",
4
4
  "description": "Handles library reporting and library usage analysis",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -21,10 +21,10 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@contrast/code-events": "^3.1.0",
24
- "@contrast/common": "1.34.1",
25
- "@contrast/config": "1.49.1",
24
+ "@contrast/common": "1.35.0",
25
+ "@contrast/config": "1.50.0",
26
26
  "@contrast/find-package-json": "^1.1.0",
27
- "@contrast/logger": "1.27.1",
27
+ "@contrast/logger": "1.28.0",
28
28
  "semver": "^7.6.0"
29
29
  }
30
30
  }
@@ -26,8 +26,8 @@ function config(config) {
26
26
  // log as-is if not a Config instance
27
27
  if (typeof config?.getReport !== 'function')
28
28
  return config;
29
- const safeCopy = { _errors: [...config._errors] };
30
- const { config: { effective_config } } = config.getReport({ redact: true });
29
+ const safeCopy = { _errors: [...config._errors], _filepaths: [...config._filepaths] };
30
+ const { config: { effective_config } } = config.getReport({ redact: true, stringify: false });
31
31
  for (const info of effective_config) {
32
32
  const { canonical_name, value } = info;
33
33
  (0, common_1.set)(safeCopy, canonical_name, value);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/logger",
3
- "version": "1.27.1",
3
+ "version": "1.28.0",
4
4
  "description": "Centralized logging for Contrast agent services",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -21,8 +21,8 @@
21
21
  "test": "bash ../scripts/test.sh"
22
22
  },
23
23
  "dependencies": {
24
- "@contrast/common": "1.34.1",
25
- "@contrast/config": "1.49.1",
24
+ "@contrast/common": "1.35.0",
25
+ "@contrast/config": "1.50.0",
26
26
  "pino": "^8.15.0"
27
27
  }
28
28
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/metrics",
3
- "version": "1.31.1",
3
+ "version": "1.32.0",
4
4
  "description": "Records and logs route latency",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -21,10 +21,10 @@
21
21
  "test": "bash ../scripts/test.sh"
22
22
  },
23
23
  "dependencies": {
24
- "@contrast/common": "1.34.1",
25
- "@contrast/config": "1.49.1",
26
- "@contrast/dep-hooks": "1.23.1",
27
- "@contrast/logger": "1.27.1",
28
- "@contrast/patcher": "1.26.1"
24
+ "@contrast/common": "1.35.0",
25
+ "@contrast/config": "1.50.0",
26
+ "@contrast/dep-hooks": "1.24.0",
27
+ "@contrast/logger": "1.28.0",
28
+ "@contrast/patcher": "1.27.0"
29
29
  }
30
30
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/patcher",
3
- "version": "1.26.1",
3
+ "version": "1.27.0",
4
4
  "description": "Advanced monkey patching--registers hooks to run in and around functions",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -20,6 +20,6 @@
20
20
  "test": "bash ../scripts/test.sh"
21
21
  },
22
22
  "dependencies": {
23
- "@contrast/logger": "1.27.1"
23
+ "@contrast/logger": "1.28.0"
24
24
  }
25
25
  }
@@ -22,7 +22,9 @@ module.exports = function init(core) {
22
22
  if (!core.config.getEffectiveValue('protect.enable')) return null;
23
23
 
24
24
  const sourceContext = sources.getStore()?.protect;
25
- return sourceContext?.allowed ? null : sourceContext;
25
+ if (!sourceContext) return null;
26
+
27
+ return sourceContext.allowed ? null : sourceContext;
26
28
  }
27
29
 
28
30
  core.protect.getSourceContext = getSourceContext;
@@ -20,7 +20,7 @@ const { callChildComponentMethodsSync } = require('@contrast/common');
20
20
  const { ConfigSource } = require('@contrast/config');
21
21
 
22
22
  module.exports = function(core) {
23
- const { config } = core;
23
+ const { config, sources } = core;
24
24
 
25
25
  const protect = core.protect = {
26
26
  agentLib: module.exports.instantiateAgentLib(),
@@ -55,6 +55,11 @@ module.exports = function(core) {
55
55
  callChildComponentMethodsSync(protect, 'install');
56
56
  };
57
57
 
58
+ // append async state to store when request-scope sources are created
59
+ sources.addHook('onSource', (ctx) => {
60
+ ctx.store.protect = protect.makeSourceContext(ctx);
61
+ });
62
+
58
63
  return protect;
59
64
  };
60
65
 
@@ -117,7 +117,6 @@ module.exports = Core.makeComponent({
117
117
 
118
118
  // all handlers will be invoked with two arguments:
119
119
  // 1) sourceContext object containing:
120
- // - reqData, the abstract request object containing only what is needed
121
120
  // - protect, the protect context
122
121
  // - rules, exclusions, virtual patches (TS data). what was in effect for this
123
122
  // url *at the time the request was started*. these will not change.
@@ -162,7 +161,7 @@ module.exports = Core.makeComponent({
162
161
  * 'connectInputs' makes sense; a flag similar to 'contentType' can be set and it can be
163
162
  * used later to avoid calling 'handleQueryParams()'
164
163
  *
165
- * @param {Object} sourceContext { reqData, protect } that will be supplied to
164
+ * @param {Object} sourceContext { protect } that will be supplied to
166
165
  * all handlers and sinks for this request. It will always be supplied by the caller
167
166
  * to a handler; the handler is not aware of the implementation.
168
167
  * @param {Object} connectInputs each property is an input to be evaluated by this
@@ -343,7 +342,8 @@ module.exports = Core.makeComponent({
343
342
 
344
343
  let bodyType;
345
344
  let inputTypes;
346
- if (sourceContext.reqData.contentType.includes('/json')) {
345
+ const { sourceInfo } = core.scopes.sources.getStore();
346
+ if (sourceInfo?.contentType?.includes?.('/json')) {
347
347
  bodyType = 'json';
348
348
  inputTypes = jsonInputTypes;
349
349
  } else {
@@ -438,9 +438,8 @@ module.exports = Core.makeComponent({
438
438
  inputAnalysis.handleIpAllowlist = function(sourceContext, ipAllowlist) {
439
439
  if (!sourceContext || !ipAllowlist.length) return;
440
440
 
441
- const { ip: reqIp, headers: reqHeaders } = sourceContext.reqData;
442
-
443
- const match = ipListAnalysis(reqIp, reqHeaders, ipAllowlist);
441
+ const { sourceInfo } = core.scopes.sources.getStore();
442
+ const match = ipListAnalysis(sourceInfo.ip, sourceInfo.rawHeaders, ipAllowlist);
444
443
 
445
444
  if (match) {
446
445
  logger.info(match, 'Found a matching IP to an entry in ipAllow list');
@@ -453,9 +452,8 @@ module.exports = Core.makeComponent({
453
452
 
454
453
  if (!sourceContext || !ipDenylist.length) return;
455
454
 
456
- const { ip: reqIp, headers: reqHeaders } = sourceContext.reqData;
457
-
458
- const match = ipListAnalysis(reqIp, reqHeaders, ipDenylist);
455
+ const { sourceInfo } = core.scopes.sources.getStore();
456
+ const match = ipListAnalysis(sourceInfo.Ip, sourceInfo.rawHeaders, ipDenylist);
459
457
 
460
458
  if (match) {
461
459
  logger.info(match, 'Found a matching IP to an entry in ipDeny list');
@@ -27,7 +27,7 @@ module.exports = function(core) {
27
27
  require('./install/http')(core);
28
28
 
29
29
  // common libraries instrumentation
30
- require('./install/body-parser1')(core);
30
+ require('./install/body-parser')(core);
31
31
  require('./install/cookie-parser1')(core);
32
32
  require('./install/formidable1')(core);
33
33
  require('./install/koa-body5')(core);
@@ -62,7 +62,7 @@ module.exports = (core) => {
62
62
 
63
63
  // Patch body parser - `body-parser` used by `express` framework
64
64
  function install() {
65
- depHooks.resolve({ name: 'body-parser', version: '<2' }, (bodyParser) => {
65
+ depHooks.resolve({ name: 'body-parser', version: '<3' }, (bodyParser) => {
66
66
  const origBodyParser = bodyParser;
67
67
 
68
68
  const { json: origJson, raw: origRaw, text: origText, urlencoded: origUrlencoded } = bodyParser;
@@ -31,24 +31,19 @@ module.exports = function (core) {
31
31
  },
32
32
  } = core;
33
33
 
34
- const instr = inputAnalysis.httpInstrumentation = {
35
- install,
36
- around
37
- };
38
-
39
- function removeCookies(headers) {
40
- for (let i = 0; i < headers.length; i += 2) {
41
- if (headers[i] === 'cookies') {
42
- headers = ArrayPrototypeSlice.call(headers);
43
- headers.splice(i, 2);
34
+ function removeCookies(rawHeaders) {
35
+ for (let i = 0; i < rawHeaders.length; i += 2) {
36
+ if (rawHeaders[i] === 'cookies') {
37
+ rawHeaders = ArrayPrototypeSlice.call(rawHeaders);
38
+ rawHeaders.splice(i, 2);
44
39
  }
45
40
  }
46
- return headers;
41
+ return rawHeaders;
47
42
  }
48
43
 
49
44
  function around(next, data) {
50
45
  let store, block;
51
- const { args: [type, req, res] } = data;
46
+ const { args: [type,, res] } = data;
52
47
 
53
48
  function callNext() {
54
49
  setImmediate(() => {
@@ -63,21 +58,20 @@ module.exports = function (core) {
63
58
 
64
59
  try {
65
60
  store = sources.getStore();
66
- if (!store) {
61
+ if (!store?.protect) {
67
62
  logger.debug({ funcKey: data.funcKey }, 'request store not available during http input-analysis');
63
+ callNext();
68
64
  return;
69
65
  }
70
-
71
- store.protect = core.protect.makeSourceContext(req, res);
72
66
  if (store.protect.allowed) {
73
67
  callNext();
74
68
  return;
75
69
  }
76
70
 
77
71
  const {
78
- reqData: { headers, uriPath, method },
79
- resData,
80
- } = store.protect;
72
+ sourceInfo: { method, rawHeaders, uriPath },
73
+ protect: { resData }
74
+ } = store;
81
75
 
82
76
  onFinished(res, (/* err, req */) => {
83
77
  resData.statusCode = res.statusCode;
@@ -86,7 +80,7 @@ module.exports = function (core) {
86
80
  });
87
81
 
88
82
  const connectInputs = {
89
- headers: removeCookies(headers),
83
+ headers: removeCookies(rawHeaders),
90
84
  uriPath,
91
85
  method: StringPrototypeToLowerCase.call(method),
92
86
  };
@@ -131,5 +125,10 @@ module.exports = function (core) {
131
125
  });
132
126
  }
133
127
 
128
+ const instr = inputAnalysis.httpInstrumentation = {
129
+ install,
130
+ around
131
+ };
132
+
134
133
  return instr;
135
134
  };
@@ -22,34 +22,35 @@ module.exports = (core) => {
22
22
  depHooks,
23
23
  patcher,
24
24
  protect,
25
- protect: { inputAnalysis },
25
+ scopes,
26
26
  } = core;
27
27
 
28
28
  // Patch `qs`
29
29
  function install() {
30
- depHooks.resolve({ name: 'qs', version: '<7' },
31
- (qs) => patcher.patch(qs, 'parse', {
32
- name: 'qs',
33
- patchType,
34
- post({ args, result }) {
35
- if (result && Object.keys(result).length) {
36
- const sourceContext = protect.getSourceContext();
37
-
38
- // We need to run analysis for the `qs` result only when it's used as a query parser.
39
- // `qs` is used also for parsing bodies, but these cases we handle individually with
40
- // the respective library that's using it (e.g. `formidable`, `co-body`) because in
41
- // some cases its use is optional and we cannot rely on it.
42
- if (sourceContext && sourceContext.reqData?.queries === args[0]) {
30
+ depHooks.resolve({ name: 'qs', version: '<7' }, (qs) => patcher.patch(qs, 'parse', {
31
+ name: 'qs',
32
+ patchType,
33
+ post({ args, result }) {
34
+ if (result && Object.keys(result).length) {
35
+ const sourceContext = protect.getSourceContext();
36
+ // We need to run analysis for the `qs` result only when it's used as a query parser.
37
+ // `qs` is used also for parsing bodies, but these cases we handle individually with
38
+ // the respective library that's using it (e.g. `formidable`, `co-body`) because in
39
+ // some cases its use is optional and we cannot rely on it.
40
+ if (sourceContext) {
41
+ const { sourceInfo } = scopes.sources.getStore();
42
+ if (sourceInfo.queries === args[0]) {
43
43
  sourceContext.parsedQuery = result;
44
- inputAnalysis.handleQueryParams(sourceContext, result);
44
+ protect.inputAnalysis.handleQueryParams(sourceContext, result);
45
45
  }
46
46
  }
47
47
  }
48
- })
48
+ }
49
+ })
49
50
  );
50
51
  }
51
52
 
52
- const qs6Instrumentation = inputAnalysis.qs6Instrumentation = {
53
+ const qs6Instrumentation = protect.inputAnalysis.qs6Instrumentation = {
53
54
  install
54
55
  };
55
56
 
@@ -22,7 +22,6 @@ module.exports = (core) => {
22
22
  depHooks,
23
23
  patcher,
24
24
  protect,
25
- protect: { inputAnalysis },
26
25
  } = core;
27
26
 
28
27
  // Patch `universal-cookie` package
@@ -36,7 +35,7 @@ module.exports = (core) => {
36
35
 
37
36
  if (sourceContext) {
38
37
  sourceContext.parsedCookies = result;
39
- inputAnalysis.handleCookies(sourceContext, result);
38
+ protect.inputAnalysis.handleCookies(sourceContext, result);
40
39
  }
41
40
  }
42
41
  }
@@ -44,7 +43,7 @@ module.exports = (core) => {
44
43
  );
45
44
  }
46
45
 
47
- const universalCookie4Instrumentation = inputAnalysis.universalCookie4Instrumentation = {
46
+ const universalCookie4Instrumentation = protect.inputAnalysis.universalCookie4Instrumentation = {
48
47
  install
49
48
  };
50
49
 
@@ -15,80 +15,36 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { primordials: { StringPrototypeToLowerCase, StringPrototypeSlice } } = require('@contrast/common');
19
-
20
18
  module.exports = function(core) {
21
- const {
22
- protect: { getPolicy }
23
- } = core;
24
-
25
- const disabledPolicy = { allowed: true };
26
-
27
- function makeSourceContext(req, res) {
28
- if (!core.config.getEffectiveValue('protect.enable')) {
29
- return disabledPolicy;
30
- }
31
-
32
- // make the abstract request. it is an abstraction of a request that
33
- // contains only the pieces of the request required by handlers. this
34
- // is done to make an explicit contract for data that is required by
35
- // the handlers. additional data that is discovered to be required by
36
- // handlers should be added here. the goal is not to pass the raw req
37
- // or res objects so that all data coupling is all defined here.
38
-
39
- // separate path and search params
40
-
41
- let uriPath, queries;
42
- const ix = req.url.indexOf('?');
43
-
44
- if (ix >= 0) {
45
- uriPath = StringPrototypeSlice.call(req.url, 0, ix);
46
- queries = StringPrototypeSlice.call(req.url, ix + 1);
47
- } else {
48
- uriPath = req.url;
49
- queries = '';
50
- }
51
-
52
- const policy = getPolicy({ uriPath });
53
-
19
+ const { protect } = core;
20
+
21
+ const DISABLED_POLICY = { allowed: true };
22
+
23
+ /**
24
+ * @param {object} param
25
+ * @param {object} param.store
26
+ * @param {import('@contrast/common').SourceInfo} param.store.sourceInfo
27
+ * @param {import('node:http').IncomingMessage} param.incomingMessage
28
+ * @param {import('node:http').ServerResponse} param.serverResponse
29
+ *
30
+ */
31
+ function makeSourceContext({
32
+ store: { sourceInfo },
33
+ // incomingMessage,
34
+ serverResponse,
35
+ }) {
36
+ if (!core.config.getEffectiveValue('protect.enable')) return DISABLED_POLICY;
37
+
38
+ const policy = protect.getPolicy({ uriPath: sourceInfo.uriPath });
54
39
  // URL exclusions can disable all rules
55
- if (!policy || policy.rulesMask === 0) {
56
- return disabledPolicy;
57
- }
58
-
59
- // lowercase header keys and capture content-type
60
- let contentType = '';
61
- const headers = Array(req.rawHeaders.length);
62
-
63
- for (let i = 0; i < req.rawHeaders.length; i += 2) {
64
- headers[i] = StringPrototypeToLowerCase.call(req.rawHeaders[i]);
65
- headers[i + 1] = req.rawHeaders[i + 1];
66
- if (headers[i] === 'content-type') {
67
- contentType = StringPrototypeToLowerCase.call(headers[i + 1]);
68
- }
69
- }
70
-
71
- // contains request data and information derived from request data. it's
72
- // possible for any derived information to be derived later, but doing
73
- // so here is typically better; it makes clear what information is used to
74
- // make decisions by different handlers.
75
- const reqData = {
76
- ip: req.socket.remoteAddress,
77
- httpVersion: req.httpVersion,
78
- method: req.method,
79
- headers,
80
- uriPath,
81
- queries,
82
- contentType,
83
- };
40
+ if (!policy || policy.rulesMask === 0) return DISABLED_POLICY;
84
41
 
85
42
  const protectStore = {
86
- reqData,
87
43
  resData: {
88
44
  statusCode: null,
89
45
  },
90
46
  // block closure captures res so it isn't exposed to beyond here
91
- blocker: new core.protect.Blocker(res),
47
+ blocker: new core.protect.Blocker(serverResponse),
92
48
  policy,
93
49
  exclusions: [],
94
50
  virtualPatchesEvaluators: [],