contrast-agent 3.12.1 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (287) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +0 -1
  3. data/.gitignore +1 -1
  4. data/.simplecov +1 -1
  5. data/Rakefile +31 -0
  6. data/exe/contrast_service +1 -7
  7. data/ext/build_funchook.rb +0 -2
  8. data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
  9. data/ext/cs__assess_array/cs__assess_array.c +6 -5
  10. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
  11. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +4 -9
  12. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -1
  13. data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
  14. data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
  15. data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
  16. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +4 -5
  17. data/ext/cs__assess_module/cs__assess_module.c +6 -6
  18. data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
  19. data/ext/cs__assess_string/cs__assess_string.c +20 -4
  20. data/ext/cs__assess_string/cs__assess_string.h +4 -1
  21. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -7
  22. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +3 -7
  23. data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
  24. data/ext/cs__common/cs__common.c +59 -28
  25. data/ext/cs__common/cs__common.h +18 -20
  26. data/ext/cs__common/extconf.rb +0 -14
  27. data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
  28. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
  29. data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
  30. data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
  31. data/ext/extconf_common.rb +0 -28
  32. data/lib/contrast-agent.rb +1 -1
  33. data/lib/contrast.rb +15 -23
  34. data/lib/contrast/agent.rb +51 -39
  35. data/lib/contrast/agent/assess.rb +11 -12
  36. data/lib/contrast/agent/assess/contrast_event.rb +39 -176
  37. data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
  38. data/lib/contrast/agent/assess/events/source_event.rb +5 -9
  39. data/lib/contrast/agent/assess/finalizers/finalize.rb +21 -0
  40. data/lib/contrast/agent/assess/finalizers/freeze.rb +13 -0
  41. data/lib/contrast/agent/assess/finalizers/hash.rb +53 -0
  42. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +2 -2
  43. data/lib/contrast/agent/assess/policy/patcher.rb +5 -5
  44. data/lib/contrast/agent/assess/policy/policy.rb +9 -9
  45. data/lib/contrast/agent/assess/policy/policy_node.rb +5 -99
  46. data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -3
  47. data/lib/contrast/agent/assess/policy/preshift.rb +15 -5
  48. data/lib/contrast/agent/assess/policy/propagation_method.rb +26 -24
  49. data/lib/contrast/agent/assess/policy/propagation_node.rb +6 -2
  50. data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
  51. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  52. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  53. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
  54. data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -4
  55. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +12 -3
  56. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +5 -0
  57. data/lib/contrast/agent/assess/policy/propagator/remove.rb +6 -11
  58. data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -4
  59. data/lib/contrast/agent/assess/policy/propagator/split.rb +5 -5
  60. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +8 -7
  61. data/lib/contrast/agent/assess/policy/propagator/trim.rb +6 -10
  62. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
  63. data/lib/contrast/agent/assess/policy/source_method.rb +6 -16
  64. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  65. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  66. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
  67. data/lib/contrast/agent/assess/policy/trigger_method.rb +7 -15
  68. data/lib/contrast/agent/assess/policy/trigger_node.rb +18 -6
  69. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
  70. data/lib/contrast/agent/assess/properties.rb +13 -383
  71. data/lib/contrast/agent/assess/property/evented.rb +78 -0
  72. data/lib/contrast/agent/assess/property/tagged.rb +339 -0
  73. data/lib/contrast/agent/assess/rule.rb +2 -2
  74. data/lib/contrast/agent/assess/rule/base.rb +3 -4
  75. data/lib/contrast/agent/assess/rule/provider.rb +3 -3
  76. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +1 -1
  77. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -22
  78. data/lib/contrast/agent/assess/tag.rb +27 -12
  79. data/lib/contrast/agent/at_exit_hook.rb +4 -2
  80. data/lib/contrast/agent/class_reopener.rb +7 -6
  81. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  82. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  83. data/lib/contrast/agent/disable_reaction.rb +1 -1
  84. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  85. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -3
  86. data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
  87. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  88. data/lib/contrast/agent/middleware.rb +37 -48
  89. data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
  90. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -5
  91. data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
  92. data/lib/contrast/agent/patching/policy/patch.rb +16 -16
  93. data/lib/contrast/agent/patching/policy/patcher.rb +30 -22
  94. data/lib/contrast/agent/patching/policy/policy.rb +9 -9
  95. data/lib/contrast/agent/patching/policy/policy_node.rb +3 -3
  96. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
  97. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -3
  98. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  99. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  100. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
  101. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  102. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +3 -3
  103. data/lib/contrast/agent/protect/policy/policy.rb +8 -8
  104. data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -3
  105. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  106. data/lib/contrast/agent/protect/rule.rb +18 -18
  107. data/lib/contrast/agent/protect/rule/base.rb +21 -32
  108. data/lib/contrast/agent/protect/rule/base_service.rb +2 -2
  109. data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
  110. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  111. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +3 -8
  112. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  113. data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
  114. data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
  115. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  116. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  117. data/lib/contrast/agent/protect/rule/xxe.rb +4 -5
  118. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
  119. data/lib/contrast/agent/railtie.rb +1 -1
  120. data/lib/contrast/agent/reaction_processor.rb +5 -5
  121. data/lib/contrast/agent/request.rb +103 -340
  122. data/lib/contrast/agent/request_context.rb +25 -21
  123. data/lib/contrast/agent/request_handler.rb +1 -1
  124. data/lib/contrast/agent/response.rb +8 -20
  125. data/lib/contrast/agent/rewriter.rb +5 -6
  126. data/lib/contrast/agent/scope.rb +1 -1
  127. data/lib/contrast/agent/service_heartbeat.rb +8 -10
  128. data/lib/contrast/agent/static_analysis.rb +4 -4
  129. data/lib/contrast/agent/thread.rb +1 -1
  130. data/lib/contrast/agent/thread_watcher.rb +49 -0
  131. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  132. data/lib/contrast/agent/version.rb +1 -1
  133. data/lib/contrast/agent/worker_thread.rb +24 -0
  134. data/lib/contrast/api.rb +4 -6
  135. data/lib/contrast/api/communication.rb +20 -0
  136. data/lib/contrast/api/communication/connection_status.rb +41 -0
  137. data/lib/contrast/api/communication/messaging_queue.rb +79 -0
  138. data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +10 -19
  139. data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
  140. data/lib/contrast/api/communication/socket.rb +45 -0
  141. data/lib/contrast/api/communication/socket_client.rb +76 -0
  142. data/lib/contrast/api/communication/speedracer.rb +111 -0
  143. data/lib/contrast/api/communication/tcp_socket.rb +31 -0
  144. data/lib/contrast/api/communication/unix_socket.rb +27 -0
  145. data/lib/contrast/api/decorators.rb +14 -4
  146. data/lib/contrast/api/decorators/address.rb +61 -0
  147. data/lib/contrast/api/decorators/application_settings.rb +10 -5
  148. data/lib/contrast/api/decorators/application_update.rb +5 -13
  149. data/lib/contrast/api/decorators/http_request.rb +140 -0
  150. data/lib/contrast/api/decorators/input_analysis.rb +3 -2
  151. data/lib/contrast/api/decorators/message.rb +76 -0
  152. data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
  153. data/lib/contrast/api/decorators/route_coverage.rb +58 -0
  154. data/lib/contrast/api/decorators/server_features.rb +3 -2
  155. data/lib/contrast/api/decorators/trace_event.rb +100 -0
  156. data/lib/contrast/api/decorators/trace_event_object.rb +58 -0
  157. data/lib/contrast/api/decorators/trace_event_signature.rb +47 -0
  158. data/lib/contrast/api/decorators/trace_taint_range.rb +52 -0
  159. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
  160. data/lib/contrast/api/decorators/user_input.rb +40 -0
  161. data/lib/contrast/common_agent_configuration.rb +2 -2
  162. data/lib/contrast/components/agent.rb +2 -2
  163. data/lib/contrast/components/app_context.rb +1 -8
  164. data/lib/contrast/components/config.rb +7 -12
  165. data/lib/contrast/components/contrast_service.rb +1 -1
  166. data/lib/contrast/components/interface.rb +16 -16
  167. data/lib/contrast/components/logger.rb +1 -1
  168. data/lib/contrast/components/scope.rb +3 -3
  169. data/lib/contrast/components/settings.rb +0 -6
  170. data/lib/contrast/config.rb +18 -18
  171. data/lib/contrast/config/base_configuration.rb +2 -2
  172. data/lib/contrast/config/protect_rule_configuration.rb +1 -1
  173. data/lib/contrast/configuration.rb +5 -5
  174. data/lib/contrast/extension/assess.rb +22 -22
  175. data/lib/contrast/extension/assess/array.rb +4 -4
  176. data/lib/contrast/extension/assess/assess_extension.rb +28 -31
  177. data/lib/contrast/extension/assess/eval_trigger.rb +3 -3
  178. data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
  179. data/lib/contrast/extension/assess/fiber.rb +3 -3
  180. data/lib/contrast/extension/assess/hash.rb +5 -3
  181. data/lib/contrast/extension/assess/kernel.rb +7 -6
  182. data/lib/contrast/extension/assess/marshal.rb +62 -0
  183. data/lib/contrast/extension/assess/regexp.rb +3 -3
  184. data/lib/contrast/extension/assess/string.rb +6 -6
  185. data/lib/contrast/extension/inventory.rb +4 -5
  186. data/lib/contrast/extension/kernel.rb +1 -1
  187. data/lib/contrast/extension/module.rb +1 -1
  188. data/lib/contrast/extension/protect.rb +3 -3
  189. data/lib/contrast/extension/protect/kernel.rb +2 -2
  190. data/lib/contrast/extension/protect/psych.rb +2 -2
  191. data/lib/contrast/framework/base_support.rb +0 -23
  192. data/lib/contrast/framework/manager.rb +7 -17
  193. data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
  194. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  195. data/lib/contrast/framework/rack/support.rb +2 -2
  196. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -3
  197. data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -6
  198. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  199. data/lib/contrast/framework/rails/patch/support.rb +3 -3
  200. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +2 -2
  201. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +2 -2
  202. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -2
  203. data/lib/contrast/framework/rails/support.rb +56 -37
  204. data/lib/contrast/framework/sinatra/patch/base.rb +2 -2
  205. data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
  206. data/lib/contrast/framework/sinatra/support.rb +13 -24
  207. data/lib/contrast/funchook/funchook.rb +45 -0
  208. data/lib/contrast/logger/application.rb +3 -3
  209. data/lib/contrast/logger/format.rb +64 -0
  210. data/lib/contrast/logger/log.rb +17 -9
  211. data/lib/contrast/logger/request.rb +30 -0
  212. data/lib/contrast/tasks/config.rb +1 -1
  213. data/lib/contrast/tasks/service.rb +2 -2
  214. data/lib/contrast/utils/assess/sampling_util.rb +2 -2
  215. data/lib/contrast/utils/assess/tracking_util.rb +46 -21
  216. data/lib/contrast/utils/boolean_util.rb +1 -1
  217. data/lib/contrast/utils/class_util.rb +5 -3
  218. data/lib/contrast/utils/freeze_util.rb +1 -1
  219. data/lib/contrast/utils/gemfile_reader.rb +5 -5
  220. data/lib/contrast/utils/hash_digest.rb +13 -3
  221. data/lib/contrast/utils/heap_dump_util.rb +2 -2
  222. data/lib/contrast/utils/invalid_configuration_util.rb +2 -18
  223. data/lib/contrast/utils/inventory_util.rb +6 -11
  224. data/lib/contrast/utils/io_util.rb +1 -1
  225. data/lib/contrast/utils/object_share.rb +0 -1
  226. data/lib/contrast/utils/os.rb +16 -4
  227. data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
  228. data/lib/contrast/utils/sha256_builder.rb +2 -2
  229. data/lib/contrast/utils/stack_trace_utils.rb +2 -3
  230. data/lib/contrast/utils/string_utils.rb +1 -1
  231. data/lib/contrast/utils/tag_util.rb +1 -1
  232. data/lib/contrast/utils/thread_tracker.rb +1 -14
  233. data/lib/contrast/utils/timer.rb +1 -17
  234. data/resources/deadzone/policy.json +5 -0
  235. data/ruby-agent.gemspec +9 -9
  236. data/service_executables/VERSION +1 -1
  237. data/service_executables/linux/contrast-service +0 -0
  238. data/service_executables/mac/contrast-service +0 -0
  239. metadata +60 -79
  240. data/funchook/Makefile +0 -29
  241. data/funchook/autom4te.cache/output.0 +0 -4976
  242. data/funchook/autom4te.cache/requests +0 -78
  243. data/funchook/autom4te.cache/traces.0 +0 -364
  244. data/funchook/config.log +0 -490
  245. data/funchook/config.status +0 -1016
  246. data/funchook/configure +0 -4976
  247. data/funchook/src/Makefile +0 -70
  248. data/funchook/src/config.h +0 -101
  249. data/funchook/src/config.h.in +0 -100
  250. data/funchook/src/decoder.o +0 -0
  251. data/funchook/src/distorm.o +0 -0
  252. data/funchook/src/funchook.o +0 -0
  253. data/funchook/src/funchook_io.o +0 -0
  254. data/funchook/src/funchook_syscall.o +0 -0
  255. data/funchook/src/funchook_unix.o +0 -0
  256. data/funchook/src/funchook_x86.o +0 -0
  257. data/funchook/src/instructions.o +0 -0
  258. data/funchook/src/insts.o +0 -0
  259. data/funchook/src/libfunchook.so +0 -0
  260. data/funchook/src/mnemonics.o +0 -0
  261. data/funchook/src/operands.o +0 -0
  262. data/funchook/src/os_func.o +0 -0
  263. data/funchook/src/os_func_unix.o +0 -0
  264. data/funchook/src/prefix.o +0 -0
  265. data/funchook/src/printf_base.o +0 -0
  266. data/funchook/src/textdefs.o +0 -0
  267. data/funchook/src/wstring.o +0 -0
  268. data/funchook/test/Makefile +0 -43
  269. data/funchook/test/funchook_test +0 -0
  270. data/funchook/test/libfunchook_test.so +0 -0
  271. data/funchook/test/test_main.o +0 -0
  272. data/funchook/test/x86_64_test.o +0 -0
  273. data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
  274. data/lib/contrast/agent/assess/insulator.rb +0 -49
  275. data/lib/contrast/agent/require_state.rb +0 -61
  276. data/lib/contrast/agent/socket_client.rb +0 -134
  277. data/lib/contrast/api/connection_status.rb +0 -49
  278. data/lib/contrast/api/socket.rb +0 -43
  279. data/lib/contrast/api/speedracer.rb +0 -188
  280. data/lib/contrast/api/tcp_socket.rb +0 -29
  281. data/lib/contrast/api/unix_socket.rb +0 -25
  282. data/lib/contrast/framework/sinatra/application_helper.rb +0 -51
  283. data/lib/contrast/framework/view_technologies_descriptor.rb +0 -21
  284. data/lib/contrast/internal_exception.rb +0 -8
  285. data/lib/contrast/utils/cache.rb +0 -58
  286. data/lib/contrast/utils/service_sender_util.rb +0 -167
  287. data/lib/contrast/utils/sinatra_helper.rb +0 -49
