contrast-agent 5.1.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cs__assess_array/cs__assess_array.c +7 -0
  3. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +19 -5
  4. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  5. data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
  6. data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -5
  7. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
  8. data/ext/cs__assess_module/cs__assess_module.c +7 -7
  9. data/ext/cs__assess_string/cs__assess_string.c +13 -1
  10. data/ext/cs__common/cs__common.c +16 -11
  11. data/ext/cs__common/cs__common.h +1 -0
  12. data/ext/cs__contrast_patch/cs__contrast_patch.c +100 -64
  13. data/ext/cs__contrast_patch/cs__contrast_patch.h +2 -0
  14. data/ext/cs__os_information/cs__os_information.c +13 -10
  15. data/ext/cs__scope/cs__scope.c +796 -0
  16. data/ext/cs__scope/cs__scope.h +88 -0
  17. data/ext/cs__scope/extconf.rb +5 -0
  18. data/lib/contrast/agent/assess/contrast_event.rb +20 -13
  19. data/lib/contrast/agent/assess/contrast_object.rb +4 -1
  20. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -0
  21. data/lib/contrast/agent/assess/policy/policy_node.rb +50 -27
  22. data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
  23. data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
  24. data/lib/contrast/agent/assess/policy/propagation_method.rb +47 -13
  25. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -5
  26. data/lib/contrast/agent/assess/policy/propagator/buffer.rb +118 -0
  27. data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
  28. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +2 -0
  29. data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
  30. data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
  31. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
  32. data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
  33. data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
  34. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  35. data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
  36. data/lib/contrast/agent/assess/policy/trigger_method.rb +6 -1
  37. data/lib/contrast/agent/assess/property/tagged.rb +1 -1
  38. data/lib/contrast/agent/assess/rule/response/{autocomplete_rule.rb → auto_complete_rule.rb} +4 -3
  39. data/lib/contrast/agent/assess/rule/response/base_rule.rb +12 -79
  40. data/lib/contrast/agent/assess/rule/response/body_rule.rb +109 -0
  41. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +157 -0
  42. data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +26 -0
  43. data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +14 -15
  44. data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +5 -25
  45. data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +29 -0
  46. data/lib/contrast/agent/assess/rule/response/header_rule.rb +70 -0
  47. data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +12 -36
  48. data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +2 -1
  49. data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +26 -0
  50. data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +35 -0
  51. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
  52. data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
  53. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  54. data/lib/contrast/agent/middleware.rb +4 -1
  55. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +1 -3
  56. data/lib/contrast/agent/patching/policy/patch.rb +2 -6
  57. data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
  58. data/lib/contrast/agent/patching/policy/policy_node.rb +15 -2
  59. data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
  60. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +147 -0
  61. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -1
  62. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -2
  63. data/lib/contrast/agent/protect/rule/base.rb +61 -2
  64. data/lib/contrast/agent/protect/rule/base_service.rb +12 -1
  65. data/lib/contrast/agent/protect/rule/cmd_injection.rb +15 -0
  66. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
  67. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
  68. data/lib/contrast/agent/protect/rule/deserialization.rb +6 -0
  69. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
  70. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +13 -1
  71. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
  72. data/lib/contrast/agent/protect/rule/no_sqli.rb +28 -0
  73. data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -0
  74. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +88 -0
  75. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +118 -0
  76. data/lib/contrast/agent/protect/rule/sqli.rb +33 -0
  77. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
  78. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
  79. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
  80. data/lib/contrast/agent/protect/rule/xxe.rb +4 -0
  81. data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
  82. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
  83. data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
  84. data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
  85. data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +44 -0
  86. data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +115 -0
  87. data/lib/contrast/agent/reporting/input_analysis/input_type.rb +44 -0
  88. data/lib/contrast/agent/reporting/input_analysis/score_level.rb +21 -0
  89. data/lib/contrast/agent/reporting/masker/masker.rb +246 -0
  90. data/lib/contrast/agent/reporting/masker/masker_utils.rb +58 -0
  91. data/lib/contrast/agent/reporting/report.rb +3 -0
  92. data/lib/contrast/agent/reporting/reporter.rb +31 -12
  93. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +30 -0
  94. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +7 -3
  95. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +40 -0
  96. data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
  97. data/lib/contrast/agent/reporting/reporting_events/finding.rb +69 -36
  98. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +88 -59
  99. data/lib/contrast/agent/reporting/reporting_events/{finding_object.rb → finding_event_object.rb} +24 -20
  100. data/lib/contrast/agent/reporting/reporting_events/finding_event_parent_object.rb +39 -0
  101. data/lib/contrast/agent/reporting/reporting_events/finding_event_property.rb +40 -0
  102. data/lib/contrast/agent/reporting/reporting_events/{finding_signature.rb → finding_event_signature.rb} +29 -24
  103. data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +12 -8
  104. data/lib/contrast/agent/reporting/reporting_events/{finding_stack.rb → finding_event_stack.rb} +23 -19
  105. data/lib/contrast/agent/reporting/reporting_events/{finding_taint_range.rb → finding_event_taint_range.rb} +17 -15
  106. data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +26 -53
  107. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
  108. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +9 -9
  109. data/lib/contrast/agent/reporting/reporting_events/poll.rb +29 -0
  110. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +2 -1
  111. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +6 -4
  112. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
  113. data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +1 -0
  114. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +1 -1
  115. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +10 -3
  116. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +0 -1
  117. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +17 -5
  118. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +54 -45
  119. data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
  120. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +97 -0
  121. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +69 -7
  122. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
  123. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +123 -85
  124. data/lib/contrast/agent/reporting/settings/application_settings.rb +9 -0
  125. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +5 -33
  126. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +1 -1
  127. data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
  128. data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
  129. data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
  130. data/lib/contrast/agent/request_context.rb +7 -2
  131. data/lib/contrast/agent/request_context_extend.rb +85 -21
  132. data/lib/contrast/agent/request_handler.rb +4 -0
  133. data/lib/contrast/agent/scope.rb +102 -107
  134. data/lib/contrast/agent/service_heartbeat.rb +45 -2
  135. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +51 -0
  136. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +36 -0
  137. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +97 -0
  138. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +65 -0
  139. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +47 -0
  140. data/lib/contrast/agent/{metric_telemetry_event.rb → telemetry/events/metric_telemetry_event.rb} +1 -1
  141. data/lib/contrast/agent/{startup_metrics_telemetry_event.rb → telemetry/events/startup_metrics_telemetry_event.rb} +3 -3
  142. data/lib/contrast/agent/{telemetry_event.rb → telemetry/events/telemetry_event.rb} +1 -1
  143. data/lib/contrast/agent/{telemetry.rb → telemetry/telemetry.rb} +32 -19
  144. data/lib/contrast/agent/thread_watcher.rb +1 -1
  145. data/lib/contrast/agent/version.rb +1 -1
  146. data/lib/contrast/agent.rb +3 -0
  147. data/lib/contrast/api/communication/speedracer.rb +1 -1
  148. data/lib/contrast/api/decorators/address.rb +1 -1
  149. data/lib/contrast/api/decorators/bot_blocker.rb +37 -0
  150. data/lib/contrast/api/decorators/ip_denylist.rb +37 -0
  151. data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
  152. data/lib/contrast/api/decorators/response_type.rb +30 -0
  153. data/lib/contrast/api/decorators/user_input.rb +11 -1
  154. data/lib/contrast/api/decorators/virtual_patch.rb +34 -0
  155. data/lib/contrast/api/decorators.rb +1 -0
  156. data/lib/contrast/components/app_context.rb +0 -4
  157. data/lib/contrast/components/assess.rb +14 -0
  158. data/lib/contrast/components/logger.rb +5 -0
  159. data/lib/contrast/components/protect.rb +6 -4
  160. data/lib/contrast/components/sampling.rb +7 -11
  161. data/lib/contrast/components/scope.rb +98 -91
  162. data/lib/contrast/components/settings.rb +106 -8
  163. data/lib/contrast/config/agent_configuration.rb +41 -12
  164. data/lib/contrast/config/api_configuration.rb +37 -12
  165. data/lib/contrast/config/api_proxy_configuration.rb +12 -3
  166. data/lib/contrast/config/application_configuration.rb +38 -14
  167. data/lib/contrast/config/assess_configuration.rb +47 -12
  168. data/lib/contrast/config/assess_rules_configuration.rb +15 -3
  169. data/lib/contrast/config/base_configuration.rb +18 -50
  170. data/lib/contrast/config/certification_configuration.rb +17 -3
  171. data/lib/contrast/config/exception_configuration.rb +14 -3
  172. data/lib/contrast/config/heap_dump_configuration.rb +43 -17
  173. data/lib/contrast/config/inventory_configuration.rb +17 -3
  174. data/lib/contrast/config/logger_configuration.rb +10 -3
  175. data/lib/contrast/config/protect_configuration.rb +17 -7
  176. data/lib/contrast/config/protect_rule_configuration.rb +17 -8
  177. data/lib/contrast/config/protect_rules_configuration.rb +115 -17
  178. data/lib/contrast/config/request_audit_configuration.rb +26 -3
  179. data/lib/contrast/config/root_configuration.rb +52 -12
  180. data/lib/contrast/config/ruby_configuration.rb +60 -22
  181. data/lib/contrast/config/sampling_configuration.rb +19 -9
  182. data/lib/contrast/config/server_configuration.rb +19 -10
  183. data/lib/contrast/config/service_configuration.rb +27 -11
  184. data/lib/contrast/configuration.rb +5 -3
  185. data/lib/contrast/extension/assess/string.rb +20 -1
  186. data/lib/contrast/extension/module.rb +0 -1
  187. data/lib/contrast/framework/manager.rb +2 -2
  188. data/lib/contrast/logger/application.rb +1 -1
  189. data/lib/contrast/logger/cef_log.rb +151 -0
  190. data/lib/contrast/tasks/config.rb +90 -3
  191. data/lib/contrast/utils/assess/object_store.rb +36 -0
  192. data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
  193. data/lib/contrast/utils/class_util.rb +3 -12
  194. data/lib/contrast/utils/hash_digest.rb +14 -6
  195. data/lib/contrast/utils/input_classification.rb +73 -0
  196. data/lib/contrast/utils/log_utils.rb +114 -0
  197. data/lib/contrast/utils/middleware_utils.rb +9 -9
  198. data/lib/contrast/utils/net_http_base.rb +13 -10
  199. data/lib/contrast/utils/object_share.rb +2 -1
  200. data/lib/contrast/utils/os.rb +0 -5
  201. data/lib/contrast/utils/patching/policy/patch_utils.rb +4 -9
  202. data/lib/contrast/utils/response_utils.rb +18 -33
  203. data/lib/contrast/utils/telemetry.rb +1 -1
  204. data/lib/contrast/utils/telemetry_client.rb +1 -1
  205. data/lib/contrast/utils/telemetry_identifier.rb +1 -1
  206. data/lib/contrast.rb +4 -3
  207. data/resources/assess/policy.json +98 -0
  208. data/resources/deadzone/policy.json +0 -86
  209. data/ruby-agent.gemspec +9 -8
  210. data/service_executables/VERSION +1 -1
  211. data/service_executables/linux/contrast-service +0 -0
  212. data/service_executables/mac/contrast-service +0 -0
  213. metadata +103 -38
  214. data/lib/contrast/agent/assess/rule/response/cachecontrol_rule.rb +0 -184
  215. data/lib/contrast/agent/assess/rule/response/clickjacking_rule.rb +0 -66
  216. data/lib/contrast/agent/assess/rule/response/x_content_type_rule.rb +0 -52
  217. data/lib/contrast/agent/assess/rule/response/x_xss_protection_rule.rb +0 -53
  218. data/lib/contrast/extension/kernel.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c756fb0e7fe0433c7507c2cdb7082e635adabea8847c545333d65800225b1e3d
