contrast-agent 3.12.2 → 3.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (306) 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 +18 -16
  17. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
  18. data/ext/cs__assess_module/cs__assess_module.c +6 -6
  19. data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
  20. data/ext/cs__assess_string/cs__assess_string.c +31 -16
  21. data/ext/cs__assess_string/cs__assess_string.h +6 -1
  22. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -7
  23. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +3 -7
  24. data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
  25. data/ext/cs__common/cs__common.c +63 -30
  26. data/ext/cs__common/cs__common.h +19 -21
  27. data/ext/cs__common/extconf.rb +0 -14
  28. data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
  29. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
  30. data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
  31. data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
  32. data/ext/extconf_common.rb +0 -28
  33. data/lib/contrast-agent.rb +1 -1
  34. data/lib/contrast.rb +15 -23
  35. data/lib/contrast/agent.rb +51 -39
  36. data/lib/contrast/agent/assess.rb +12 -12
  37. data/lib/contrast/agent/assess/contrast_event.rb +40 -185
  38. data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
  39. data/lib/contrast/agent/assess/events/source_event.rb +5 -9
  40. data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
  41. data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
  42. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +2 -2
  43. data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
  44. data/lib/contrast/agent/assess/policy/policy.rb +9 -11
  45. data/lib/contrast/agent/assess/policy/policy_node.rb +5 -99
  46. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -3
  47. data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
  48. data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -45
  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/append.rb +8 -5
  52. data/lib/contrast/agent/assess/policy/propagator/base.rb +2 -2
  53. data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
  54. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  55. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
  56. data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -7
  57. data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
  58. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +18 -9
  59. data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
  60. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
  61. data/lib/contrast/agent/assess/policy/propagator/remove.rb +14 -15
  62. data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
  63. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
  64. data/lib/contrast/agent/assess/policy/propagator/select.rb +19 -11
  65. data/lib/contrast/agent/assess/policy/propagator/splat.rb +14 -8
  66. data/lib/contrast/agent/assess/policy/propagator/split.rb +19 -13
  67. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +36 -26
  68. data/lib/contrast/agent/assess/policy/propagator/trim.rb +17 -15
  69. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
  70. data/lib/contrast/agent/assess/policy/source_method.rb +90 -73
  71. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  72. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  73. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -11
  74. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
  75. data/lib/contrast/agent/assess/policy/trigger_method.rb +41 -26
  76. data/lib/contrast/agent/assess/policy/trigger_node.rb +30 -17
  77. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
  78. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
  79. data/lib/contrast/agent/assess/properties.rb +15 -383
  80. data/lib/contrast/agent/assess/property/evented.rb +78 -0
  81. data/lib/contrast/agent/assess/property/tagged.rb +339 -0
  82. data/lib/contrast/agent/assess/property/updated.rb +136 -0
  83. data/lib/contrast/agent/assess/rule.rb +2 -2
  84. data/lib/contrast/agent/assess/rule/base.rb +3 -4
  85. data/lib/contrast/agent/assess/rule/provider.rb +3 -3
  86. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +1 -1
  87. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -22
  88. data/lib/contrast/agent/assess/tag.rb +27 -12
  89. data/lib/contrast/agent/assess/tracker.rb +66 -0
  90. data/lib/contrast/agent/at_exit_hook.rb +4 -2
  91. data/lib/contrast/agent/class_reopener.rb +14 -11
  92. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  93. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  94. data/lib/contrast/agent/disable_reaction.rb +1 -1
  95. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  96. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -3
  97. data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
  98. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  99. data/lib/contrast/agent/middleware.rb +36 -48
  100. data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
  101. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -5
  102. data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
  103. data/lib/contrast/agent/patching/policy/patch.rb +16 -16
  104. data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
  105. data/lib/contrast/agent/patching/policy/policy.rb +10 -13
  106. data/lib/contrast/agent/patching/policy/policy_node.rb +3 -3
  107. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
  108. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -3
  109. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  110. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  111. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
  112. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  113. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +3 -3
  114. data/lib/contrast/agent/protect/policy/policy.rb +8 -8
  115. data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -3
  116. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  117. data/lib/contrast/agent/protect/rule.rb +18 -18
  118. data/lib/contrast/agent/protect/rule/base.rb +21 -32
  119. data/lib/contrast/agent/protect/rule/base_service.rb +2 -2
  120. data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
  121. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  122. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +3 -8
  123. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  124. data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
  125. data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
  126. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  127. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  128. data/lib/contrast/agent/protect/rule/xxe.rb +4 -5
  129. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
  130. data/lib/contrast/agent/railtie.rb +1 -1
  131. data/lib/contrast/agent/reaction_processor.rb +5 -5
  132. data/lib/contrast/agent/request.rb +103 -340
  133. data/lib/contrast/agent/request_context.rb +25 -21
  134. data/lib/contrast/agent/request_handler.rb +1 -1
  135. data/lib/contrast/agent/response.rb +25 -26
  136. data/lib/contrast/agent/rewriter.rb +6 -9
  137. data/lib/contrast/agent/scope.rb +1 -1
  138. data/lib/contrast/agent/service_heartbeat.rb +8 -10
  139. data/lib/contrast/agent/static_analysis.rb +4 -4
  140. data/lib/contrast/agent/thread.rb +1 -1
  141. data/lib/contrast/agent/thread_watcher.rb +49 -0
  142. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  143. data/lib/contrast/agent/version.rb +1 -1
  144. data/lib/contrast/agent/worker_thread.rb +24 -0
  145. data/lib/contrast/api.rb +4 -6
  146. data/lib/contrast/api/communication.rb +20 -0
  147. data/lib/contrast/api/communication/connection_status.rb +41 -0
  148. data/lib/contrast/api/communication/messaging_queue.rb +76 -0
  149. data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +10 -19
  150. data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
  151. data/lib/contrast/api/communication/socket.rb +45 -0
  152. data/lib/contrast/api/communication/socket_client.rb +76 -0
  153. data/lib/contrast/api/communication/speedracer.rb +111 -0
  154. data/lib/contrast/api/communication/tcp_socket.rb +31 -0
  155. data/lib/contrast/api/communication/unix_socket.rb +27 -0
  156. data/lib/contrast/api/decorators.rb +14 -4
  157. data/lib/contrast/api/decorators/address.rb +61 -0
  158. data/lib/contrast/api/decorators/application_settings.rb +10 -5
  159. data/lib/contrast/api/decorators/application_update.rb +7 -17
  160. data/lib/contrast/api/decorators/http_request.rb +140 -0
  161. data/lib/contrast/api/decorators/input_analysis.rb +3 -2
  162. data/lib/contrast/api/decorators/message.rb +76 -0
  163. data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
  164. data/lib/contrast/api/decorators/route_coverage.rb +58 -0
  165. data/lib/contrast/api/decorators/server_features.rb +3 -2
  166. data/lib/contrast/api/decorators/trace_event.rb +100 -0
  167. data/lib/contrast/api/decorators/trace_event_object.rb +58 -0
  168. data/lib/contrast/api/decorators/trace_event_signature.rb +47 -0
  169. data/lib/contrast/api/decorators/trace_taint_range.rb +52 -0
  170. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
  171. data/lib/contrast/api/decorators/user_input.rb +40 -0
  172. data/lib/contrast/common_agent_configuration.rb +2 -2
  173. data/lib/contrast/components/agent.rb +2 -2
  174. data/lib/contrast/components/app_context.rb +12 -17
  175. data/lib/contrast/components/config.rb +8 -23
  176. data/lib/contrast/components/contrast_service.rb +3 -3
  177. data/lib/contrast/components/interface.rb +16 -16
  178. data/lib/contrast/components/logger.rb +1 -1
  179. data/lib/contrast/components/scope.rb +3 -3
  180. data/lib/contrast/components/settings.rb +0 -6
  181. data/lib/contrast/config.rb +18 -18
  182. data/lib/contrast/config/application_configuration.rb +5 -2
  183. data/lib/contrast/config/base_configuration.rb +2 -2
  184. data/lib/contrast/config/protect_rule_configuration.rb +1 -1
  185. data/lib/contrast/config/service_configuration.rb +8 -2
  186. data/lib/contrast/configuration.rb +93 -52
  187. data/lib/contrast/extension/assess.rb +21 -23
  188. data/lib/contrast/extension/assess/array.rb +12 -9
  189. data/lib/contrast/extension/assess/erb.rb +6 -3
  190. data/lib/contrast/extension/assess/eval_trigger.rb +3 -3
  191. data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
  192. data/lib/contrast/extension/assess/fiber.rb +12 -12
  193. data/lib/contrast/extension/assess/hash.rb +5 -4
  194. data/lib/contrast/extension/assess/kernel.rb +19 -11
  195. data/lib/contrast/extension/assess/marshal.rb +63 -0
  196. data/lib/contrast/extension/assess/regexp.rb +8 -7
  197. data/lib/contrast/extension/assess/string.rb +13 -15
  198. data/lib/contrast/extension/inventory.rb +4 -5
  199. data/lib/contrast/extension/kernel.rb +1 -1
  200. data/lib/contrast/extension/module.rb +1 -1
  201. data/lib/contrast/extension/protect.rb +3 -3
  202. data/lib/contrast/extension/protect/kernel.rb +2 -2
  203. data/lib/contrast/extension/protect/psych.rb +2 -2
  204. data/lib/contrast/framework/base_support.rb +0 -23
  205. data/lib/contrast/framework/manager.rb +7 -17
  206. data/lib/contrast/framework/rack/patch/session_cookie.rb +13 -19
  207. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  208. data/lib/contrast/framework/rack/support.rb +2 -2
  209. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -3
  210. data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -13
  211. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  212. data/lib/contrast/framework/rails/patch/support.rb +3 -3
  213. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +2 -2
  214. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +2 -2
  215. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -2
  216. data/lib/contrast/framework/rails/support.rb +58 -37
  217. data/lib/contrast/framework/sinatra/patch/base.rb +2 -2
  218. data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
  219. data/lib/contrast/framework/sinatra/support.rb +13 -24
  220. data/lib/contrast/funchook/funchook.rb +45 -0
  221. data/lib/contrast/logger/application.rb +13 -5
  222. data/lib/contrast/logger/format.rb +64 -0
  223. data/lib/contrast/logger/log.rb +17 -9
  224. data/lib/contrast/logger/request.rb +30 -0
  225. data/lib/contrast/tasks/config.rb +1 -1
  226. data/lib/contrast/tasks/service.rb +2 -2
  227. data/lib/contrast/utils/assess/sampling_util.rb +2 -2
  228. data/lib/contrast/utils/assess/tracking_util.rb +89 -19
  229. data/lib/contrast/utils/boolean_util.rb +1 -1
  230. data/lib/contrast/utils/class_util.rb +2 -2
  231. data/lib/contrast/utils/duck_utils.rb +0 -10
  232. data/lib/contrast/utils/env_configuration_item.rb +2 -1
  233. data/lib/contrast/utils/gemfile_reader.rb +5 -5
  234. data/lib/contrast/utils/hash_digest.rb +13 -3
  235. data/lib/contrast/utils/heap_dump_util.rb +2 -2
  236. data/lib/contrast/utils/invalid_configuration_util.rb +21 -35
  237. data/lib/contrast/utils/inventory_util.rb +6 -11
  238. data/lib/contrast/utils/io_util.rb +1 -1
  239. data/lib/contrast/utils/object_share.rb +0 -1
  240. data/lib/contrast/utils/os.rb +16 -4
  241. data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
  242. data/lib/contrast/utils/sha256_builder.rb +2 -2
  243. data/lib/contrast/utils/stack_trace_utils.rb +2 -3
  244. data/lib/contrast/utils/string_utils.rb +11 -6
  245. data/lib/contrast/utils/tag_util.rb +1 -1
  246. data/lib/contrast/utils/thread_tracker.rb +1 -14
  247. data/lib/contrast/utils/timer.rb +1 -17
  248. data/resources/assess/policy.json +0 -10
  249. data/resources/deadzone/policy.json +5 -0
  250. data/ruby-agent.gemspec +24 -23
  251. data/service_executables/VERSION +1 -1
  252. data/service_executables/linux/contrast-service +0 -0
  253. data/service_executables/mac/contrast-service +0 -0
  254. metadata +92 -92
  255. data/funchook/Makefile +0 -29
  256. data/funchook/autom4te.cache/output.0 +0 -4964
  257. data/funchook/autom4te.cache/requests +0 -77
  258. data/funchook/autom4te.cache/traces.0 +0 -361
  259. data/funchook/config.log +0 -651
  260. data/funchook/config.status +0 -1015
  261. data/funchook/configure +0 -4964
  262. data/funchook/src/Makefile +0 -70
  263. data/funchook/src/config.h +0 -101
  264. data/funchook/src/config.h.in +0 -100
  265. data/funchook/src/decoder.o +0 -0
  266. data/funchook/src/distorm.o +0 -0
  267. data/funchook/src/funchook.o +0 -0
  268. data/funchook/src/funchook_io.o +0 -0
  269. data/funchook/src/funchook_syscall.o +0 -0
  270. data/funchook/src/funchook_unix.o +0 -0
  271. data/funchook/src/funchook_x86.o +0 -0
  272. data/funchook/src/instructions.o +0 -0
  273. data/funchook/src/insts.o +0 -0
  274. data/funchook/src/libfunchook.dylib +0 -0
  275. data/funchook/src/mnemonics.o +0 -0
  276. data/funchook/src/operands.o +0 -0
  277. data/funchook/src/os_func.o +0 -0
  278. data/funchook/src/os_func_unix.o +0 -0
  279. data/funchook/src/prefix.o +0 -0
  280. data/funchook/src/printf_base.o +0 -0
  281. data/funchook/src/textdefs.o +0 -0
  282. data/funchook/src/wstring.o +0 -0
  283. data/funchook/test/Makefile +0 -43
  284. data/funchook/test/funchook_test +0 -0
  285. data/funchook/test/libfunchook_test.so +0 -0
  286. data/funchook/test/libfunchook_test.so.dSYM/Contents/Info.plist +0 -20
  287. data/funchook/test/libfunchook_test.so.dSYM/Contents/Resources/DWARF/libfunchook_test.so +0 -0
  288. data/funchook/test/test_main.o +0 -0
  289. data/funchook/test/x86_64_test.o +0 -0
  290. data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
  291. data/lib/contrast/agent/assess/insulator.rb +0 -49
  292. data/lib/contrast/agent/require_state.rb +0 -61
  293. data/lib/contrast/agent/socket_client.rb +0 -134
  294. data/lib/contrast/api/connection_status.rb +0 -49
  295. data/lib/contrast/api/socket.rb +0 -43
  296. data/lib/contrast/api/speedracer.rb +0 -188
  297. data/lib/contrast/api/tcp_socket.rb +0 -29
  298. data/lib/contrast/api/unix_socket.rb +0 -25
  299. data/lib/contrast/extension/assess/assess_extension.rb +0 -148
  300. data/lib/contrast/framework/sinatra/application_helper.rb +0 -51
  301. data/lib/contrast/framework/view_technologies_descriptor.rb +0 -21
  302. data/lib/contrast/internal_exception.rb +0 -8
  303. data/lib/contrast/utils/cache.rb +0 -58
  304. data/lib/contrast/utils/freeze_util.rb +0 -32
  305. data/lib/contrast/utils/service_sender_util.rb +0 -167
  306. data/lib/contrast/utils/sinatra_helper.rb +0 -49
