contrast-agent 4.13.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (390) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +2 -1
  3. data/Gemfile +1 -1
  4. data/LICENSE.txt +1 -1
  5. data/Rakefile +1 -1
  6. data/exe/contrast_service +1 -1
  7. data/ext/build_funchook.rb +1 -1
  8. data/ext/cs__assess_array/cs__assess_array.c +1 -1
  9. data/ext/cs__assess_array/extconf.rb +1 -1
  10. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +1 -1
  11. data/ext/cs__assess_basic_object/extconf.rb +1 -1
  12. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  13. data/ext/cs__assess_fiber_track/extconf.rb +1 -1
  14. data/ext/cs__assess_hash/cs__assess_hash.c +1 -1
  15. data/ext/cs__assess_hash/extconf.rb +1 -1
  16. data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -1
  17. data/ext/cs__assess_kernel/extconf.rb +1 -1
  18. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +1 -1
  19. data/ext/cs__assess_marshal_module/extconf.rb +1 -1
  20. data/ext/cs__assess_module/cs__assess_module.c +1 -1
  21. data/ext/cs__assess_module/extconf.rb +1 -1
  22. data/ext/cs__assess_regexp/cs__assess_regexp.c +1 -1
  23. data/ext/cs__assess_regexp/extconf.rb +1 -1
  24. data/ext/cs__assess_string/cs__assess_string.c +1 -1
  25. data/ext/cs__assess_string/extconf.rb +1 -1
  26. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +1 -1
  27. data/ext/cs__assess_string_interpolation26/extconf.rb +1 -1
  28. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -1
  29. data/ext/cs__assess_yield_track/extconf.rb +1 -1
  30. data/ext/cs__common/cs__common.c +1 -1
  31. data/ext/cs__common/extconf.rb +1 -1
  32. data/ext/cs__contrast_patch/cs__contrast_patch.c +1 -1
  33. data/ext/cs__contrast_patch/extconf.rb +1 -1
  34. data/ext/cs__os_information/cs__os_information.c +1 -1
  35. data/ext/cs__os_information/extconf.rb +1 -1
  36. data/ext/extconf_common.rb +1 -1
  37. data/lib/contrast/agent/assess/contrast_event.rb +7 -11
  38. data/lib/contrast/agent/assess/contrast_object.rb +1 -1
  39. data/lib/contrast/agent/assess/events/event_data.rb +30 -0
  40. data/lib/contrast/agent/assess/events/event_factory.rb +14 -6
  41. data/lib/contrast/agent/assess/events/source_event.rb +22 -3
  42. data/lib/contrast/agent/assess/finalizers/freeze.rb +1 -1
  43. data/lib/contrast/agent/assess/finalizers/hash.rb +1 -1
  44. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +7 -7
  45. data/lib/contrast/agent/assess/policy/patcher.rb +1 -35
  46. data/lib/contrast/agent/assess/policy/policy.rb +1 -1
  47. data/lib/contrast/agent/assess/policy/policy_node.rb +7 -7
  48. data/lib/contrast/agent/assess/policy/policy_scanner.rb +6 -1
  49. data/lib/contrast/agent/assess/policy/preshift.rb +1 -1
  50. data/lib/contrast/agent/assess/policy/propagation_method.rb +55 -28
  51. data/lib/contrast/agent/assess/policy/propagation_node.rb +1 -1
  52. data/lib/contrast/agent/assess/policy/propagator/append.rb +1 -1
  53. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  54. data/lib/contrast/agent/assess/policy/propagator/center.rb +2 -2
  55. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  56. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -2
  57. data/lib/contrast/agent/assess/policy/propagator/insert.rb +5 -2
  58. data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -1
  59. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +7 -3
  60. data/lib/contrast/agent/assess/policy/propagator/next.rb +1 -1
  61. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +1 -1
  62. data/lib/contrast/agent/assess/policy/propagator/rack_protection.rb +1 -1
  63. data/lib/contrast/agent/assess/policy/propagator/remove.rb +1 -1
  64. data/lib/contrast/agent/assess/policy/propagator/replace.rb +1 -1
  65. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +1 -1
  66. data/lib/contrast/agent/assess/policy/propagator/select.rb +3 -2
  67. data/lib/contrast/agent/assess/policy/propagator/splat.rb +1 -1
  68. data/lib/contrast/agent/assess/policy/propagator/split.rb +27 -25
  69. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +3 -157
  70. data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +190 -0
  71. data/lib/contrast/agent/assess/policy/propagator/trim.rb +9 -4
  72. data/lib/contrast/agent/assess/policy/propagator.rb +1 -1
  73. data/lib/contrast/agent/assess/policy/source_method.rb +39 -26
  74. data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
  75. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  76. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  77. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +7 -2
  78. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
  79. data/lib/contrast/agent/assess/policy/trigger_method.rb +68 -18
  80. data/lib/contrast/agent/assess/policy/trigger_node.rb +15 -7
  81. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  82. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
  83. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +1 -1
  84. data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +2 -2
  85. data/lib/contrast/agent/assess/properties.rb +1 -1
  86. data/lib/contrast/agent/assess/property/evented.rb +25 -12
  87. data/lib/contrast/agent/assess/property/tagged.rb +52 -58
  88. data/lib/contrast/agent/assess/property/updated.rb +1 -1
  89. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +1 -19
  90. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +1 -13
  91. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +42 -60
  92. data/lib/contrast/agent/assess/rule/provider.rb +1 -1
  93. data/lib/contrast/agent/assess/rule/response/autocomplete_rule.rb +130 -0
  94. data/lib/contrast/agent/assess/rule/response/base_rule.rb +117 -0
  95. data/lib/contrast/agent/assess/tag.rb +1 -1
  96. data/lib/contrast/agent/assess/tracker.rb +1 -1
  97. data/lib/contrast/agent/assess.rb +1 -2
  98. data/lib/contrast/agent/at_exit_hook.rb +1 -1
  99. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +13 -8
  100. data/lib/contrast/agent/deadzone/policy/policy.rb +1 -1
  101. data/lib/contrast/agent/disable_reaction.rb +1 -1
  102. data/lib/contrast/agent/exclusion_matcher.rb +1 -1
  103. data/lib/contrast/agent/inventory/database_config.rb +115 -77
  104. data/lib/contrast/agent/inventory/dependencies.rb +1 -1
  105. data/lib/contrast/agent/inventory/dependency_analysis.rb +1 -1
  106. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +3 -3
  107. data/lib/contrast/agent/inventory/policy/datastores.rb +1 -1
  108. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  109. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  110. data/lib/contrast/agent/inventory.rb +1 -1
  111. data/lib/contrast/agent/metric_telemetry_event.rb +3 -3
  112. data/lib/contrast/agent/middleware.rb +8 -77
  113. data/lib/contrast/agent/module_data.rb +1 -1
  114. data/lib/contrast/agent/patching/policy/after_load_patch.rb +1 -1
  115. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +1 -1
  116. data/lib/contrast/agent/patching/policy/method_policy.rb +31 -104
  117. data/lib/contrast/agent/patching/policy/method_policy_extend.rb +113 -0
  118. data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
  119. data/lib/contrast/agent/patching/policy/patch.rb +1 -1
  120. data/lib/contrast/agent/patching/policy/patch_status.rb +2 -26
  121. data/lib/contrast/agent/patching/policy/patcher.rb +13 -13
  122. data/lib/contrast/agent/patching/policy/policy.rb +1 -1
  123. data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
  124. data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
  125. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +1 -1
  126. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +1 -1
  127. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +1 -1
  128. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +1 -1
  129. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -1
  130. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
  131. data/lib/contrast/agent/protect/policy/policy.rb +1 -1
  132. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  133. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  134. data/lib/contrast/agent/protect/rule/base.rb +1 -1
  135. data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
  136. data/lib/contrast/agent/protect/rule/cmd_injection.rb +1 -1
  137. data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
  138. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  139. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
  140. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -1
  141. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  142. data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -1
  143. data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +1 -1
  144. data/lib/contrast/agent/protect/rule/sqli/default_sql_scanner.rb +1 -1
  145. data/lib/contrast/agent/protect/rule/sqli/mysql_sql_scanner.rb +1 -1
  146. data/lib/contrast/agent/protect/rule/sqli/postgres_sql_scanner.rb +2 -2
  147. data/lib/contrast/agent/protect/rule/sqli/sqlite_sql_scanner.rb +1 -1
  148. data/lib/contrast/agent/protect/rule/sqli.rb +1 -1
  149. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  150. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  151. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +1 -1
  152. data/lib/contrast/agent/protect/rule/xxe.rb +1 -1
  153. data/lib/contrast/agent/protect/rule.rb +1 -1
  154. data/lib/contrast/agent/reaction_processor.rb +1 -1
  155. data/lib/contrast/agent/reporting/report.rb +27 -0
  156. data/lib/contrast/agent/reporting/reporter.rb +115 -0
  157. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +49 -0
  158. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +82 -0
  159. data/lib/contrast/agent/reporting/reporting_events/architecture_component.rb +80 -0
  160. data/lib/contrast/agent/reporting/reporting_events/discovered_route.rb +59 -0
  161. data/lib/contrast/agent/reporting/reporting_events/finding.rb +185 -0
  162. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +264 -0
  163. data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +57 -0
  164. data/lib/contrast/agent/reporting/reporting_events/finding_object.rb +90 -0
  165. data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +121 -0
  166. data/lib/contrast/agent/reporting/reporting_events/finding_signature.rb +105 -0
  167. data/lib/contrast/agent/reporting/reporting_events/finding_stack.rb +67 -0
  168. data/lib/contrast/agent/reporting/reporting_events/finding_taint_range.rb +58 -0
  169. data/lib/contrast/agent/reporting/reporting_events/library_discovery.rb +93 -0
  170. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +50 -0
  171. data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +54 -0
  172. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +66 -0
  173. data/lib/contrast/agent/reporting/reporting_events/preflight.rb +39 -0
  174. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +75 -0
  175. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +47 -0
  176. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +76 -0
  177. data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +66 -0
  178. data/lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb +65 -0
  179. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +52 -0
  180. data/lib/contrast/agent/reporting/reporting_events/trace_event_source.rb +30 -0
  181. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +137 -0
  182. data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +67 -0
  183. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +165 -0
  184. data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +55 -0
  185. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +86 -0
  186. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +154 -0
  187. data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +66 -0
  188. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +30 -0
  189. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +57 -0
  190. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +196 -0
  191. data/lib/contrast/agent/reporting/settings/application_settings.rb +67 -0
  192. data/lib/contrast/agent/reporting/settings/assess.rb +45 -0
  193. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +136 -0
  194. data/lib/contrast/agent/reporting/settings/exclusions.rb +123 -0
  195. data/lib/contrast/agent/reporting/settings/protect.rb +89 -0
  196. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +243 -0
  197. data/lib/contrast/agent/reporting/settings/reaction.rb +30 -0
  198. data/lib/contrast/agent/reporting/settings/server_features.rb +78 -0
  199. data/lib/contrast/agent/request.rb +46 -84
  200. data/lib/contrast/agent/request_context.rb +20 -131
  201. data/lib/contrast/agent/request_context_extend.rb +163 -0
  202. data/lib/contrast/agent/request_handler.rb +41 -5
  203. data/lib/contrast/agent/response.rb +25 -88
  204. data/lib/contrast/agent/rule_set.rb +1 -1
  205. data/lib/contrast/agent/scope.rb +1 -1
  206. data/lib/contrast/agent/service_heartbeat.rb +1 -1
  207. data/lib/contrast/agent/startup_metrics_telemetry_event.rb +73 -23
  208. data/lib/contrast/agent/static_analysis.rb +14 -4
  209. data/lib/contrast/agent/telemetry.rb +16 -8
  210. data/lib/contrast/agent/telemetry_event.rb +9 -10
  211. data/lib/contrast/agent/thread.rb +1 -1
  212. data/lib/contrast/agent/thread_watcher.rb +32 -6
  213. data/lib/contrast/agent/tracepoint_hook.rb +1 -4
  214. data/lib/contrast/agent/version.rb +2 -2
  215. data/lib/contrast/agent/worker_thread.rb +1 -1
  216. data/lib/contrast/agent.rb +16 -1
  217. data/lib/contrast/api/communication/connection_status.rb +11 -8
  218. data/lib/contrast/api/communication/messaging_queue.rb +38 -4
  219. data/lib/contrast/api/communication/response_processor.rb +22 -11
  220. data/lib/contrast/api/communication/service_lifecycle.rb +14 -4
  221. data/lib/contrast/api/communication/socket.rb +7 -9
  222. data/lib/contrast/api/communication/socket_client.rb +33 -13
  223. data/lib/contrast/api/communication/speedracer.rb +38 -2
  224. data/lib/contrast/api/communication/tcp_socket.rb +5 -4
  225. data/lib/contrast/api/communication/unix_socket.rb +2 -1
  226. data/lib/contrast/api/communication.rb +1 -1
  227. data/lib/contrast/api/decorators/address.rb +1 -1
  228. data/lib/contrast/api/decorators/agent_startup.rb +1 -1
  229. data/lib/contrast/api/decorators/application_settings.rb +1 -1
  230. data/lib/contrast/api/decorators/application_startup.rb +1 -1
  231. data/lib/contrast/api/decorators/application_update.rb +1 -1
  232. data/lib/contrast/api/decorators/architecture_component.rb +36 -0
  233. data/lib/contrast/api/decorators/finding.rb +29 -0
  234. data/lib/contrast/api/decorators/http_request.rb +3 -2
  235. data/lib/contrast/api/decorators/input_analysis.rb +1 -1
  236. data/lib/contrast/api/decorators/instrumentation_mode.rb +1 -1
  237. data/lib/contrast/api/decorators/library.rb +1 -1
  238. data/lib/contrast/api/decorators/library_usage_update.rb +1 -1
  239. data/lib/contrast/api/decorators/message.rb +1 -1
  240. data/lib/contrast/api/decorators/rasp_rule_sample.rb +1 -1
  241. data/lib/contrast/api/decorators/route_coverage.rb +1 -1
  242. data/lib/contrast/api/decorators/server_features.rb +1 -1
  243. data/lib/contrast/api/decorators/trace_event.rb +1 -1
  244. data/lib/contrast/api/decorators/trace_event_object.rb +1 -1
  245. data/lib/contrast/api/decorators/trace_event_signature.rb +1 -1
  246. data/lib/contrast/api/decorators/trace_taint_range.rb +1 -1
  247. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +1 -1
  248. data/lib/contrast/api/decorators/user_input.rb +1 -1
  249. data/lib/contrast/api/decorators.rb +2 -1
  250. data/lib/contrast/api.rb +1 -1
  251. data/lib/contrast/components/agent.rb +5 -24
  252. data/lib/contrast/components/api.rb +67 -2
  253. data/lib/contrast/components/app_context.rb +12 -66
  254. data/lib/contrast/components/app_context_extend.rb +78 -0
  255. data/lib/contrast/components/assess.rb +12 -8
  256. data/lib/contrast/components/base.rb +24 -1
  257. data/lib/contrast/components/config.rb +38 -23
  258. data/lib/contrast/components/contrast_service.rb +6 -1
  259. data/lib/contrast/components/heap_dump.rb +1 -1
  260. data/lib/contrast/components/inventory.rb +5 -1
  261. data/lib/contrast/components/logger.rb +1 -1
  262. data/lib/contrast/components/protect.rb +6 -2
  263. data/lib/contrast/components/sampling.rb +3 -3
  264. data/lib/contrast/components/scope.rb +1 -1
  265. data/lib/contrast/components/settings.rb +25 -12
  266. data/lib/contrast/config/agent_configuration.rb +2 -2
  267. data/lib/contrast/config/api_configuration.rb +9 -4
  268. data/lib/contrast/config/api_proxy_configuration.rb +14 -0
  269. data/lib/contrast/config/application_configuration.rb +3 -4
  270. data/lib/contrast/config/assess_configuration.rb +4 -4
  271. data/lib/contrast/config/assess_rules_configuration.rb +1 -1
  272. data/lib/contrast/config/base_configuration.rb +18 -29
  273. data/lib/contrast/config/certification_configuration.rb +15 -0
  274. data/lib/contrast/config/env_variables.rb +3 -10
  275. data/lib/contrast/config/exception_configuration.rb +1 -1
  276. data/lib/contrast/config/heap_dump_configuration.rb +7 -7
  277. data/lib/contrast/config/inventory_configuration.rb +2 -6
  278. data/lib/contrast/config/logger_configuration.rb +1 -1
  279. data/lib/contrast/config/protect_configuration.rb +1 -1
  280. data/lib/contrast/config/protect_rule_configuration.rb +2 -2
  281. data/lib/contrast/config/protect_rules_configuration.rb +1 -1
  282. data/lib/contrast/config/request_audit_configuration.rb +18 -0
  283. data/lib/contrast/config/root_configuration.rb +1 -1
  284. data/lib/contrast/config/ruby_configuration.rb +10 -7
  285. data/lib/contrast/config/sampling_configuration.rb +1 -1
  286. data/lib/contrast/config/server_configuration.rb +1 -1
  287. data/lib/contrast/config/service_configuration.rb +2 -3
  288. data/lib/contrast/config.rb +1 -2
  289. data/lib/contrast/configuration.rb +2 -3
  290. data/lib/contrast/extension/assess/array.rb +9 -9
  291. data/lib/contrast/extension/assess/erb.rb +15 -5
  292. data/lib/contrast/extension/assess/eval_trigger.rb +3 -1
  293. data/lib/contrast/extension/assess/exec_trigger.rb +2 -1
  294. data/lib/contrast/extension/assess/fiber.rb +6 -3
  295. data/lib/contrast/extension/assess/hash.rb +1 -1
  296. data/lib/contrast/extension/assess/kernel.rb +8 -3
  297. data/lib/contrast/extension/assess/marshal.rb +6 -2
  298. data/lib/contrast/extension/assess/regexp.rb +8 -2
  299. data/lib/contrast/extension/assess/string.rb +8 -2
  300. data/lib/contrast/extension/assess.rb +1 -1
  301. data/lib/contrast/extension/delegator.rb +1 -1
  302. data/lib/contrast/extension/extension.rb +2 -4
  303. data/lib/contrast/extension/inventory.rb +1 -1
  304. data/lib/contrast/extension/kernel.rb +1 -1
  305. data/lib/contrast/extension/module.rb +1 -1
  306. data/lib/contrast/extension/protect/psych.rb +1 -1
  307. data/lib/contrast/extension/protect.rb +1 -1
  308. data/lib/contrast/extension/thread.rb +32 -13
  309. data/lib/contrast/framework/base_support.rb +5 -1
  310. data/lib/contrast/framework/grape/support.rb +25 -1
  311. data/lib/contrast/framework/manager.rb +33 -36
  312. data/lib/contrast/framework/manager_extend.rb +50 -0
  313. data/lib/contrast/framework/platform_version.rb +1 -1
  314. data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
  315. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  316. data/lib/contrast/framework/rack/support.rb +1 -1
  317. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -1
  318. data/lib/contrast/framework/rails/patch/assess_configuration.rb +1 -1
  319. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  320. data/lib/contrast/framework/rails/patch/support.rb +1 -1
  321. data/lib/contrast/framework/rails/railtie.rb +2 -2
  322. data/lib/contrast/framework/rails/support.rb +46 -2
  323. data/lib/contrast/framework/sinatra/support.rb +26 -3
  324. data/lib/contrast/funchook/funchook.rb +21 -18
  325. data/lib/contrast/logger/application.rb +1 -1
  326. data/lib/contrast/logger/format.rb +1 -1
  327. data/lib/contrast/logger/log.rb +9 -104
  328. data/lib/contrast/logger/request.rb +1 -1
  329. data/lib/contrast/logger/time.rb +1 -1
  330. data/lib/contrast/security_exception.rb +1 -1
  331. data/lib/contrast/tasks/config.rb +1 -1
  332. data/lib/contrast/tasks/service.rb +1 -1
  333. data/lib/contrast/utils/assess/propagation_method_utils.rb +1 -1
  334. data/lib/contrast/utils/assess/property/tagged_utils.rb +24 -1
  335. data/lib/contrast/utils/assess/sampling_util.rb +4 -4
  336. data/lib/contrast/utils/assess/source_method_utils.rb +1 -1
  337. data/lib/contrast/utils/assess/split_utils.rb +23 -0
  338. data/lib/contrast/utils/assess/tracking_util.rb +21 -16
  339. data/lib/contrast/utils/assess/trigger_method_utils.rb +4 -3
  340. data/lib/contrast/utils/class_util.rb +19 -15
  341. data/lib/contrast/utils/duck_utils.rb +1 -1
  342. data/lib/contrast/utils/env_configuration_item.rb +2 -2
  343. data/lib/contrast/utils/exclude_key.rb +1 -1
  344. data/lib/contrast/utils/findings.rb +65 -0
  345. data/lib/contrast/utils/hash_digest.rb +46 -79
  346. data/lib/contrast/utils/hash_digest_extend.rb +129 -0
  347. data/lib/contrast/utils/head_dump_utils_extend.rb +74 -0
  348. data/lib/contrast/utils/heap_dump_util.rb +3 -66
  349. data/lib/contrast/utils/invalid_configuration_util.rb +32 -2
  350. data/lib/contrast/utils/io_util.rb +2 -2
  351. data/lib/contrast/utils/job_servers_running.rb +1 -1
  352. data/lib/contrast/utils/log_utils.rb +108 -0
  353. data/lib/contrast/utils/lru_cache.rb +1 -1
  354. data/lib/contrast/utils/metrics_hash.rb +2 -2
  355. data/lib/contrast/utils/middleware_utils.rb +87 -0
  356. data/lib/contrast/utils/net_http_base.rb +165 -0
  357. data/lib/contrast/utils/object_share.rb +2 -6
  358. data/lib/contrast/utils/os.rb +9 -5
  359. data/lib/contrast/utils/patching/policy/patch_utils.rb +63 -99
  360. data/lib/contrast/utils/patching/policy/patcher_utils.rb +1 -1
  361. data/lib/contrast/utils/preflight_util.rb +1 -1
  362. data/lib/contrast/utils/request_utils.rb +96 -0
  363. data/lib/contrast/utils/resource_loader.rb +1 -1
  364. data/lib/contrast/utils/response_utils.rb +97 -0
  365. data/lib/contrast/utils/sha256_builder.rb +1 -1
  366. data/lib/contrast/utils/stack_trace_utils.rb +1 -1
  367. data/lib/contrast/utils/string_utils.rb +69 -67
  368. data/lib/contrast/utils/tag_util.rb +11 -10
  369. data/lib/contrast/utils/telemetry.rb +11 -10
  370. data/lib/contrast/utils/telemetry_client.rb +90 -0
  371. data/lib/contrast/utils/telemetry_identifier.rb +18 -25
  372. data/lib/contrast/utils/thread_tracker.rb +1 -1
  373. data/lib/contrast/utils/timer.rb +1 -1
  374. data/lib/contrast-agent.rb +1 -1
  375. data/lib/contrast.rb +1 -1
  376. data/ruby-agent.gemspec +9 -10
  377. metadata +102 -49
  378. data/ext/cs__assess_active_record_named/cs__active_record_named.c +0 -46
  379. data/ext/cs__assess_active_record_named/cs__active_record_named.h +0 -11
  380. data/ext/cs__assess_active_record_named/extconf.rb +0 -5
  381. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +0 -95
  382. data/lib/contrast/agent/class_reopener.rb +0 -258
  383. data/lib/contrast/agent/rewriter.rb +0 -259
  384. data/lib/contrast/config/default_value.rb +0 -17
  385. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +0 -37
  386. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +0 -41
  387. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +0 -75
  388. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +0 -35
  389. data/lib/contrast/utils/requests_client.rb +0 -150
  390. data/lib/contrast/utils/ruby_ast_rewriter.rb +0 -82