4
- data.tar.gz: c71e1a8d020e3dfe98ea58d844924b0b0a9e1576b5f6899d186abc28e4efb152
3
+ metadata.gz: 47aa135a205e4a74d64b778ae543f892213ca70e47be654032147a8bfe16dc82
4
+ data.tar.gz: 60f0de0e2675578bfb735c4f90303748bdc5e2053f2722dac4907bf84364d2f9
5
5
  SHA512:
6
- metadata.gz: 82a0a252fa7696b2590f8be43fba09e03c6b13371a58a678b31e088e01a244311e0ac9d5b077de5d7970c16bc9a2144504d01a0e037c5e0f0b06d06e8530c57a
7
- data.tar.gz: d9fd4708ab8238a22a2e3187e880a898635739b00f0d2f4f224904325f3b88b28f3470cf37733d5875e97018a02a5bfe10bd7f041219fd842b596e9697bfdbb6
6
+ metadata.gz: fdd2d1209de7366f810cb1d7355700a54cd7d7749d94736213cf96c47b8e5cedad449ec0dc2ab09753c0ecc3d064498d18d1d001edc5d998c6c615c4cd05b571
7
+ data.tar.gz: 888016b33c67e7f2f77f320affcd1e945a7cc6e1c01c87d559d231cbed3309bbd4fff74833a5296f21680492955977d042594a39d807d4cb91eecd6adc4b4636
@@ -22,7 +22,9 @@ static VALUE contrast_assess_array_join(const int argc, const VALUE *argv,
22
22
  }
