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.
- checksums.yaml +4 -4
- data/ext/cs__assess_array/cs__assess_array.c +7 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +19 -5
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
- data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -5
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
- data/ext/cs__assess_module/cs__assess_module.c +7 -7
- data/ext/cs__assess_string/cs__assess_string.c +13 -1
- data/ext/cs__common/cs__common.c +16 -11
- data/ext/cs__common/cs__common.h +1 -0
- data/ext/cs__contrast_patch/cs__contrast_patch.c +100 -64
- data/ext/cs__contrast_patch/cs__contrast_patch.h +2 -0
- data/ext/cs__os_information/cs__os_information.c +13 -10
- data/ext/cs__scope/cs__scope.c +796 -0
- data/ext/cs__scope/cs__scope.h +88 -0
- data/ext/cs__scope/extconf.rb +5 -0
- data/lib/contrast/agent/assess/contrast_event.rb +20 -13
- data/lib/contrast/agent/assess/contrast_object.rb +4 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +2 -0
- data/lib/contrast/agent/assess/policy/policy_node.rb +50 -27
- data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
- data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
- data/lib/contrast/agent/assess/policy/propagation_method.rb +47 -13
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -5
- data/lib/contrast/agent/assess/policy/propagator/buffer.rb +118 -0
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +2 -0
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
- data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
- data/lib/contrast/agent/assess/policy/trigger_method.rb +6 -1
- data/lib/contrast/agent/assess/property/tagged.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/{autocomplete_rule.rb → auto_complete_rule.rb} +4 -3
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +12 -79
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +109 -0
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +157 -0
- data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +26 -0
- data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +14 -15
- data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +5 -25
- data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +29 -0
- data/lib/contrast/agent/assess/rule/response/header_rule.rb +70 -0
- data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +12 -36
- data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +2 -1
- data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +26 -0
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +35 -0
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
- data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
- data/lib/contrast/agent/exclusion_matcher.rb +3 -3
- data/lib/contrast/agent/middleware.rb +4 -1
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +1 -3
- data/lib/contrast/agent/patching/policy/patch.rb +2 -6
- data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
- data/lib/contrast/agent/patching/policy/policy_node.rb +15 -2
- data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +147 -0
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -1
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -2
- data/lib/contrast/agent/protect/rule/base.rb +61 -2
- data/lib/contrast/agent/protect/rule/base_service.rb +12 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +15 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
- data/lib/contrast/agent/protect/rule/deserialization.rb +6 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +13 -1
- data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
- data/lib/contrast/agent/protect/rule/no_sqli.rb +28 -0
- data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +88 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +118 -0
- data/lib/contrast/agent/protect/rule/sqli.rb +33 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
- data/lib/contrast/agent/protect/rule/xxe.rb +4 -0
- data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
- data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
- data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
- data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +44 -0
- data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +115 -0
- data/lib/contrast/agent/reporting/input_analysis/input_type.rb +44 -0
- data/lib/contrast/agent/reporting/input_analysis/score_level.rb +21 -0
- data/lib/contrast/agent/reporting/masker/masker.rb +246 -0
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +58 -0
- data/lib/contrast/agent/reporting/report.rb +3 -0
- data/lib/contrast/agent/reporting/reporter.rb +31 -12
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +30 -0
- data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +7 -3
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +40 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +69 -36
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +88 -59
- data/lib/contrast/agent/reporting/reporting_events/{finding_object.rb → finding_event_object.rb} +24 -20
- data/lib/contrast/agent/reporting/reporting_events/finding_event_parent_object.rb +39 -0
- data/lib/contrast/agent/reporting/reporting_events/finding_event_property.rb +40 -0
- data/lib/contrast/agent/reporting/reporting_events/{finding_signature.rb → finding_event_signature.rb} +29 -24
- data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +12 -8
- data/lib/contrast/agent/reporting/reporting_events/{finding_stack.rb → finding_event_stack.rb} +23 -19
- data/lib/contrast/agent/reporting/reporting_events/{finding_taint_range.rb → finding_event_taint_range.rb} +17 -15
- data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +26 -53
- data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +9 -9
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +29 -0
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +6 -4
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
- data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +1 -0
- data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +10 -3
- data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +17 -5
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +54 -45
- data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +97 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +69 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +123 -85
- data/lib/contrast/agent/reporting/settings/application_settings.rb +9 -0
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +5 -33
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +1 -1
- data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
- data/lib/contrast/agent/request_context.rb +7 -2
- data/lib/contrast/agent/request_context_extend.rb +85 -21
- data/lib/contrast/agent/request_handler.rb +4 -0
- data/lib/contrast/agent/scope.rb +102 -107
- data/lib/contrast/agent/service_heartbeat.rb +45 -2
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +51 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +36 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +97 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +65 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +47 -0
- data/lib/contrast/agent/{metric_telemetry_event.rb → telemetry/events/metric_telemetry_event.rb} +1 -1
- data/lib/contrast/agent/{startup_metrics_telemetry_event.rb → telemetry/events/startup_metrics_telemetry_event.rb} +3 -3
- data/lib/contrast/agent/{telemetry_event.rb → telemetry/events/telemetry_event.rb} +1 -1
- data/lib/contrast/agent/{telemetry.rb → telemetry/telemetry.rb} +32 -19
- data/lib/contrast/agent/thread_watcher.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent.rb +3 -0
- data/lib/contrast/api/communication/speedracer.rb +1 -1
- data/lib/contrast/api/decorators/address.rb +1 -1
- data/lib/contrast/api/decorators/bot_blocker.rb +37 -0
- data/lib/contrast/api/decorators/ip_denylist.rb +37 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
- data/lib/contrast/api/decorators/response_type.rb +30 -0
- data/lib/contrast/api/decorators/user_input.rb +11 -1
- data/lib/contrast/api/decorators/virtual_patch.rb +34 -0
- data/lib/contrast/api/decorators.rb +1 -0
- data/lib/contrast/components/app_context.rb +0 -4
- data/lib/contrast/components/assess.rb +14 -0
- data/lib/contrast/components/logger.rb +5 -0
- data/lib/contrast/components/protect.rb +6 -4
- data/lib/contrast/components/sampling.rb +7 -11
- data/lib/contrast/components/scope.rb +98 -91
- data/lib/contrast/components/settings.rb +106 -8
- data/lib/contrast/config/agent_configuration.rb +41 -12
- data/lib/contrast/config/api_configuration.rb +37 -12
- data/lib/contrast/config/api_proxy_configuration.rb +12 -3
- data/lib/contrast/config/application_configuration.rb +38 -14
- data/lib/contrast/config/assess_configuration.rb +47 -12
- data/lib/contrast/config/assess_rules_configuration.rb +15 -3
- data/lib/contrast/config/base_configuration.rb +18 -50
- data/lib/contrast/config/certification_configuration.rb +17 -3
- data/lib/contrast/config/exception_configuration.rb +14 -3
- data/lib/contrast/config/heap_dump_configuration.rb +43 -17
- data/lib/contrast/config/inventory_configuration.rb +17 -3
- data/lib/contrast/config/logger_configuration.rb +10 -3
- data/lib/contrast/config/protect_configuration.rb +17 -7
- data/lib/contrast/config/protect_rule_configuration.rb +17 -8
- data/lib/contrast/config/protect_rules_configuration.rb +115 -17
- data/lib/contrast/config/request_audit_configuration.rb +26 -3
- data/lib/contrast/config/root_configuration.rb +52 -12
- data/lib/contrast/config/ruby_configuration.rb +60 -22
- data/lib/contrast/config/sampling_configuration.rb +19 -9
- data/lib/contrast/config/server_configuration.rb +19 -10
- data/lib/contrast/config/service_configuration.rb +27 -11
- data/lib/contrast/configuration.rb +5 -3
- data/lib/contrast/extension/assess/string.rb +20 -1
- data/lib/contrast/extension/module.rb +0 -1
- data/lib/contrast/framework/manager.rb +2 -2
- data/lib/contrast/logger/application.rb +1 -1
- data/lib/contrast/logger/cef_log.rb +151 -0
- data/lib/contrast/tasks/config.rb +90 -3
- data/lib/contrast/utils/assess/object_store.rb +36 -0
- data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
- data/lib/contrast/utils/class_util.rb +3 -12
- data/lib/contrast/utils/hash_digest.rb +14 -6
- data/lib/contrast/utils/input_classification.rb +73 -0
- data/lib/contrast/utils/log_utils.rb +114 -0
- data/lib/contrast/utils/middleware_utils.rb +9 -9
- data/lib/contrast/utils/net_http_base.rb +13 -10
- data/lib/contrast/utils/object_share.rb +2 -1
- data/lib/contrast/utils/os.rb +0 -5
- data/lib/contrast/utils/patching/policy/patch_utils.rb +4 -9
- data/lib/contrast/utils/response_utils.rb +18 -33
- data/lib/contrast/utils/telemetry.rb +1 -1
- data/lib/contrast/utils/telemetry_client.rb +1 -1
- data/lib/contrast/utils/telemetry_identifier.rb +1 -1
- data/lib/contrast.rb +4 -3
- data/resources/assess/policy.json +98 -0
- data/resources/deadzone/policy.json +0 -86
- data/ruby-agent.gemspec +9 -8
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +103 -38
- data/lib/contrast/agent/assess/rule/response/cachecontrol_rule.rb +0 -184
- data/lib/contrast/agent/assess/rule/response/clickjacking_rule.rb +0 -66
- data/lib/contrast/agent/assess/rule/response/x_content_type_rule.rb +0 -52
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_rule.rb +0 -53
- data/lib/contrast/extension/kernel.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47aa135a205e4a74d64b778ae543f892213ca70e47be654032147a8bfe16dc82
|
4
|
+
data.tar.gz: 60f0de0e2675578bfb735c4f90303748bdc5e2053f2722dac4907bf84364d2f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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 (
|
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
|
-
|
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
|
-
/*
|
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 *
|
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
|
-
|
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
|
-
|
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 (
|
15
|
-
|
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
|
-
|
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
|
-
|
9
|
-
|
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
|
-
|
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
|
-
|
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,
|
35
|
+
rb_funcall(marshal_propagator, rb_sym_protect_marshal_load, 1,
|
36
|
+
source_string);
|
23
37
|
}
|
24
38
|
|
25
|
-
|
39
|
+
/* Invoke the original method */
|
26
40
|
result = rb_call_super(argc, argv);
|
27
41
|
|
28
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
|
data/ext/cs__common/cs__common.c
CHANGED
@@ -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
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
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
|
-
|
149
|
-
|
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");
|
data/ext/cs__common/cs__common.h
CHANGED
@@ -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;
|