@@ -0,0 +1,108 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ module Contrast
5
+ module Utils
6
+ # Method utility used by Contrast::Logger::log
7
+ module LogUtils
8
+ DEFAULT_NAME = 'contrast.log'
9
+ DEFAULT_LEVEL = ::Ougai::Logging::Severity::INFO
10
+ VALID_LEVELS = ::Ougai::Logging::Severity::SEV_LABEL
11
+ STDOUT_STR = 'STDOUT'
12
+ STDERR_STR = 'STDERR'
13
+ PROGNAME = 'Contrast Agent'
14
+ DATE_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%L%z'
15
+
16
+ private
17
+
18
+ def build path: STDOUT_STR, level_const: DEFAULT_LEVEL
19
+ logger = case path
20
+ when STDOUT_STR, STDERR_STR
21
+ ::Ougai::Logger.new(Object.cs__const_get(path))
22
+ else
23
+ ::Ougai::Logger.new(path)
24
+ end
25
+ add_contrast_loggers(logger)
26
+ logger.progname = PROGNAME
27
+ logger.level = level_const
28
+ logger.formatter = Contrast::Logger::Format.new
29
+ logger.formatter.datetime_format = DATE_TIME_FORMAT
30
+ logger
31
+ end
32
+
33
+ def add_contrast_loggers logger
34
+ logger.extend(Contrast::Logger::Application)
35
+ logger.extend(Contrast::Logger::Request)
36
+ logger.extend(Contrast::Logger::Time)
37
+ end
38
+
39
+ # Determine the valid path to which to log, given the precedence of config > settings > default.
40
+ #
41
+ # @param log_file [String, nil] the file to which to log as provided by the settings retrieved from the
42
+ # TeamServer.
43
+ # @return [String] the path to which to log or STDOUT / STDERR if one of those values provided.
44
+ def find_valid_path log_file
45
+ config = ::Contrast::CONFIG.root.agent.logger
46
+ config_path = config&.path&.length.to_i.positive? ? config.path : nil
47
+ valid_path(config_path || log_file)
48
+ end
49
+
50
+ def valid_path path
51
+ path = path.nil? ? Contrast::Utils::ObjectShare::EMPTY_STRING : path
52
+ return path if path == STDOUT_STR
53
+ return path if path == STDERR_STR
54
+
55
+ path = DEFAULT_NAME if path.empty?
56
+ if write_permission?(path)
57
+ path
58
+ elsif write_permission?(DEFAULT_NAME)
59
+ # Log once when the path is invalid. We'll change to this path, so no
60
+ # need to log again.
61
+ if previous_path != DEFAULT_NAME
62
+ $stdout.puts "[!] Unable to write to '#{ path }'. Writing to default log '#{ DEFAULT_NAME }' instead."
63
+ end
64
+ DEFAULT_NAME
65
+ else
66
+ # Log once when the path is invalid. We'll change to this path, so no
67
+ # need to log again.
68
+ $stdout.puts "[!] Unable to write to '#{ path }'. Writing to standard out instead."
69
+ STDOUT_STR
70
+ end
71
+ end
72
+
73
+ # Determine the valid level to which to log, given the precedence of config > settings > default.
74
+ #
75
+ # @param log_level [String, nil] the level at which to log as provided by the settings retrieved from the
76
+ # TeamServer.
77
+ # @return [::Ougai::Logging::Severity] the level at which to log
78
+ def find_valid_level log_level
79
+ config = ::Contrast::CONFIG.root.agent.logger
80
+ config_level = config&.level&.length&.positive? ? config.level : nil
81
+
82
+ valid_level(config_level || log_level)
83
+ end
84
+
85
+ def valid_level level
86
+ level ||= DEFAULT_LEVEL
87
+ level = level.upcase
88
+ if VALID_LEVELS.include?(level)
89
+ Object.cs__const_get("::Ougai::Logging::Severity::#{ level }")
90
+ else
91
+ DEFAULT_LEVEL
92
+ end
93
+ rescue StandardError
94
+ DEFAULT_LEVEL
95
+ end
96
+
97
+ # Log that the Agent log has changed and include some default information at the start of the log.
98
+ def log_update
99
+ logger.debug('Initialized new contrast agent logger')
100
+ logger.debug_with_time('middleware: log environment') do
101
+ logger.application_environment
102
+ logger.application_configuration
103
+ logger.application_libraries
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/components/logger'
@@ -15,7 +15,7 @@ module Contrast
15
15
  ERROR_MESSAGES = [
16
16
  'The key is not string or does not meet the requirements.',
17
17
  'The key extends the allowed length.',
18
- 'VThe provided value is not the right data type'
18
+ 'The provided value is not the right data type'
19
19
  ].cs__freeze