23
23
  /* Finally, default to empty String. Implicit since nil.to_s is ''*/
24
24
 
25
+ /* call the Array.join but patched one */
25
26
  result = rb_funcall2(ary, rb_sym_assess_array_join, argc, argv);
27
+ /* call the Contrast::Extensions::Assess::ArrayPropagator#cs__track_join */
26
28
  result = rb_funcall(array_propagator, rb_sym_assess_track_array_join, 3,
27
29
  ary, sep, result);
28
30
 
@@ -33,6 +35,11 @@ void Init_cs__assess_array(void) {
33
35
  array_propagator =
34
36
  rb_define_class_under(core_assess, "ArrayPropagator", rb_cObject);
35
37
  rb_sym_assess_track_array_join = rb_intern("cs__track_join");
38
+ /*
39
+ * Here we need to check before using the alias or prepend spec
40
+ * This patch is happening here, we register the cs__track_join
41
+ * method of the Array propagator, and call it here from Ruby.
42
+ */
36
43
  rb_sym_assess_array_join =
37
44
  contrast_register_patch("Array", "join", contrast_assess_array_join);
38
45
  }
@@ -3,8 +3,20 @@
3
3
 
4
4
  #include "cs__assess_basic_object.h"
5
5
  #include "../cs__common/cs__common.h"
