contrast-agent 3.14.0 → 4.2.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_marshal_module/cs__assess_marshal_module.c +18 -15
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
- data/ext/cs__assess_string/cs__assess_string.c +24 -25
- data/ext/cs__assess_string/cs__assess_string.h +3 -1
- data/ext/cs__common/cs__common.c +4 -2
- data/ext/cs__common/cs__common.h +1 -1
- data/lib/contrast.rb +1 -1
- data/lib/contrast/agent.rb +4 -12
- data/lib/contrast/agent/assess.rb +1 -0
- data/lib/contrast/agent/assess/contrast_event.rb +143 -79
- data/lib/contrast/agent/assess/events/source_event.rb +1 -1
- data/lib/contrast/agent/assess/finalizers/freeze.rb +3 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +45 -1
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +10 -3
- data/lib/contrast/agent/assess/policy/patcher.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy.rb +0 -2
- data/lib/contrast/agent/assess/policy/policy_node.rb +15 -10
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +19 -3
- data/lib/contrast/agent/assess/policy/preshift.rb +7 -11
- data/lib/contrast/agent/assess/policy/propagation_method.rb +50 -33
- data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +5 -3
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +4 -7
- data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +8 -5
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
- data/lib/contrast/agent/assess/policy/propagator/split.rb +24 -19
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +47 -31
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +85 -58
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +76 -28
- data/lib/contrast/agent/assess/policy/trigger_node.rb +38 -43
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
- data/lib/contrast/agent/assess/properties.rb +2 -0
- data/lib/contrast/agent/assess/property/evented.rb +5 -18
- data/lib/contrast/agent/assess/property/tagged.rb +9 -3
- data/lib/contrast/agent/assess/property/updated.rb +131 -0
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +23 -8
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +83 -14
- data/lib/contrast/agent/assess/tag.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +66 -0
- data/lib/contrast/agent/at_exit_hook.rb +5 -5
- data/lib/contrast/agent/class_reopener.rb +7 -5
- data/lib/contrast/agent/inventory.rb +15 -0
- data/lib/contrast/agent/inventory/dependencies.rb +50 -0
- data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
- data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
- data/lib/contrast/agent/middleware.rb +1 -3
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +5 -5
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +20 -20
- data/lib/contrast/agent/patching/policy/module_policy.rb +10 -10
- data/lib/contrast/agent/patching/policy/patch.rb +6 -0
- data/lib/contrast/agent/patching/policy/patcher.rb +13 -22
- data/lib/contrast/agent/patching/policy/policy.rb +17 -6
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -5
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +4 -3
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +9 -25
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
- data/lib/contrast/agent/request.rb +34 -34
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +17 -6
- data/lib/contrast/agent/rewriter.rb +1 -3
- data/lib/contrast/agent/scope.rb +59 -53
- data/lib/contrast/agent/static_analysis.rb +7 -7
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/communication/messaging_queue.rb +1 -4
- data/lib/contrast/api/communication/socket_client.rb +36 -1
- data/lib/contrast/api/decorators.rb +3 -0
- data/lib/contrast/api/decorators/address.rb +13 -14
- data/lib/contrast/api/decorators/application_update.rb +2 -4
- data/lib/contrast/api/decorators/library.rb +53 -0
- data/lib/contrast/api/decorators/library_usage_update.rb +30 -0
- data/lib/contrast/api/decorators/message.rb +1 -0
- data/lib/contrast/api/decorators/trace_event.rb +25 -23
- data/lib/contrast/common_agent_configuration.rb +2 -1
- data/lib/contrast/components/agent.rb +6 -5
- data/lib/contrast/components/app_context.rb +49 -38
- data/lib/contrast/components/config.rb +30 -48
- data/lib/contrast/components/contrast_service.rb +9 -9
- data/lib/contrast/components/interface.rb +25 -3
- data/lib/contrast/components/inventory.rb +6 -1
- data/lib/contrast/components/scope.rb +49 -6
- data/lib/contrast/components/settings.rb +23 -23
- data/lib/contrast/config/application_configuration.rb +5 -2
- data/lib/contrast/config/inventory_configuration.rb +2 -2
- data/lib/contrast/config/service_configuration.rb +8 -0
- data/lib/contrast/configuration.rb +88 -47
- data/lib/contrast/extension/assess.rb +0 -2
- data/lib/contrast/extension/assess/array.rb +15 -8
- data/lib/contrast/extension/assess/erb.rb +11 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +6 -6
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -4
- data/lib/contrast/extension/assess/fiber.rb +12 -12
- data/lib/contrast/extension/assess/hash.rb +5 -6
- data/lib/contrast/extension/assess/kernel.rb +28 -23
- data/lib/contrast/extension/assess/marshal.rb +11 -6
- data/lib/contrast/extension/assess/regexp.rb +8 -7
- data/lib/contrast/extension/assess/string.rb +21 -21
- data/lib/contrast/extension/protect/kernel.rb +3 -3
- data/lib/contrast/framework/base_support.rb +1 -1
- data/lib/contrast/framework/manager.rb +3 -3
- data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -11
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +10 -10
- data/lib/contrast/framework/rails/patch/support.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -3
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
- data/lib/contrast/framework/rails/support.rb +5 -0
- data/lib/contrast/framework/sinatra/patch/base.rb +11 -11
- data/lib/contrast/framework/sinatra/support.rb +4 -4
- data/lib/contrast/logger/application.rb +11 -3
- data/lib/contrast/logger/log.rb +7 -2
- data/lib/contrast/utils/assess/tracking_util.rb +48 -3
- data/lib/contrast/utils/duck_utils.rb +0 -10
- data/lib/contrast/utils/env_configuration_item.rb +2 -1
- data/lib/contrast/utils/invalid_configuration_util.rb +20 -21
- data/lib/contrast/utils/inventory_util.rb +0 -7
- data/lib/contrast/utils/sha256_builder.rb +0 -12
- data/lib/contrast/utils/string_utils.rb +10 -5
- data/resources/assess/policy.json +31 -22
- data/ruby-agent.gemspec +21 -18
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +71 -30
- data/lib/contrast/agent/assess/finalizers/finalize.rb +0 -21
- data/lib/contrast/extension/assess/assess_extension.rb +0 -145
- data/lib/contrast/utils/boolean_util.rb +0 -30
- data/lib/contrast/utils/freeze_util.rb +0 -32
- data/lib/contrast/utils/gemfile_reader.rb +0 -193
data/service_executables/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.16.0
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contrast-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- galen.palmer@contrastsecurity.com
|
@@ -9,10 +9,11 @@ authors:
|
|
9
9
|
- donald.propst@contrastsecurity.com
|
10
10
|
- alex.macdonald@contrastsecurity.com
|
11
11
|
- mark.petersen@contrastsecurity.com
|
12
|
+
- joshua.reed@contrastsecurity.com
|
12
13
|
autorequire:
|
13
14
|
bindir: exe
|
14
15
|
cert_chain: []
|
15
|
-
date: 2020-
|
16
|
+
date: 2020-12-18 00:00:00.000000000 Z
|
16
17
|
dependencies:
|
17
18
|
- !ruby/object:Gem::Dependency
|
18
19
|
name: amazing_print
|
@@ -56,6 +57,20 @@ dependencies:
|
|
56
57
|
- - ">="
|
57
58
|
- !ruby/object:Gem::Version
|
58
59
|
version: '0'
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: debase
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
59
74
|
- !ruby/object:Gem::Dependency
|
60
75
|
name: debride
|
61
76
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,6 +141,20 @@ dependencies:
|
|
126
141
|
- - ">="
|
127
142
|
- !ruby/object:Gem::Version
|
128
143
|
version: '0'
|
144
|
+
- !ruby/object:Gem::Dependency
|
145
|
+
name: flay
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
type: :development
|
152
|
+
prerelease: false
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
129
158
|
- !ruby/object:Gem::Dependency
|
130
159
|
name: openssl
|
131
160
|
requirement: !ruby/object:Gem::Requirement
|
@@ -258,42 +287,56 @@ dependencies:
|
|
258
287
|
requirements:
|
259
288
|
- - '='
|
260
289
|
- !ruby/object:Gem::Version
|
261
|
-
version: 0.
|
290
|
+
version: 0.93.1
|
262
291
|
type: :development
|
263
292
|
prerelease: false
|
264
293
|
version_requirements: !ruby/object:Gem::Requirement
|
265
294
|
requirements:
|
266
295
|
- - '='
|
267
296
|
- !ruby/object:Gem::Version
|
268
|
-
version: 0.
|
297
|
+
version: 0.93.1
|
269
298
|
- !ruby/object:Gem::Dependency
|
270
299
|
name: rubocop-performance
|
271
300
|
requirement: !ruby/object:Gem::Requirement
|
272
301
|
requirements:
|
273
302
|
- - '='
|
274
303
|
- !ruby/object:Gem::Version
|
275
|
-
version: 1.
|
304
|
+
version: 1.8.1
|
276
305
|
type: :development
|
277
306
|
prerelease: false
|
278
307
|
version_requirements: !ruby/object:Gem::Requirement
|
279
308
|
requirements:
|
280
309
|
- - '='
|
281
310
|
- !ruby/object:Gem::Version
|
282
|
-
version: 1.
|
311
|
+
version: 1.8.1
|
283
312
|
- !ruby/object:Gem::Dependency
|
284
313
|
name: rubocop-rspec
|
285
314
|
requirement: !ruby/object:Gem::Requirement
|
286
315
|
requirements:
|
287
316
|
- - '='
|
288
317
|
- !ruby/object:Gem::Version
|
289
|
-
version: 1.
|
318
|
+
version: 1.43.2
|
290
319
|
type: :development
|
291
320
|
prerelease: false
|
292
321
|
version_requirements: !ruby/object:Gem::Requirement
|
293
322
|
requirements:
|
294
323
|
- - '='
|
295
324
|
- !ruby/object:Gem::Version
|
296
|
-
version: 1.
|
325
|
+
version: 1.43.2
|
326
|
+
- !ruby/object:Gem::Dependency
|
327
|
+
name: ruby-debug-ide
|
328
|
+
requirement: !ruby/object:Gem::Requirement
|
329
|
+
requirements:
|
330
|
+
- - ">="
|
331
|
+
- !ruby/object:Gem::Version
|
332
|
+
version: '0'
|
333
|
+
type: :development
|
334
|
+
prerelease: false
|
335
|
+
version_requirements: !ruby/object:Gem::Requirement
|
336
|
+
requirements:
|
337
|
+
- - ">="
|
338
|
+
- !ruby/object:Gem::Version
|
339
|
+
version: '0'
|
297
340
|
- !ruby/object:Gem::Dependency
|
298
341
|
name: simplecov
|
299
342
|
requirement: !ruby/object:Gem::Requirement
|
@@ -438,22 +481,16 @@ dependencies:
|
|
438
481
|
name: rack
|
439
482
|
requirement: !ruby/object:Gem::Requirement
|
440
483
|
requirements:
|
441
|
-
- - "
|
484
|
+
- - "~>"
|
442
485
|
- !ruby/object:Gem::Version
|
443
486
|
version: '2.0'
|
444
|
-
- - "<"
|
445
|
-
- !ruby/object:Gem::Version
|
446
|
-
version: '3.0'
|
447
487
|
type: :runtime
|
448
488
|
prerelease: false
|
449
489
|
version_requirements: !ruby/object:Gem::Requirement
|
450
490
|
requirements:
|
451
|
-
- - "
|
491
|
+
- - "~>"
|
452
492
|
- !ruby/object:Gem::Version
|
453
493
|
version: '2.0'
|
454
|
-
- - "<"
|
455
|
-
- !ruby/object:Gem::Version
|
456
|
-
version: '3.0'
|
457
494
|
description: This gem instantiates a Rack middleware for rack-based web applications
|
458
495
|
in order to provide Interactive Application Security Testing and Protection.
|
459
496
|
email:
|
@@ -462,20 +499,20 @@ executables:
|
|
462
499
|
- contrast_service
|
463
500
|
extensions:
|
464
501
|
- ext/cs__common/extconf.rb
|
465
|
-
- ext/cs__assess_string/extconf.rb
|
466
502
|
- ext/cs__assess_active_record_named/extconf.rb
|
467
|
-
- ext/
|
468
|
-
- ext/cs__assess_yield_track/extconf.rb
|
503
|
+
- ext/cs__assess_fiber_track/extconf.rb
|
469
504
|
- ext/cs__assess_basic_object/extconf.rb
|
470
|
-
- ext/
|
471
|
-
- ext/
|
505
|
+
- ext/cs__contrast_patch/extconf.rb
|
506
|
+
- ext/cs__assess_array/extconf.rb
|
472
507
|
- ext/cs__protect_kernel/extconf.rb
|
473
|
-
- ext/cs__assess_string_interpolation26/extconf.rb
|
474
508
|
- ext/cs__assess_kernel/extconf.rb
|
509
|
+
- ext/cs__assess_regexp/extconf.rb
|
510
|
+
- ext/cs__assess_hash/extconf.rb
|
511
|
+
- ext/cs__assess_module/extconf.rb
|
512
|
+
- ext/cs__assess_string_interpolation26/extconf.rb
|
475
513
|
- ext/cs__assess_marshal_module/extconf.rb
|
476
|
-
- ext/
|
477
|
-
- ext/
|
478
|
-
- ext/cs__assess_array/extconf.rb
|
514
|
+
- ext/cs__assess_yield_track/extconf.rb
|
515
|
+
- ext/cs__assess_string/extconf.rb
|
479
516
|
extra_rdoc_files: []
|
480
517
|
files:
|
481
518
|
- ".clang-format"
|
@@ -674,7 +711,6 @@ files:
|
|
674
711
|
- lib/contrast/agent/assess/contrast_event.rb
|
675
712
|
- lib/contrast/agent/assess/events/event_factory.rb
|
676
713
|
- lib/contrast/agent/assess/events/source_event.rb
|
677
|
-
- lib/contrast/agent/assess/finalizers/finalize.rb
|
678
714
|
- lib/contrast/agent/assess/finalizers/freeze.rb
|
679
715
|
- lib/contrast/agent/assess/finalizers/hash.rb
|
680
716
|
- lib/contrast/agent/assess/policy/dynamic_source_factory.rb
|
@@ -719,6 +755,7 @@ files:
|
|
719
755
|
- lib/contrast/agent/assess/properties.rb
|
720
756
|
- lib/contrast/agent/assess/property/evented.rb
|
721
757
|
- lib/contrast/agent/assess/property/tagged.rb
|
758
|
+
- lib/contrast/agent/assess/property/updated.rb
|
722
759
|
- lib/contrast/agent/assess/rule.rb
|
723
760
|
- lib/contrast/agent/assess/rule/base.rb
|
724
761
|
- lib/contrast/agent/assess/rule/provider.rb
|
@@ -727,12 +764,18 @@ files:
|
|
727
764
|
- lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb
|
728
765
|
- lib/contrast/agent/assess/rule/redos.rb
|
729
766
|
- lib/contrast/agent/assess/tag.rb
|
767
|
+
- lib/contrast/agent/assess/tracker.rb
|
730
768
|
- lib/contrast/agent/at_exit_hook.rb
|
731
769
|
- lib/contrast/agent/class_reopener.rb
|
732
770
|
- lib/contrast/agent/deadzone/policy/deadzone_node.rb
|
733
771
|
- lib/contrast/agent/deadzone/policy/policy.rb
|
734
772
|
- lib/contrast/agent/disable_reaction.rb
|
735
773
|
- lib/contrast/agent/exclusion_matcher.rb
|
774
|
+
- lib/contrast/agent/inventory.rb
|
775
|
+
- lib/contrast/agent/inventory/dependencies.rb
|
776
|
+
- lib/contrast/agent/inventory/dependency_analysis.rb
|
777
|
+
- lib/contrast/agent/inventory/dependency_usage_analysis.rb
|
778
|
+
- lib/contrast/agent/inventory/gemfile_digest_cache.rb
|
736
779
|
- lib/contrast/agent/inventory/policy/datastores.rb
|
737
780
|
- lib/contrast/agent/inventory/policy/policy.rb
|
738
781
|
- lib/contrast/agent/inventory/policy/trigger_node.rb
|
@@ -810,6 +853,8 @@ files:
|
|
810
853
|
- lib/contrast/api/decorators/application_update.rb
|
811
854
|
- lib/contrast/api/decorators/http_request.rb
|
812
855
|
- lib/contrast/api/decorators/input_analysis.rb
|
856
|
+
- lib/contrast/api/decorators/library.rb
|
857
|
+
- lib/contrast/api/decorators/library_usage_update.rb
|
813
858
|
- lib/contrast/api/decorators/message.rb
|
814
859
|
- lib/contrast/api/decorators/rasp_rule_sample.rb
|
815
860
|
- lib/contrast/api/decorators/route_coverage.rb
|
@@ -858,7 +903,6 @@ files:
|
|
858
903
|
- lib/contrast/configuration.rb
|
859
904
|
- lib/contrast/extension/assess.rb
|
860
905
|
- lib/contrast/extension/assess/array.rb
|
861
|
-
- lib/contrast/extension/assess/assess_extension.rb
|
862
906
|
- lib/contrast/extension/assess/erb.rb
|
863
907
|
- lib/contrast/extension/assess/eval_trigger.rb
|
864
908
|
- lib/contrast/extension/assess/exec_trigger.rb
|
@@ -905,12 +949,9 @@ files:
|
|
905
949
|
- lib/contrast/tasks/service.rb
|
906
950
|
- lib/contrast/utils/assess/sampling_util.rb
|
907
951
|
- lib/contrast/utils/assess/tracking_util.rb
|
908
|
-
- lib/contrast/utils/boolean_util.rb
|
909
952
|
- lib/contrast/utils/class_util.rb
|
910
953
|
- lib/contrast/utils/duck_utils.rb
|
911
954
|
- lib/contrast/utils/env_configuration_item.rb
|
912
|
-
- lib/contrast/utils/freeze_util.rb
|
913
|
-
- lib/contrast/utils/gemfile_reader.rb
|
914
955
|
- lib/contrast/utils/hash_digest.rb
|
915
956
|
- lib/contrast/utils/heap_dump_util.rb
|
916
957
|
- lib/contrast/utils/invalid_configuration_util.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'contrast/agent/assess/finalizers/hash'
|
5
|
-
require 'contrast/agent/assess/finalizers/freeze'
|
6
|
-
|
7
|
-
module Contrast
|
8
|
-
module Agent
|
9
|
-
module Assess
|
10
|
-
module Finalizers
|
11
|
-
# Our module for handling finalizing, allowing for the tracking of
|
12
|
-
# Objects without impacting GC and causing a memory leak. Access to any
|
13
|
-
# Finalizers object should run through this module as the Finalizers
|
14
|
-
# have tightly coupled dependencies on each other.
|
15
|
-
module Finalize
|
16
|
-
PROPERTIES_HASH = Contrast::Agent::Assess::Finalizers::Hash.new
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'contrast/agent/assess/properties'
|
5
|
-
require 'contrast/agent/assess/finalizers/finalize'
|
6
|
-
|
7
|
-
module Contrast
|
8
|
-
module Extension
|
9
|
-
module Assess
|
10
|
-
# This module is responsible for maintaining the data we need to
|
11
|
-
# construct a trace event for the object in which it is included. Rather
|
12
|
-
# than have this code all over the place, any class that wants to use
|
13
|
-
# dataflow features should be sent
|
14
|
-
# 'include Contrast::Extension::Assess::AssessExtension'
|
15
|
-
module AssessExtension
|
16
|
-
def cs__transfer_properties dup
|
17
|
-
Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH[dup] ||= Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH[self].dup
|
18
|
-
end
|
19
|
-
|
20
|
-
# Lazily build properties object. Only objects that have been tracked
|
21
|
-
# will have the @_cs__properties, but all will respond to the
|
22
|
-
# cs__properties method call. You should only call this method if you
|
23
|
-
# either intend to start tracking an object or you have already checked
|
24
|
-
# cs__tracked? and it is true.
|
25
|
-
def cs__properties
|
26
|
-
Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH[self] ||= Contrast::Agent::Assess::Properties.new
|
27
|
-
end
|
28
|
-
|
29
|
-
# This is a way to check if we are already tracking an object without
|
30
|
-
# adding tracking to it. If the object already has been tracked we will
|
31
|
-
# return the tracking state of its properties. If the object hasn't
|
32
|
-
# already been tracked we will return false without starting to track
|
33
|
-
# it
|
34
|
-
def cs__tracked?
|
35
|
-
!!Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH[self]&.tracked?
|
36
|
-
end
|
37
|
-
|
38
|
-
def cs__reset_properties
|
39
|
-
Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH[self] = nil
|
40
|
-
end
|
41
|
-
|
42
|
-
# copy tags and info from object to self if object support methods
|
43
|
-
# obj: the object from which to copy tags and events
|
44
|
-
# shift: how far to shift the tags, negative moves left
|
45
|
-
# skip_tags: array of tags to skip copying
|
46
|
-
def cs__copy_from obj, shift = 0, skip_tags = nil
|
47
|
-
return if obj.equal?(self)
|
48
|
-
return unless Contrast::Utils::DuckUtils.quacks_to?(obj,
|
49
|
-
:cs__tracked?)
|
50
|
-
return unless obj.cs__tracked?
|
51
|
-
return unless cs__properties
|
52
|
-
|
53
|
-
cs__adjust_duplicate(obj)
|
54
|
-
|
55
|
-
obj.cs__properties.events.each do |event|
|
56
|
-
cs__properties.events << event
|
57
|
-
end
|
58
|
-
|
59
|
-
obj.cs__properties.tag_keys.each do |key|
|
60
|
-
next if skip_tags&.include?(key)
|
61
|
-
|
62
|
-
new_tags = []
|
63
|
-
value = obj.cs__properties.fetch_tag(key)
|
64
|
-
value.each do |tag|
|
65
|
-
new_tags << tag.copy_modified(shift)
|
66
|
-
end
|
67
|
-
existing = cs__properties.fetch_tag(key)
|
68
|
-
if existing
|
69
|
-
existing.concat(new_tags)
|
70
|
-
Contrast::Utils::TagUtil.size_aware_merge(self, existing)
|
71
|
-
else
|
72
|
-
cs__properties.set_tags(key, new_tags)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Some propagation occurred, but we're not sure what the
|
78
|
-
# exact transformation was. To be safe, we just explode
|
79
|
-
# all the tags from the source to the return.
|
80
|
-
#
|
81
|
-
# If the return already had that tag, the existing tag
|
82
|
-
# range is recycled to save us an object.
|
83
|
-
def cs__splat_tags ret, source = self
|
84
|
-
return unless Contrast::Utils::DuckUtils.trackable?(ret)
|
85
|
-
|
86
|
-
length = Contrast::Utils::StringUtils.ret_length(ret)
|
87
|
-
return if length.zero?
|
88
|
-
|
89
|
-
cs__splat_from_source(ret, length, source)
|
90
|
-
cs__splat_from_ret(ret, length)
|
91
|
-
end
|
92
|
-
|
93
|
-
def cs__splat_from_source ret, ret_length, source
|
94
|
-
splat_source = Contrast::Utils::DuckUtils.trackable?(source)
|
95
|
-
splat_source &&= source.cs__tracked?
|
96
|
-
return unless splat_source
|
97
|
-
|
98
|
-
source.cs__properties.tag_keys.each do |key|
|
99
|
-
existing = ret.cs__properties.fetch_tag(key)
|
100
|
-
# if the tag already exists, drop all but the first range
|
101
|
-
# then change that range to cover the entire return
|
102
|
-
if existing
|
103
|
-
existing.drop(existing.length - 1)
|
104
|
-
range = existing[0]
|
105
|
-
range.repurpose(0, ret_length)
|
106
|
-
else
|
107
|
-
ret.cs__properties.add_tag(key, 0...ret_length)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def cs__splat_from_ret ret, length
|
113
|
-
return unless ret.cs__tracked?
|
114
|
-
|
115
|
-
ret.cs__properties.tag_keys.each do |key|
|
116
|
-
next unless key
|
117
|
-
|
118
|
-
existing = ret.cs__properties.fetch_tag(key)
|
119
|
-
next unless existing
|
120
|
-
|
121
|
-
existing.each do |range|
|
122
|
-
range.update_end(length) if range.end_idx > length
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
# Because of how our tracking works now, sometimes the Source and
|
130
|
-
# Target are the same, but their IDs in our map will be different due
|
131
|
-
# to PreShift duplication. To account for this, we have to ensure that
|
132
|
-
# the Object we're copying from does not have the same Properties
|
133
|
-
# that the Object we're copying to does. If they are the same, wipe the
|
134
|
-
# Target so that the copy method can update events and ranges as
|
135
|
-
# necessary.
|
136
|
-
# DO NOT TAKE THIS OUT!
|
137
|
-
def cs__adjust_duplicate obj
|
138
|
-
cs__reset_properties if obj.cs__properties == cs__properties
|
139
|
-
cs__reset_properties if obj.cs__properties.__id__ == cs__properties.dupped_from
|
140
|
-
cs__reset_properties if obj.cs__properties.dupped_from == cs__properties.__id__
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'contrast/utils/object_share'
|
5
|
-
|
6
|
-
module Contrast
|
7
|
-
module Utils
|
8
|
-
# Utility methods for asserting truthy or falsy state of a value expected
|
9
|
-
# to equate to a boolean
|
10
|
-
class BooleanUtil
|
11
|
-
class << self
|
12
|
-
def false? config
|
13
|
-
return false if config == true
|
14
|
-
return true if config == false
|
15
|
-
return false unless config.cs__is_a?(String)
|
16
|
-
|
17
|
-
Contrast::Utils::ObjectShare::FALSE.casecmp?(config)
|
18
|
-
end
|
19
|
-
|
20
|
-
def true? config
|
21
|
-
return false if config == false
|
22
|
-
return true if config == true
|
23
|
-
return false unless config.cs__is_a?(String)
|
24
|
-
|
25
|
-
Contrast::Utils::ObjectShare::TRUE.casecmp?(config)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'contrast/utils/duck_utils'
|
5
|
-
|
6
|
-
module Contrast
|
7
|
-
module Utils
|
8
|
-
# This utility allows us to act on frozen objects, creating an unfrozen
|
9
|
-
# duplicate in those cases where that is possible.
|
10
|
-
class FreezeUtil
|
11
|
-
class << self
|
12
|
-
# Make every attempt to duplicate the frozen object so that it can
|
13
|
-
# be tracked.
|
14
|
-
#
|
15
|
-
# @param original [Object] something frozen, usually a String
|
16
|
-
# @return [Object] the original or an unfrozen copy
|
17
|
-
def unfreeze_dup original
|
18
|
-
return original unless original.cs__frozen?
|
19
|
-
|
20
|
-
copy = original.dup
|
21
|
-
if Contrast::Utils::DuckUtils.iterable_hash?(copy)
|
22
|
-
copy.each_key do |key|
|
23
|
-
value = original[key]
|
24
|
-
copy[key] = value.dup
|
25
|
-
end
|
26
|
-
end
|
27
|
-
copy
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|