20
20
  KEY_REGEXP = /[a-zA-Z0-9_-]{1,63}/.cs__freeze
21
21
 
@@ -0,0 +1,87 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ module Contrast
5
+ module Utils
6
+ # helper methods for Contrast::Agent::Middleware
7
+ # including disclaimers, deprecation notices, error handling, setup
8
+ module MiddlewareUtils
9
+ private
10
+
11
+ def setup_agent
12
+ ::Contrast::SETTINGS.reset_state
13
+
14
+ inform_deprecations
15
+ telemetry_disclaimer
16
+
17
+ if ::Contrast::CONFIG.invalid?
18
+ ::Contrast::AGENT.disable!
19
+ logger.error('!!! CONFIG FILE IS INVALID - DISABLING CONTRAST AGENT !!!')
20
+ elsif ::Contrast::AGENT.disabled?
21
+ logger.warn('Contrast disabled by configuration. Continuing without instrumentation.')
22
+ else
23
+ ::Contrast::AGENT.enable!
24
+ end
25
+ end
26
+
27
+ SECURITY_EXCEPTION_MARKER = 'Contrast::SecurityException'
28
+ # We're only going to suppress SecurityExceptions indicating a blocked attack. And, only if the
29
+ # config.agent.ruby.exceptions.capture? is set
30
+ def handle_exception exception
31
+ if security_exception?(exception)
32
+ exception_control = ::Contrast::AGENT.exception_control
33
+ raise exception unless exception_control[:enable]
34
+
35
+ [exception_control[:status], {}, [exception_control[:message]]]
36
+ else
37
+ logger.debug('Re-throwing original error', exception)
38
+ raise exception
39
+ end
40
+ end
41
+
42
+ # Is the given exception one raised by our Protect code?
43
+ #
44
+ # @param exception [Exception]
45
+ # @return [Boolean]
46
+ def security_exception? exception
47
+ exception.is_a?(Contrast::SecurityException) || exception.message&.include?(SECURITY_EXCEPTION_MARKER)
48
+ end
49
+
50
+ # As we deprecate support to prepare to remove dead code, we need to inform our users still relying on the now
51
+ # deprecated and soon to be removed functionality. This method handles doing that by leveraging the standard
52
+ # Kernel#warn approach
53
+ def inform_deprecations
54
+ # Ruby 2.5 is currently in security maintenance, meaning int is only receiving updates for security issues. It
55
+ # will move to eol on 31 March 2021. As such, we can remove support for it in Q3. We'll begin the deprecation
56
+ # warnings now so that customers have time to reach out if they'll be impacted.
57
+ # TODO: RUBY-715 remove this part of the method, leaving it empty if there are no other deprecations, when we
58
+ # drop 2.5 support.
59
+ return unless RUBY_VERSION < '2.6.0'
60
+
61
+ Kernel.warn('[Contrast Security] [DEPRECATION] Support for Ruby 2.5 will be removed in April 2021. '\
62
+ 'Please contact Customer Support prior if you require continued support.')
63
+ end
64
+
65
+ # Displays Telemetry disclaimer if Telemetry is enabled.
66
+ # if .telemetry file doesn't exist we create one and then show the disclaimer.
67
+ # if the file already exists we do nothing.
68
+ def telemetry_disclaimer
69
+ return unless Contrast::Agent::Telemetry.enabled?
70
+ return unless Contrast::Utils::Telemetry.create_telemetry_file
71
+
72
+ logger.info Contrast::Utils::Telemetry.disclaimer
73
+ $stdout.print Contrast::Utils::Telemetry.disclaimer
74
+ true
75
+ end
76
+
77
+ def application_code env
78
+ logger.trace_with_time('application') do
79
+ app.call(env)
80
+ end
81
+ rescue Contrast::SecurityException => e
82
+ logger.trace('Security Exception raised during application lifecycle to prevent an attack', e)
83
+ raise e
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,165 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'net/http'
5
+ require 'contrast/components/logger'
6
+ require 'contrast/utils/object_share'
7
+ require 'socket'
8
+
9
+ module Contrast
10
+ module Utils
11
+ # This module creates a Net::HTTP client base to be used by different services
12
+ # All HTTP clients reporting to Telemetry or TS should inherit from this
13
+ class NetHttpBase
14
+ include Contrast::Components::Logger::InstanceMethods
15
+ # This method initializes the Net::HTTP client we'll need. it will validate
16
+ # the connection and make the first request. If connection is valid and response
17
+ # is available then the open connection is returned.
18
+ #
19
+ # @param service_name [String] Name of service used in logging messages
20
+ # @param url [String]
21
+ # @param use_proxy [Boolean] flag used to indicate proxy connections [default = false]
22
+ # @param use_custom_cert [Boolean] flag used to indicate whether the client is to use
23
+ # self signed certificates provided by config [default = false]
24
+ # @return [Net::HTTP, nil] Return open connection or nil
25
+ def initialize_connection service_name, url, use_proxy = false, use_custom_cert = false
26
+ return unless url
27
+
28
+ addr = URI(url)
29
+ # the proxy is enabled only if there is provided url even if the enable is set to true
30
+ return if addr.host.nil? || addr.port.nil?
31
+ return if addr.scheme != 'https' && !addr.host.to_s.include?('localhost') # TODO: RUBY-99999 allow http w/ localhost # rubocop:disable Layout/LineLength
32
+
33
+ proxy_addr = URI(Contrast::API.proxy_url) if proxy_enabled?
34
+ net_http_client = initialize_client addr, proxy_addr, use_proxy, use_custom_cert
35
+ return if net_http_client.nil?
36
+
37
+ net_http_client.start
38
+ return unless net_http_client.started?
39
+
40
+ logger.debug("Starting #{ service_name } connection test")
41
+ return unless connection_verified? net_http_client
42
+
43
+ logger.debug('Client verified', service: service_name, url: url)
44
+ net_http_client
45
+ rescue StandardError => e
46
+ logger.error('Connection failed', e, service: service_name, url: url)
47
+ nil
48
+ end
49
+
50
+ # Validates connection with assigned domain.
51
+ # If connection is running, SSL certificate of the endpoint is valid, Ip address is resolvable
52
+ # and response is received without peer's reset or refuse of connection,
53
+ # then validation returns true. Error handling is in place so that the work of the agent will continue as
54
+ # normal without Telemetry.
55
+ #
56
+ # @param client [Net::HTTP]
57
+ # @return [Boolean] true | false
58
+ def connection_verified? client
59
+ return @_connection_verified unless @_connection_verified.nil?
60
+ return false if client.nil?
61
+
62
+ # Before RUBY 2.7 there is no #ipaddr
63
+ ipaddr = if RUBY_VERSION < '2.7.0'
64
+ socket = TCPSocket.open(client.address, client.port)
65
+ ipaddr = socket.peeraddr[3]
66
+ socket.close
67
+ ipaddr
68
+ else
69
+ client.ipaddr
70
+ end
71
+ response = client.request(Net::HTTP::Get.new(client.address))
72
+ verify_cert = client.address.to_s.include?('localhost') ||
73
+ OpenSSL::SSL.verify_certificate_identity(client.peer_cert, client.address)
74
+ resolved = resolved? client.address, ipaddr
75
+ @_connection_verified = if resolved && response && verify_cert
76
+ true
77
+ else
78
+ false
79
+ end
80
+ rescue OpenSSL::SSL::SSLError, Resolv::ResolvError, Errno::ECONNRESET, Errno::ECONNREFUSED,
81
+ Errno::ETIMEDOUT, Errno::ESHUTDOWN, Errno::EHOSTDOWN, Errno::EHOSTUNREACH, Errno::EISCONN,
82
+ Errno::ECONNABORTED, Errno::ENETRESET, Errno::ENETUNREACH => e
83
+
84
+ logger.warn("#{ service_name } connection failed", e.message)
85
+ false
86
+ end
87
+
88
+ private
89
+
90
+ # Resolves the address of the assigned domain to array of corresponding IPs (if more than one)
91
+ # and runs a matcher to see if current connection IP is in the list.
92
+ # This is called within #verify_connection, if called on it's own there will be no
93
+ # error handling.
94
+ #
95
+ # @param address [String] Human friendly address of assigned domain
96
+ # @param ipaddr [String] Machine friendly IP address of the assigned domain
97
+ # @return[Boolean] true if both addresses are resolved | false if one of the addresses
98
+ # is non-resolvable
99
+ def resolved? address, ipaddr
100
+ return @_resolved unless @_resolved.nil?
101
+
102
+ @_resolved = if (addresses = Resolv.getaddresses address)
103
+ addresses.any? { |addr| addr.include?(ipaddr) }
104
+ else
105
+ false
106
+ end
107
+ end
108
+
109
+ # if the configuration for the use of self-signed certificates is enabled
110
+ # and required for this client then assign the files and keys to the client
111
+ #
112
+ # @param client [Net::HTTP]
113
+ def assign_cert client
114
+ if Contrast::API.certification_ca_file
115
+ client.ca_file = OpenSSL::X509::Certificate.new(File.read(Contrast::API.certification_ca_file)).to_s
116
+ elsif Contrast::API.certification_cert_file
117
+ client.cert = OpenSSL::X509::Certificate.new(File.read(Contrast::API.certification_cert_file)).to_s
118
+ elsif Contrast::API.certification_key_file
119
+ client.key = OpenSSL::PKey::RSA.new(File.read(Contrast::API.certification_key_file)).to_s
120
+ end
121
+ rescue Errno::ENOENT => e
122
+ logger.error('Custom certificates failed', e.message)
123
+ end
124
+
125
+ # sets default setting for client validation of certificates and
126
+ # timeout options
127
+ #
128
+ # @param addr [URI::Generic] uri of assigned domain
129
+ # @param proxy_addr [URI::Generic | nil] uri of proxy
130
+ # @param use_proxy [Boolean] flag used to indicate proxy connections [default = false]
131
+ # @param use_custom_cert [Boolean] flag used to indicate whether the client is to use
132
+ # self signed certificates provided by config [default = false]
133
+ # @return [Net::HTTP]
134
+ def initialize_client addr, proxy_addr, use_proxy, use_custom_cert
135
+ initialize_client = if proxy_enabled? && use_proxy
136
+ Net::HTTP.new(addr.host, nil, proxy_addr&.host, proxy_addr&.port)
137
+ else
138
+ Net::HTTP.new(addr.host, addr.port)
139
+ end
140
+ return initialize_client if addr.host.to_s.include?('localhost') # TODO: RUBY-99999 allow http w/ localhost
141
+
142
+ assign_cert(initialize_client) if use_custom_cert && Contrast::API.certification_enabled?
143
+ initialize_client.use_ssl = true
144
+ initialize_client.verify_mode = OpenSSL::SSL::VERIFY_PEER
145
+ initialize_client.verify_depth = 5
146
+ # open connection timeout in ms
147
+ # if connection reaches timeout this will produce Net::OpenTimeout error
148
+ initialize_client.open_timeout = 10
149
+ # if we can't read the response or a chunk within time this will cause a
150
+ # Net::ReadTimeout error when the request is made
151
+ initialize_client.read_timeout = 10
152
+ initialize_client
153
+ end
154
+
155
+ # Check if proxy is enabled
156
+ #
157
+ # @return @_proxy_enabled [Boolean] True if proxy is enabled and url is present else false
158
+ def proxy_enabled?
159
+ return @_proxy_enabled unless @_proxy_enabled.nil?
160
+
161
+ @_proxy_enabled = Contrast::API.proxy_enabled? && !Contrast::API.proxy_url.nil?
162
+ end
163
+ end
164
+ end
165
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # rubocop:disable Security/Object/Freeze
@@ -30,6 +30,7 @@ module Contrast
30
30
  SEMICOLON = ';'