6
+ #include "../cs__scope/cs__scope.h"
6
7
  #include <ruby.h>
7
8
 
9
+ /*
10
+ * Source code of instance_eval:
11
+ *
12
+ * static VALUE
13
+ * rb_obj_instance_eval_internal(int argc, const VALUE *argv, VALUE self)
14
+ * {
15
+ * VALUE klass = singleton_class_for_eval(self);
16
+ * return specific_eval(argc, argv, klass, self, RB_PASS_CALLED_KEYWORDS);
17
+ * }
18
+ */
19
+
8
20
  void contrast_assess_instance_eval_trigger_check(VALUE self, VALUE source,
9
21
  VALUE ret) {
10
22
  rb_funcall(basic_eval_trigger, instance_trigger_check_method, 3, self,
@@ -19,19 +31,21 @@ contrast_assess_basic_object_instance_eval(const int argc, const VALUE *argv,
19
31
  return rb_obj_instance_eval(argc, argv, self);
20
32
  }
21
33
 
22
- int nested_scope =
23
- RTEST(rb_funcall(contrast_patcher(), rb_sym_in_scope, 0));
34
+ VALUE nested_scope = inst_methods_in_cntr_scope(contrast_patcher(), 0);
24
35
 
25
- rb_funcall(contrast_patcher(), rb_sym_enter_scope, 0);
36
+ /* Enter scope */
37
+ inst_methods_enter_cntr_scope(contrast_patcher(), 0);
26
38
 
39
+ /* Call the source: */
27
40
  VALUE ret = rb_obj_instance_eval(argc, argv, self);
28
41
 
29
- if (!nested_scope && argc > 0) {
42
+ if (nested_scope == Qfalse && argc > 0) {
30
43
  VALUE data = argv[0];
31
44
  contrast_assess_instance_eval_trigger_check(self, data, ret);
32
45
  }
33
46
 
34
- rb_funcall(contrast_patcher(), rb_sym_exit_scope, 0);
47
+ /* Exit scope */
48
+ inst_methods_exit_cntr_scope(contrast_patcher(), 0);
35
49
 
36
50
  return ret;
37
51
  }
@@ -30,7 +30,7 @@ VALUE rb_fiber_new_hook(VALUE (*func)(ANYARGS), VALUE obj) {
30
30
  ID meth;
31
31
  };
32
32
 
33
- /* underlying object is first entry in Enumerator struct def.
33
+ /* underlying object is first entry in Enumerator struct def.
34
34
  * that's all statically defined w/in enumerator.c, so we can't
35
35
  * reference the data types and be safe about it. (yippee.)
36
36
  * we cut out the TypedData_Get_Struct middleman & just go for it.
@@ -17,7 +17,6 @@ static VALUE contrast_assess_hash_bracket_constructor(const int argc,
17
17
  const VALUE hash) {
18
18
  VALUE result;
19
19
 
20
-
21
20
  /* Array of Arrays: Hash[ [ [key, value], ... ] ] -> new_hash */
22
21
  if (RB_TYPE_P(argv[0], T_ARRAY)) {
23
22
  int i;
@@ -34,13 +33,13 @@ static VALUE contrast_assess_hash_bracket_constructor(const int argc,
34
33
  }
35
34
  }
36
35
 
37
- const VALUE * argv_final = argv;
36
+ const VALUE *argv_final = argv;
38
37
  /* unhandled case - shouldn't need it since issue is only unfrozen
39
38
  * String keys
40
39
  * # Hash[ object ] -> new_hash
41
40
  */
42
- result =
43
- rb_funcall2(hash, rb_sym_assess_hash_bracket_constructor, argc, argv_final);
41
+ result = rb_funcall2(hash, rb_sym_assess_hash_bracket_constructor, argc,
42
+ argv_final);
44
43
 
45
44
  return result;
46
45
  }
@@ -3,19 +3,21 @@
3
3
 
4
4
  #include "cs__assess_kernel.h"
5
5
  #include "../cs__common/cs__common.h"
6
+ #include "../cs__scope/cs__scope.h"
6
7
  #include <ruby.h>
7
8
 
8
9
  VALUE
9
10
  contrast_patched_kernel_exec(const int argc, const VALUE *argv,
10
11
  const VALUE self) {
11
- int nested_scope =
12
- RTEST(rb_funcall(contrast_patcher(), rb_sym_in_scope, 0));
12
+ VALUE nested_scope = inst_methods_in_cntr_scope(contrast_patcher(), 0);
13
13
 
14
- if (!nested_scope && argc > 0) {
15
- rb_funcall(contrast_patcher(), rb_sym_enter_scope, 0);
14
+ if (nested_scope == Qfalse && argc > 0) {
15
+ /* enter scope */
16
+ inst_methods_enter_cntr_scope(contrast_patcher(), 0);
16
17
  VALUE data = argv[0];
17
18
  rb_funcall(kernel_propagator, exec_apply_trigger, 1, data);
18
- rb_funcall(contrast_patcher(), rb_sym_exit_scope, 0);
19
+ /* exit scope */
20
+ inst_methods_exit_cntr_scope(contrast_patcher(), 0);
19
21
  }
20
22
 
21
23
  /* maybe this should be rb_funcall2. this works right now because *argv ==
@@ -5,36 +5,50 @@
5
5
  #include "../cs__common/cs__common.h"
6
6
  #include <ruby.h>
7
7
 
8
- static VALUE contrast_marshal_module_load(const int argc,
9
- const VALUE *argv) {
8
+ /*
9
+ * Marshal#load source:
10
+ * static VALUE
11
+ * marshal_load(int argc, VALUE *argv)
12
+ * {
13
+ * VALUE port, proc;
14
+ *
15
+ * rb_check_arity(argc, 1, 2);
16
+ * port = argv[0];
17
+ * proc = argc > 1 ? argv[1] : Qnil;
18
+ * return rb_marshal_load_with_proc(port, proc);
19
+ * }
20
+ */
21
+ static VALUE contrast_marshal_module_load(const int argc, const VALUE *argv) {
10
22
  VALUE result;
11
23
  VALUE source_string;
12
24
 
13
- // Our patches only need only apply in the case where there was valid input.
25
+ /* Our patches need to apply only in the case where there was valid input.
26
+ */
14
27
  if (argc >= 1) {
15
28
  source_string = argv[0];
16
29
  } else {
17
30
  source_string = Qnil;
18
31
  }
19
32
 
20
- // Run our protect code ahead of the original method
33
+ /* Run our protect code ahead of the original method */
21
34
  if (source_string != Qnil) {
22
- rb_funcall(marshal_propagator, rb_sym_protect_marshal_load, 1, source_string);
35
+ rb_funcall(marshal_propagator, rb_sym_protect_marshal_load, 1,
36
+ source_string);
23
37
  }
24
38
 
25
- // Invoke the original method
39
+ /* Invoke the original method */
26
40
  result = rb_call_super(argc, argv);
27
41
 
28
- // Run our assess code after the original method
42
+ /* Run our assess code after the original method */
29
43
  if (source_string != Qnil) {
30
44
  VALUE tracked =
31
45
  rb_funcall(properties_hash, rb_sym_hash_tracked, 1, source_string);
32
46
 
33
- // Assuming the source is tracked and needs assess checks
47
+ /* Assuming the source is tracked and needs assess checks */
34
48
  if (tracked == Qtrue) {
35
49
  VALUE skip =
36
50
  rb_funcall(contrast_patcher(), rb_sym_skip_assess_analysis, 0);
37
- // And Assess is enabled and applies to this request
51
+ /* And Assess is enabled and applies to this request */
38
52
  if (skip == Qfalse) {
39
53
  rb_funcall(marshal_propagator, rb_sym_assess_marshal_load, 2,
40
54
  source_string, result);
@@ -45,7 +59,7 @@ static VALUE contrast_marshal_module_load(const int argc,
45
59
  }
46
60
 
47
61
  void Init_cs__assess_marshal_module(void) {
48
- // Contrast::Agent::Assess::Tracker::PROPERTIES_HASH
62
+ /* Contrast::Agent::Assess::Tracker::PROPERTIES_HASH */
49
63
  VALUE tracker = rb_define_class_under(assess, "Tracker", rb_cObject);
50
64
  properties_hash = rb_const_get(tracker, rb_intern("PROPERTIES_HASH"));
51
65
  marshal_propagator =
@@ -53,6 +67,6 @@ void Init_cs__assess_marshal_module(void) {
53
67
  rb_sym_assess_marshal_load = rb_intern("cs__load_assess");
54
68
  rb_sym_protect_marshal_load = rb_intern("cs__load_protect");
55
69
 
56
- contrast_register_singleton_prepend_patch(
57
- "Marshal", "load", &contrast_marshal_module_load);
70
+ contrast_register_singleton_prepend_patch("Marshal", "load",
71
+ &contrast_marshal_module_load);
58
72
  }
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "cs__assess_module.h"
5
5
  #include "../cs__common/cs__common.h"
6
+ #include "../cs__scope/cs__scope.h"
6
7
  #include <ruby.h>
7
8
 
8
9
  void contrast_assess_eval_trigger_check(VALUE module, VALUE source, VALUE ret) {
@@ -11,12 +12,11 @@ void contrast_assess_eval_trigger_check(VALUE module, VALUE source, VALUE ret) {
11
12
  return;
12
13
  }
13
14
 
14
- int nested_scope =
15
- RTEST(rb_funcall(contrast_patcher(), rb_sym_in_scope, 0));
15
+ int nested_scope = inst_methods_in_cntr_scope(contrast_patcher(), 0);
16
+ /* enter scope */
17
+ inst_methods_enter_cntr_scope(contrast_patcher(), 0);
16
18
 
17
- rb_funcall(contrast_patcher(), rb_sym_enter_scope, 0);
18
-
19
- if (!nested_scope) {
19
+ if (nested_scope == Qfalse) {
20
20
  VALUE method = rb_funcall(rb_mKernel, rb_sym_method, 0);
21
21
  /* If this method ever throws an exception, the scope-leave
22
22
  * needs to be moved within a rescue call.
@@ -24,8 +24,8 @@ void contrast_assess_eval_trigger_check(VALUE module, VALUE source, VALUE ret) {
24
24
  rb_funcall(module_eval_trigger, trigger_check_method, 4, module, source,
25
25
  ret, method);
26
26
  }
27
-
28
- rb_funcall(contrast_patcher(), rb_sym_exit_scope, 0);
27
+ /* exit scope */
28
+ inst_methods_exit_cntr_scope(contrast_patcher(), 0);
29
29
  }
30
30
 
31
31
  VALUE
@@ -5,6 +5,18 @@
5
5
  #include "../cs__common/cs__common.h"
6
6
  #include <ruby.h>
7
7
 
8
+ /*
9
+ * The -@ method source:
10
+ *
11
+ * static VALUE
12
+ * str_uminus(VALUE str)
13
+ * {
14
+ * if (!BARE_STRING_P(str) && !rb_obj_frozen_p(str)) {
15
+ * str = rb_str_dup(str);
16
+ * }
17
+ * return rb_fstring(str);
18
+ * }
19
+ */
8
20
  static VALUE contrast_assess_string_freeze(const int argc, VALUE *argv,
9
21
  const VALUE obj) {
10
22
  if (!OBJ_FROZEN(obj)) {
@@ -39,7 +51,7 @@ void Init_cs__assess_string(void) {
39
51
  rb_sym_dup = rb_intern("dup");
40
52
  rb_sym_freeze = rb_intern("freeze");
41
53
  rb_sym_pre_freeze = rb_intern("pre_freeze");
42
- // Contrast::Agent::Assess::Tracker::PROPERTIES_HASH
54
+ /* Contrast::Agent::Assess::Tracker::PROPERTIES_HASH */
43
55
  VALUE tracker = rb_define_class_under(assess, "Tracker", rb_cObject);
44
56
  properties_hash = rb_const_get(tracker, rb_intern("PROPERTIES_HASH"));
45
57
 
@@ -10,6 +10,7 @@
10
10
  VALUE contrast, agent, patching, policy, assess;
11
11
  VALUE core_extensions, core_assess;
12
12
  VALUE assess_policy, assess_propagator;
13
+ VALUE components;
13
14
  VALUE funchook_path;
14
15
 
15
16
  VALUE rb_sym_enter_scope;
@@ -59,8 +60,7 @@ VALUE contrast_patcher() {
59
60
  }
60
61
 
61
62
  VALUE contrast_register_patch(const char *module_name, const char *method_name,
62
- VALUE(c_fn)(const int, VALUE *,
63
- const VALUE)) {
63
+ VALUE(c_fn)(const int, VALUE *, const VALUE)) {
64
64
  return _contrast_register_patch(module_name, method_name, c_fn,
65
65
  IMPL_ALIAS_INSTANCE);
66
66
  }
@@ -74,17 +74,17 @@ VALUE contrast_register_singleton_patch(const char *module_name,
74
74
  }
75
75
 
76
76
  VALUE contrast_register_prepend_patch(const char *module_name,
77
- const char *method_name,
78
- VALUE(c_fn)(const int, VALUE *,
79
- const VALUE)) {
77
+ const char *method_name,
78
+ VALUE(c_fn)(const int, VALUE *,
79
+ const VALUE)) {
80
80
  return _contrast_register_patch(module_name, method_name, c_fn,
81
81
  IMPL_PREPEND_INSTANCE);
82
82
  }
83
83
 
84
84
  VALUE contrast_register_singleton_prepend_patch(const char *module_name,
85
- const char *method_name,
86
- VALUE(c_fn)(const int, VALUE *,
87
- const VALUE)) {
85
+ const char *method_name,
86
+ VALUE(c_fn)(const int, VALUE *,
87
+ const VALUE)) {
88
88
  return _contrast_register_patch(module_name, method_name, c_fn,
89
89
  IMPL_PREPEND_SINGLETON);
90
90
  }
@@ -134,7 +134,7 @@ _contrast_register_patch(const char *module_name, const char *method_name,
134
134
  case IMPL_PREPEND_INSTANCE:
135
135
  impl = ID2SYM(rb_sym_prepend_instance);
136
136
  case IMPL_PREPEND_SINGLETON:
137
- impl = ID2SYM(rb_sym_prepend_singleton);
137
+ impl = ID2SYM(rb_sym_prepend_singleton);
138
138
  break;
139
139
  }
140
140
 
@@ -145,8 +145,10 @@ _contrast_register_patch(const char *module_name, const char *method_name,
145
145
  }
146
146
 
147
147
  int rb_ver_below_three() {
148
- int ruby_version = FIX2INT(rb_funcall(rb_const_get(rb_cObject, rb_intern("RUBY_VERSION")), rb_intern("to_i"), 0));
149
- return ruby_version < 3;
148
+ int ruby_version =
149
+ FIX2INT(rb_funcall(rb_const_get(rb_cObject, rb_intern("RUBY_VERSION")),
150
+ rb_intern("to_i"), 0));
151
+ return ruby_version < 3;
150
152
  }
151
153
 
152
154
  void Init_cs__common(void) {
@@ -175,6 +177,9 @@ void Init_cs__common(void) {
175
177
  contrast = rb_define_module("Contrast");
176
178
  agent = rb_define_module_under(contrast, "Agent");
177
179
 
180
+ /* components => Contrast::Components */
181
+ components = rb_define_module_under(contrast, "Components");
182
+
178
183
  assess = rb_define_module_under(agent, "Assess");
179
184
 
180
185
  patching = rb_define_module_under(agent, "Patching");
@@ -17,6 +17,7 @@ extern VALUE contrast, agent, patching, policy, assess;
17
17
  extern VALUE core_extensions, core_assess;
18
18
  extern VALUE assess_policy, assess_propagator;
19
19
  extern VALUE funchook_path;
20
+ extern VALUE components;
20
21
 
21
22
  extern VALUE rb_sym_enter_scope;
22
23
  extern VALUE rb_sym_exit_scope;