@@ -1,5 +1,5 @@
1
- #include <ruby.h>
2
1
  #include "../cs__common/cs__common.h"
2
+ #include <ruby.h>
3
3
 
4
4
  /* Calls to Contrast modules */
5
5
  /* Contrast::Agent::Patching::Policy::PatchStatus */
@@ -140,8 +140,7 @@ VALUE contrast_call_super(const VALUE *args);
140
140
  * instance (specifically for frozen sources)
141
141
  */
142
142
  VALUE contrast_patch_dispatch(const int argc, const VALUE *argv,
143
- const patch_impl impl,
144
- const VALUE object);
143
+ const patch_impl impl, const VALUE object);
145
144
 
146
145
  VALUE contrast_alias_instance_patch(const int argc, const VALUE *argv,
147
146
  const VALUE object);
@@ -149,7 +148,6 @@ VALUE contrast_alias_instance_patch(const int argc, const VALUE *argv,
149
148
  VALUE contrast_alias_singleton_patch(const int argc, const VALUE *argv,
150
149
  const VALUE object);
151
150
 
152
-
153
151
  VALUE contrast_prepend_patch(const int argc, const VALUE *argv,
154
152
  const VALUE object);
155
153
 
@@ -169,12 +167,12 @@ VALUE contrast_prepend_patch(const int argc, const VALUE *argv,
169
167
  * - prepending Foo with Foo::ContrastPrepend
170
168
  *
171
169
  * originalModule - Module; the actual Module being prepended
172
- * methodPolicy - :MethodPolicy; the method policy that apply to the method being redefined
170
+ * methodPolicy - :MethodPolicy; the method policy that apply to the method
171
+ * being redefined
173
172
  *
174
173
  * return - Boolean; if the prepend occurred or not
175
174
  */
176
- VALUE contrast_patch_prepend(const VALUE self,
177
- const VALUE originalModule,
175
+ VALUE contrast_patch_prepend(const VALUE self, const VALUE originalModule,
178
176
  const VALUE methodPolicy);
179
177
 
180
178
  /*
@@ -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'] = 'true'
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,27 @@ 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/assess/tracker'
12
+ require 'contrast/agent/module_data'
13
+ require 'contrast/agent/rewriter'
14
+ require 'contrast/agent/assess/policy/preshift'
14
15
 
15
- cs__scoped_require 'contrast/utils/prevent_serialization'
16
+ require 'contrast/utils/prevent_serialization'
16
17
 
17
18
  # Rules - generic
18
- cs__scoped_require 'contrast/agent/assess/rule'
19
- cs__scoped_require 'contrast/agent/assess/rule/base'
19
+ require 'contrast/agent/assess/rule'
20
+ require 'contrast/agent/assess/rule/base'
20
21
 
21
22
  # Dynamic Sources
22
- cs__scoped_require 'contrast/agent/assess/policy/dynamic_source_factory'
23
+ require 'contrast/agent/assess/policy/dynamic_source_factory'
23
24
 
24
25
  # Rule: REDOS
25
- cs__scoped_require 'contrast/agent/assess/rule/redos'
26
+ require 'contrast/agent/assess/rule/redos'
26
27
 
27
28
  # 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'
29
+ require 'contrast/agent/assess/properties'
30
+ require 'contrast/agent/assess/tag'
31
+ require 'contrast/agent/assess/events/event_factory'
32
32
  end
33
33
  end
34
34
  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
@@ -51,15 +51,11 @@ module Contrast
51
51
  def safe_dup original
52
52
  return nil unless original
53
53
 
54
- begin
55
- original.dup
56
- rescue StandardError
57
- original
58
- end
54
+ Contrast::Agent::Assess::Tracker.duplicate(original)
59
55
  end
60
56
  end
61
57
 
62
- attr_reader :event_id, :parent_ids
58
+ attr_reader :event_id, :parent_ids, :policy_node, :stack_trace, :time, :thread, :object, :ret, :args
63
59
 
64
60
  # We need this to track the parent id's of events to build up a flow
65
61
  # chart of the finding
@@ -78,7 +74,7 @@ module Contrast
78
74
  @policy_node = policy_node
79
75
  # so long as this event is built in a factory, we know Contrast Code
80
76
  # will be the first three events
81
- @caller = caller(3, 20)
77
+ @stack_trace = caller(3, 20)
82
78
  @time = Contrast::Utils::Timer.now_ms
83
79
  @thread = Thread.current.object_id
84
80
 
@@ -95,13 +91,11 @@ module Contrast
95
91
  value_of_source(source, object, ret, args)
96
92
  end
97
93
  selected = mapped.select do |source|
98
- source &&
99
- Contrast::Utils::DuckUtils.quacks_to?(source, :cs__properties) &&
100
- source.cs__properties.events &&
101
- source.cs__properties.events.last
94
+ source && Contrast::Agent::Assess::Tracker.properties(source)&.events&.last
102
95
  end
103
96
  selected.map do |source|
104
- source.cs__properties.events.last.event_id
97
+ properties = Contrast::Agent::Assess::Tracker.properties(source)
98
+ properties.events.last.event_id
105
99
  end
106
100
  end
107
101
 
@@ -157,6 +151,31 @@ module Contrast
157
151
  end
158
152
  end
159
153
 
154
+ # We have to do a little work to figure out what our TS appropriate
155
+ # target is. To break this down, the logic is as follows:
156
+ # 1) If my policy_node has a target, work on targets. Else, work on sources.
157
+ # Per TS law, each policy_node must have at least a source or a target.
158
+ # The only type of policy_node w/o targets is a Trigger, but that may
159
+ # change.
160
+ # 2) If I have a highlight, it means that I have a P target that is
161
+ # not in integer form (it was a named / keyword type for which I had
162
+ # to find the index). I need to address this so that TS can process
163
+ # it.
164
+ # 3) I'll set the event's source and target to TS values.
165
+ # 4) Return the highlight or the first source/target as the taint
166
+ # target.
167
+ def determine_taint_target event_dtm
168
+ if @policy_node&.targets&.any?
169
+ event_dtm.source = @policy_node.source_string if @policy_node.source_string
170
+ event_dtm.target = @highlight ? "P#{ @highlight }" : @policy_node.target_string
171
+ @highlight || @policy_node.targets[0]
172
+ elsif policy_node&.sources&.any?
173
+ event_dtm.source = @highlight ? "P#{ @highlight }" : @policy_node.source_string
174
+ event_dtm.target = @policy_node.target_string if @policy_node.target_string
175
+ @highlight || @policy_node.sources[0]
176
+ end
177
+ end
178
+
160
179
  def value_of_source source, object, ret, args
161
180
  case source
162
181
  when Contrast::Utils::ObjectShare::OBJECT_KEY
@@ -179,171 +198,7 @@ module Contrast
179
198
 
180
199
  # Convert this event into a DTM that TeamServer can consume
181
200
  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
201
+ Contrast::Api::Dtm::TraceEvent.build(self)
347
202
  end
348
203
  end
349
204
  end