31
31
  SINGLE_QUOTE = '\''
32
32
  SLASH = '/'
33
+ SPACE = ' '
33
34
  UNDERSCORE = '_'
34
35
  DOUBLE_UNDERSCORE = '__'
35
36
  AT = '@'
@@ -46,8 +47,6 @@ module Contrast
46
47
  CACHE = 'cache'
47
48
 
48
49
  CONTRAST_PATCHED_METHOD_START = 'cs__patched_'
49
- CONTRAST_MODULE_START = 'Contrast::'
50
- ANONYMOUS_CLASS_MARKER = '#<'
51
50
  DOUBLE_COLON = '::'
52
51
 
53
52
  EMPTY_ARRAY = [].freeze
@@ -65,9 +64,6 @@ module Contrast
65
64
  TRUE = 'true'
66
65
  FALSE = 'false'
67
66
 
68
- CLASS = 'Class'
69
- MODULE = 'Module'
70
-
71
67
  OBJECT_KEY = 'O'
72
68
  RETURN_KEY = 'R'
73
69
  UNKNOWN = 'unknown'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/components/scope'
@@ -36,11 +36,14 @@ module Contrast
36
36
  # Check current OS type
37
37
  # returns true if check is correct or false if not
38
38
  def windows?
39
- (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
39
+ return @_windows unless @_windows.nil?
40
+
41
+ @_windows = !(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil?
40
42
  end
41
43
 
42
44
  def mac?
43
- RUBY_PLATFORM.include? 'darwin'
45
+ @_mac = RUBY_PLATFORM.include? 'darwin' if @_mac.nil?
46
+ @_mac
44
47
  end
45
48
 
46
49
  def unix?
@@ -48,11 +51,12 @@ module Contrast
48
51
  end
49
52
 
50
53
  def linux?
51
- unix? and !mac?
54
+ (unix? and !mac?)
52
55
  end
53
56
 
54
57
  def jruby?
55
- RUBY_ENGINE == 'jruby'
58
+ @_jruby = RUBY_ENGINE == 'jruby' if @_jruby.nil?
59
+ @_jruby
56
60
  end
57
61
  end
58
62
  end