@@ -10,7 +10,7 @@ static VALUE contrast_protect_fork(const int argc, const VALUE *argv,
10
10
  VALUE ret;
11
11
  if (rb_block_given_p()) {
12
12
  /* We call our hook, but it's a little complicated.
13
- * We wrap the fork block with our own lambda in
13
+ * We wrap the fork block with our own lambda in
14
14
  * order to instrument it. There are no public
15
15
  * methods in the Ruby C API to set the prevailing
16
16
  * block, so we have to use rb_funcall_with_block.
@@ -20,12 +20,14 @@ static VALUE contrast_protect_fork(const int argc, const VALUE *argv,
20
20
  */
21
21
  VALUE wrapper;
22
22
  wrapper =
23
- rb_funcall_with_block(kernel_protect, rb_sym_protect_kernel_wrapper, 0,
24
- NULL, rb_block_proc());
25
- rb_funcall(rb_mKernel, rb_intern("public"), 1, ID2SYM(rb_sym_protect_kernel_fork));
23
+ rb_funcall_with_block(kernel_protect, rb_sym_protect_kernel_wrapper,
24
+ 0, NULL, rb_block_proc());
25
+ rb_funcall(rb_mKernel, rb_intern("public"), 1,
26
+ ID2SYM(rb_sym_protect_kernel_fork));
26
27
  ret = rb_funcall_with_block(self, rb_sym_protect_kernel_fork, argc,
27
28
  argv, wrapper);
28
- rb_funcall(rb_mKernel, rb_intern("private"), 1, ID2SYM(rb_sym_protect_kernel_fork));
29
+ rb_funcall(rb_mKernel, rb_intern("private"), 1,
30
+ ID2SYM(rb_sym_protect_kernel_fork));
29
31
  } else {
30
32
  ret = rb_funcall2(self, rb_sym_protect_kernel_fork, argc, argv);
31
33
  }
@@ -37,12 +39,9 @@ void Init_cs__protect_kernel(void) {
37
39
  kernel_protect = rb_define_module_under(core_protect, "Kernel");
38
40
  rb_sym_protect_kernel_wrapper = rb_intern("build_wrapper");
39
41
 
40
- rb_sym_protect_kernel_fork = contrast_register_patch("Kernel",
41
- "fork",
42
- &contrast_protect_fork);
43
-
44
- rb_sym_protect_kernel_fork = contrast_register_singleton_patch("Kernel",
45
- "fork",
46
- &contrast_protect_fork);
42
+ rb_sym_protect_kernel_fork =
43
+ contrast_register_patch("Kernel", "fork", &contrast_protect_fork);
47
44
 
45
+ rb_sym_protect_kernel_fork = contrast_register_singleton_patch(
46
+ "Kernel", "fork", &contrast_protect_fork);
48
47
  }
@@ -6,7 +6,7 @@ static VALUE kernel_protect;
6
6
  static VALUE rb_sym_protect_kernel_fork;
7
7
  static VALUE rb_sym_protect_kernel_wrapper;
8
8
 
9
- static VALUE
10
- contrast_protect_fork(const int argc, const VALUE *argv, const VALUE self);
9
+ static VALUE contrast_protect_fork(const int argc, const VALUE *argv,
10
+ const VALUE self);
11
11
 
12
12
  void Init_cs__protect_kernel(void);
@@ -18,34 +18,6 @@ def ext_path
18
18
  __dir__
19
19
  end
20
20
 
21
- def rpath_root
22
- if (/darwin/ =~ RUBY_PLATFORM).nil?
23
- '\$${ORIGIN}'
24
- else
25
- '@loader_path'
26
- end
27
- end
28
-
29
- def funchook_rpath!
30
- options = " -Wl,-rpath,#{ rpath_root }/../../shared_libraries"
31
- raise unless try_link('int main() {return 0;}', options)
32
-
33
- $LDFLAGS << options
34
- $LDFLAGS << " -L#{ __dir__ }/../shared_libraries"
35
-
36
- find_header('funchook.h', ext_path)
37
- have_header('funchook.h')
38
-
39
- find_library('funchook', 'funchook_create', '../shared_libraries')
40
- find_library('funchook', 'funchook_install')
41
- find_library('funchook', 'funchook_prepare')
42
- have_library('funchook', 'funchook_create')
43
- have_library('funchook', 'funchook_install')
44
- have_library('funchook', 'funchook_prepare')
45
- end
46
-
47
21
  require_relative './build_funchook'
48
22
 
49
- # default make pathway, here for convenience
50
- funchook_rpath!
51
23
  make!
@@ -5,4 +5,4 @@
5
5
  # want to go through the trouble of renaming to contrast_agent.gem, which we
6
6
  # shouldn't do until we're ready to go to RubyGems
7
7
 
8
- require_relative './contrast' # rubocop:disable Kernel/RequireRelative
8
+ require_relative './contrast'
@@ -1,6 +1,9 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
+ # Used to prevent deprecation warnings from flooding stdout
5
+ ENV['PB_IGNORE_DEPRECATIONS'] = 'truee'
6
+
4
7
  # Top-level namespace for Contrast Security agent
5
8
  module Contrast
6
9
  end
@@ -22,36 +25,25 @@ class Object
22
25
  alias_method :cs__singleton_class, :singleton_class
23
26
  end
24
27
 
25
- require_relative './contrast/agent/require_state' # rubocop:disable Kernel/RequireRelative
26
-
27
- # We have to do this here BEOFRE we require anything b/c we can't use the
28
- # Contrast require methods without it.
29
- module Kernel
30
- def cs__scoped_require path
31
- Contrast::Agent::RequireStates.enter
32
- require(path) # rubocop:disable Kernel/Require
33
- ensure
34
- Contrast::Agent::RequireStates.exit
35
- end
36
- end
37
-
38
28
  # component interface for class creation
39
29
  # config gets built as a consequence of this require
40
- cs__scoped_require 'contrast/components/interface'
30
+ require 'contrast/components/interface'
31
+
32
+ # This needs to be required very early, after component interfaces, and before instrumentation attempts
33
+ require 'contrast/funchook/funchook'
41
34
 
42
35
  # shared configuration support
43
- cs__scoped_require 'contrast/config'
44
- cs__scoped_require 'contrast/configuration'
36
+ require 'contrast/config'
37
+ require 'contrast/configuration'
45
38
 
46
- cs__scoped_require 'contrast/agent/version'
39
+ require 'contrast/agent/version'
47
40
 
48
41
  # errors and exceptions
49
- cs__scoped_require 'contrast/security_exception'
50
- cs__scoped_require 'contrast/internal_exception'
42
+ require 'contrast/security_exception'
51
43
 
52
44
  # shared utils
53
- cs__scoped_require 'contrast/utils/timer'
54
- cs__scoped_require 'contrast/utils/preflight_util'
45
+ require 'contrast/utils/timer'
46
+ require 'contrast/utils/preflight_util'
55
47
 
56
- cs__scoped_require 'contrast/utils/assess/sampling_util'
57
- cs__scoped_require 'contrast/agent'
48
+ require 'contrast/utils/assess/sampling_util'
49
+ require 'contrast/agent'
@@ -1,45 +1,50 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'English'
4
+ require 'English'
5
5
 
6
6
  # This must precede other Contrast C extensions
7
- cs__scoped_require 'cs__common/cs__common'
7
+ require 'cs__common/cs__common'
8
8
  # This must precede any patching we do as we log patches and we shouldn't cause
9
9
  # requires to happen during that process.
10
- cs__scoped_require 'contrast/components/logger'
10
+ require 'contrast/components/logger'
11
11
 
12
12
  # defining instrumentation, this must precede core extensions
13
13
  # because they need to register their patches
14
- cs__scoped_require 'contrast/agent/patching/policy/patcher'
15
- cs__scoped_require 'contrast/agent/patching/policy/patch'
14
+ require 'contrast/agent/patching/policy/patcher'
15
+ require 'contrast/agent/patching/policy/patch'
16
16
 
17
17
  # core extensions
18
- cs__scoped_require 'contrast/extension/assess'
19
- cs__scoped_require 'contrast/extension/delegator'
20
- cs__scoped_require 'contrast/extension/inventory'
21
- cs__scoped_require 'contrast/extension/module'
22
- cs__scoped_require 'contrast/extension/protect'
23
- cs__scoped_require 'contrast/extension/protect/kernel'
18
+ require 'contrast/extension/assess'
19
+ require 'contrast/extension/delegator'
20
+ require 'contrast/extension/inventory'
21
+ require 'contrast/extension/module'
22
+ require 'contrast/extension/protect'
23
+ require 'contrast/extension/protect/kernel'
24
24
 
25
- cs__scoped_require 'contrast/utils/object_share'
26
- cs__scoped_require 'contrast/utils/boolean_util'
27
- cs__scoped_require 'contrast/utils/string_utils'
28
- cs__scoped_require 'contrast/utils/io_util'
29
- cs__scoped_require 'contrast/utils/os'
25
+ require 'contrast/utils/object_share'
26
+ require 'contrast/utils/boolean_util'
27
+ require 'contrast/utils/string_utils'
28
+ require 'contrast/utils/io_util'
29
+ require 'contrast/utils/os'
30
30
 
31
- cs__scoped_require 'contrast/common_agent_configuration'
31
+ require 'contrast/common_agent_configuration'
32
32
 
33
- cs__scoped_require 'contrast/utils/hash_digest'
34
- cs__scoped_require 'contrast/utils/invalid_configuration_util'
33
+ require 'contrast/utils/hash_digest'
34
+ require 'contrast/utils/invalid_configuration_util'
35
35
 
36
36
  # scoping
37
- cs__scoped_require 'contrast/agent/scope'
37
+ require 'contrast/agent/scope'
38
38
 
39
- cs__scoped_require 'contrast/utils/thread_tracker'
39
+ require 'contrast/utils/thread_tracker'
40
40
 
41
41
  # Framework support
42
- cs__scoped_require 'contrast/framework/manager'
42
+ require 'contrast/framework/manager'
43
+
44
+ # Communication to SR
45
+ require 'contrast/api/communication'
46
+
47
+ require 'contrast/agent/thread_watcher'
43
48
 
44
49
  module Contrast
45
50
  # Top namespace of the Agent section. Holds tracking contexts that will be
@@ -51,43 +56,50 @@ module Contrast
51
56
  def self.framework_manager
52
57
  @_framework_manager ||= Contrast::Framework::Manager.new
53
58
  end
59
+
60
+ def self.messaging_queue
61
+ @_messaging_queue ||= Contrast::Api::Communication::MessagingQueue.new
62
+ end
63
+
64
+ def self.thread_watcher
65
+ @_thread_watcher ||= Contrast::Agent::ThreadWatcher.new
66
+ end
54
67
  end
55
68
  end
56
69
 
57
- cs__scoped_require 'contrast/api'
70
+ require 'contrast/api'
58
71
 
59
- cs__scoped_require 'contrast/utils/resource_loader'
60
- cs__scoped_require 'contrast/utils/duck_utils'
61
- cs__scoped_require 'contrast/agent/tracepoint_hook'
62
- cs__scoped_require 'contrast/agent/at_exit_hook'
72
+ require 'contrast/utils/resource_loader'
73
+ require 'contrast/utils/duck_utils'
74
+ require 'contrast/agent/tracepoint_hook'
75
+ require 'contrast/agent/at_exit_hook'
63
76
 
64
77
  # communication with contrast service
65
- cs__scoped_require 'contrast/agent/exclusion_matcher'
66
- cs__scoped_require 'contrast/agent/socket_client'
78
+ require 'contrast/agent/exclusion_matcher'
67
79
 
68
80
  # threads that handle contrast scope
69
- cs__scoped_require 'contrast/agent/thread'
81
+ require 'contrast/agent/thread'
70
82
 
71
83
  # keep track of attacks
72
- cs__scoped_require 'contrast/agent/request_context'
84
+ require 'contrast/agent/request_context'
73
85
 
74
- cs__scoped_require 'contrast/agent/assess'
86
+ require 'contrast/agent/assess'
75
87
 
76
88
  # protect rules
77
- cs__scoped_require 'contrast/agent/protect/rule'
89
+ require 'contrast/agent/protect/rule'
78
90
 
79
- # application libraries and technologies
80
- cs__scoped_require 'contrast/utils/gemfile_reader'
91
+ # application libraries
92
+ require 'contrast/utils/gemfile_reader'
81
93
 
82
94
  # rack event monitoring
83
- cs__scoped_require 'contrast/agent/middleware'
95
+ require 'contrast/agent/middleware'
84
96
 
85
97
  # TODO: RUBY-919
86
98
  # Refactor to use Contrast::Framework::Manager
87
99
  # Contrast::Framework::Manager.before_load_patches!
88
100
  if defined?(::Rails)
89
- cs__scoped_require 'contrast/framework/rails/patch/support'
90
- cs__scoped_require 'contrast/framework/rails/patch/rails_application_configuration'
101
+ require 'contrast/framework/rails/patch/support'
102
+ require 'contrast/framework/rails/patch/rails_application_configuration'
91
103
  Contrast::Framework::Rails::Patch::RailsApplicationConfiguration.instrument
92
- cs__scoped_require 'contrast/agent/railtie' if ::Rails::VERSION::MAJOR.to_i >= 3
104
+ require 'contrast/agent/railtie' if ::Rails::VERSION::MAJOR.to_i >= 3
93
105
  end
@@ -8,27 +8,26 @@ module Contrast
8
8
  # class under this namespace should be required here, providing a single
9
9
  # point of require for this functionality.
10
10
  module Assess
11
- cs__scoped_require 'contrast/agent/module_data'
12
- cs__scoped_require 'contrast/agent/rewriter'
13
- cs__scoped_require 'contrast/agent/assess/policy/preshift'
11
+ require 'contrast/agent/module_data'
12
+ require 'contrast/agent/rewriter'
13
+ require 'contrast/agent/assess/policy/preshift'
14
14
 
15
- cs__scoped_require 'contrast/utils/prevent_serialization'
15
+ require 'contrast/utils/prevent_serialization'
16
16
 
17
17
  # Rules - generic
18
- cs__scoped_require 'contrast/agent/assess/rule'
19
- cs__scoped_require 'contrast/agent/assess/rule/base'
18
+ require 'contrast/agent/assess/rule'
19
+ require 'contrast/agent/assess/rule/base'
20
20
 
21
21
  # Dynamic Sources
22
- cs__scoped_require 'contrast/agent/assess/policy/dynamic_source_factory'
22
+ require 'contrast/agent/assess/policy/dynamic_source_factory'
23
23
 
24
24
  # Rule: REDOS
25
- cs__scoped_require 'contrast/agent/assess/rule/redos'
25
+ require 'contrast/agent/assess/rule/redos'
26
26
 
27
27
  # reporting / tracking
28
- cs__scoped_require 'contrast/agent/assess/insulator'
29
- cs__scoped_require 'contrast/agent/assess/properties'
30
- cs__scoped_require 'contrast/agent/assess/tag'
31
- cs__scoped_require 'contrast/agent/assess/events/event_factory'
28
+ require 'contrast/agent/assess/properties'
29
+ require 'contrast/agent/assess/tag'
30
+ require 'contrast/agent/assess/events/event_factory'
32
31
  end
33
32
  end
34
33
  end
@@ -1,14 +1,14 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/assess/tracking_util'
5
- cs__scoped_require 'contrast/utils/class_util'
6
- cs__scoped_require 'contrast/utils/duck_utils'
7
- cs__scoped_require 'contrast/utils/object_share'
8
- cs__scoped_require 'contrast/utils/prevent_serialization'
9
- cs__scoped_require 'contrast/utils/stack_trace_utils'
10
- cs__scoped_require 'contrast/utils/string_utils'
11
- cs__scoped_require 'contrast/utils/timer'
4
+ require 'contrast/utils/assess/tracking_util'
5
+ require 'contrast/utils/class_util'
6
+ require 'contrast/utils/duck_utils'
7
+ require 'contrast/utils/object_share'
8
+ require 'contrast/utils/prevent_serialization'
9
+ require 'contrast/utils/stack_trace_utils'
10
+ require 'contrast/utils/string_utils'
11
+ require 'contrast/utils/timer'
12
12
 
13
13
  module Contrast
14
14
  module Agent
@@ -52,14 +52,16 @@ module Contrast
52
52
  return nil unless original
53
53
 
54
54
  begin
55
- original.dup
55
+ duplicate = original.dup
56
+ original.cs__transfer_properties(duplicate)
57
+ duplicate
56
58
  rescue StandardError
57
59
  original
58
60
  end
59
61
  end
60
62
  end
61
63
 
62
- attr_reader :event_id, :parent_ids
64
+ attr_reader :event_id, :parent_ids, :policy_node, :stack_trace, :time, :thread, :object, :ret, :args
63
65
 
64
66
  # We need this to track the parent id's of events to build up a flow
65
67
  # chart of the finding
@@ -78,7 +80,7 @@ module Contrast
78
80
  @policy_node = policy_node
79
81
  # so long as this event is built in a factory, we know Contrast Code
80
82
  # will be the first three events
81
- @caller = caller(3, 20)
83
+ @stack_trace = caller(3, 20)
82
84
  @time = Contrast::Utils::Timer.now_ms
83
85
  @thread = Thread.current.object_id
84
86
 
@@ -157,6 +159,31 @@ module Contrast
157
159
  end
158
160
  end
159
161
 
162
+ # We have to do a little work to figure out what our TS appropriate
163
+ # target is. To break this down, the logic is as follows:
164
+ # 1) If my policy_node has a target, work on targets. Else, work on sources.
165
+ # Per TS law, each policy_node must have at least a source or a target.
166
+ # The only type of policy_node w/o targets is a Trigger, but that may
167
+ # change.
168
+ # 2) If I have a highlight, it means that I have a P target that is
169
+ # not in integer form (it was a named / keyword type for which I had
170
+ # to find the index). I need to address this so that TS can process
171
+ # it.
172
+ # 3) I'll set the event's source and target to TS values.
173
+ # 4) Return the highlight or the first source/target as the taint
174
+ # target.
175
+ def determine_taint_target event_dtm
176
+ if @policy_node&.targets&.any?
177
+ event_dtm.source = @policy_node.source_string if @policy_node.source_string
178
+ event_dtm.target = @highlight ? "P#{ @highlight }" : @policy_node.target_string
179
+ @highlight || @policy_node.targets[0]
180
+ elsif policy_node&.sources&.any?
181
+ event_dtm.source = @highlight ? "P#{ @highlight }" : @policy_node.source_string
182
+ event_dtm.target = @policy_node.target_string if @policy_node.target_string
183
+ @highlight || @policy_node.sources[0]
184
+ end
185
+ end
186
+
160
187
  def value_of_source source, object, ret, args
161
188
  case source
162
189
  when Contrast::Utils::ObjectShare::OBJECT_KEY
@@ -179,171 +206,7 @@ module Contrast
179
206
 
180
207
  # Convert this event into a DTM that TeamServer can consume
181
208
  def to_dtm_event
182
- event = Contrast::Api::Dtm::TraceEvent.new
183
-
184
- # Figure out what the target of this event was. It's a little
185
- # annoying for us since P can be named (thanks, Ruby) where
186
- # as for everyone else it is idx based.
187
- taint_target = determine_taint_target(event)
188
-
189
- event.type = @policy_node.node_type
190
- event.action = @policy_node.build_action
191
- event.timestamp_ms = @time.to_i
192
- event.thread = Contrast::Utils::StringUtils.force_utf8(@thread)
193
- truncate_obj = Contrast::Utils::ObjectShare::OBJECT_KEY != taint_target
194
- event.object = build_event_object(@object, truncate_obj)
195
- truncate_ret = Contrast::Utils::ObjectShare::RETURN_KEY != taint_target
196
- event.ret = build_event_object(@ret, truncate_ret)
197
- built_args = build_event_args(taint_target)
198
- built_args.each do |arg|
199
- event.args << arg
200
- end
201
- taint_ranges = find_taint_ranges(@object, @args, @ret, taint_target)
202
- taint_ranges.each do |range|
203
- event.taint_ranges << range
204
- end
205
-
206
- # We delayed doing this as long as possible b/c it's expensive
207
- stack = Contrast::Utils::StackTraceUtils.build_assess_stack_array(@caller)
208
- event.stack += stack
209
-
210
- event.object_id = event_id.to_i
211
- parent_ids&.each do |id|
212
- parent = Contrast::Api::Dtm::ParentObjectId.new
213
- parent.id = id.to_i
214
- event.parent_object_ids << parent
215
- end
216
-
217
- # not to be confused w/ the partial signature
218
- build_complete_signature(event)
219
-
220
- event
221
- end
222
-
223
- # We're not going to build the signature string here, b/c we have all
224
- # the composite pieces of it. Instead, we're going to let TeamServer
225
- # render this for us.
226
- def build_complete_signature event
227
- signature = Contrast::Api::Dtm::TraceEventSignature.new
228
- event.signature = signature
229
- return_type = @ret ? @ret.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
230
- signature.return_type = Contrast::Utils::StringUtils.force_utf8(return_type)
231
- signature.class_name = Contrast::Utils::StringUtils.force_utf8(@policy_node.class_name)
232
- signature.method_name = Contrast::Utils::StringUtils.force_utf8(@policy_node.method_name)
233
- if @args
234
- @args&.each do |arg|
235
- arg_type = arg ? arg.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
236
- signature.arg_types << Contrast::Utils::StringUtils.force_utf8(arg_type)
237
- end
238
- end
239
- signature.constructor = @policy_node.method_name == :new
240
- # if there's a ret, then this method isn't nil. not 100% full proof since you can
241
- # return nil, but this is the best we've got currently.
242
- signature.void_method = @ret.nil?
243
- # 8 is STATIC in Java... we have to placate them for now
244
- # it has been requested that flags be removed since it isn't used
245
- signature.flags = 8 unless @policy_node.instance_method?
246
- end
247
-
248
- # Wrapper around build_event_object for the args array. Handles
249
- # tainting the correct argument.
250
- def build_event_args taint_target
251
- event_args = []
252
- @args.each_index do |idx|
253
- truncate_arg = taint_target != idx
254
- event_arg = build_event_object(@args[idx], truncate_arg)
255
- event_args << event_arg
256
- end
257
- event_args
258
- end
259
-
260
- # Build the event object. We were originally going to include taint on
261
- # each one, but TS doesn't accept / use that, so it is a waste of time.
262
- #
263
- # We'll truncate any object that isn't important to the taint ranges of
264
- # this event, so that we don't murder TeamServer by, for instance,
265
- # hypothetically sending the entire rendered HTML page >_> <_< >_>
266
- ELLIPSIS = '...'
267
- UNTRUNCATED_PORTION_LENGTH = 25
268
- TRUNCATION_LENGTH = (UNTRUNCATED_PORTION_LENGTH * 2) + 3 # ELLIPSIS length
269
- def build_event_object object, truncate
270
- event_object = Contrast::Api::Dtm::TraceEventObject.new
271
- obj_string = Contrast::Utils::StringUtils.force_utf8(object)
272
- if truncate && Contrast::Utils::StringUtils.ret_length(obj_string) > TRUNCATION_LENGTH
273
- tmp = []
274
- tmp << obj_string[0, UNTRUNCATED_PORTION_LENGTH]
275
- tmp << ELLIPSIS
276
- tmp << obj_string[
277
- obj_string.length - UNTRUNCATED_PORTION_LENGTH,
278
- UNTRUNCATED_PORTION_LENGTH]
279
- obj_string = tmp.join
280
- end
281
- event_object.value = Base64.encode64(obj_string)
282
- event_object.tracked = Contrast::Utils::Assess::TrackingUtil.tracked?(object)
283
- event_object
284
- end
285
-
286
- # We have to do a little work to figure out what our TS appropriate
287
- # target is. To break this down, the logic is as follows:
288
- # 1) If my policy_node has a target, work on targets. Else, work on sources.
289
- # Per TS law, each policy_node must have at least a source or a target.
290
- # The only type of policy_node w/o targets is a Trigger, but that may
291
- # change.
292
- # 2) If I have a highlight, it means that I have a P target that is
293
- # not in integer form (it was a named / keyword type for which I had
294
- # to find the index). I need to address this so that TS can process
295
- # it.
296
- # 3) I'll set the event's source and target to TS values.
297
- # 4) Return the highlight or the first source/target as the taint
298
- # target.
299
- def determine_taint_target event
300
- if @policy_node&.targets&.any?
301
- event.source = @policy_node.source_string if @policy_node.source_string
302
- event.target = if @highlight
303
- "P#{ @highlight }"
304
- else
305
- @policy_node.target_string
306
- end
307
- @highlight || @policy_node.targets[0]
308
- elsif @policy_node&.sources&.any?
309
- event.source = if @highlight
310
- "P#{ @highlight }"
311
- else
312
- @policy_node.source_string
313
- end
314
- event.target = @policy_node.target_string if @policy_node.target_string
315
- @highlight || @policy_node.sources[0]
316
- end
317
- end
318
-
319
- # TeamServer only supports one object's taint ranges at a time.
320
- # We'll find the taint ranges for the target and return those
321
- def find_taint_ranges object, args, ret, taint_target
322
- # If there's no taint_target, this isn't a dataflow trace, but a
323
- # trigger one
324
- return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless taint_target
325
-
326
- properties = case taint_target
327
- when Contrast::Utils::ObjectShare::OBJECT_KEY
328
- object.cs__properties
329
- when Contrast::Utils::ObjectShare::RETURN_KEY
330
- ret.cs__properties
331
- else
332
- target = args[taint_target]
333
- if target.is_a?(Hash)
334
- if @policy_node&.targets&.any?
335
- target[@policy_node.targets[0]].cs__properties
336
- else
337
- target[@policy_node.sources[0]].cs__properties
338
- end
339
- else
340
- target.cs__properties
341
- end
342
- end
343
-
344
- return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless properties.tracked?
345
-
346
- properties.tags_to_dtm
209
+ Contrast::Api::Dtm::TraceEvent.build(self)
347
210
  end
348
211
  end
349
212
  end