contrast-agent 4.8.0 → 4.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.rspec +0 -1
  4. data/.rspec_parallel +6 -0
  5. data/.simplecov +1 -0
  6. data/ext/cs__contrast_patch/cs__contrast_patch.c +0 -1
  7. data/ext/cs__contrast_patch/cs__contrast_patch.h +0 -2
  8. data/lib/contrast/agent/assess/contrast_event.rb +1 -5
  9. data/lib/contrast/agent/assess/contrast_object.rb +0 -3
  10. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -5
  11. data/lib/contrast/agent/assess/policy/patcher.rb +5 -4
  12. data/lib/contrast/agent/assess/policy/policy.rb +1 -1
  13. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -6
  14. data/lib/contrast/agent/assess/policy/preshift.rb +16 -12
  15. data/lib/contrast/agent/assess/policy/propagation_method.rb +102 -59
  16. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +2 -7
  17. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +31 -11
  18. data/lib/contrast/agent/assess/policy/propagator/remove.rb +4 -9
  19. data/lib/contrast/agent/assess/policy/propagator/split.rb +10 -6
  20. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +3 -3
  21. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +6 -7
  22. data/lib/contrast/agent/assess/policy/source_method.rb +18 -22
  23. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +0 -4
  24. data/lib/contrast/agent/assess/policy/trigger_method.rb +62 -88
  25. data/lib/contrast/agent/assess/policy/trigger_node.rb +1 -1
  26. data/lib/contrast/agent/assess/property/evented.rb +2 -1
  27. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +3 -4
  28. data/lib/contrast/agent/at_exit_hook.rb +3 -3
  29. data/lib/contrast/agent/class_reopener.rb +6 -5
  30. data/lib/contrast/agent/disable_reaction.rb +4 -5
  31. data/lib/contrast/agent/exclusion_matcher.rb +2 -7
  32. data/lib/contrast/agent/inventory/database_config.rb +117 -0
  33. data/lib/contrast/agent/inventory/dependency_analysis.rb +2 -6
  34. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +9 -10
  35. data/lib/contrast/agent/inventory/policy/datastores.rb +5 -6
  36. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  37. data/lib/contrast/agent/middleware.rb +15 -13
  38. data/lib/contrast/agent/patching/policy/after_load_patch.rb +6 -3
  39. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +21 -16
  40. data/lib/contrast/agent/patching/policy/module_policy.rb +2 -4
  41. data/lib/contrast/agent/patching/policy/patch.rb +13 -8
  42. data/lib/contrast/agent/patching/policy/patch_status.rb +3 -7
  43. data/lib/contrast/agent/patching/policy/patcher.rb +14 -14
  44. data/lib/contrast/agent/patching/policy/policy.rb +2 -4
  45. data/lib/contrast/agent/patching/policy/policy_node.rb +2 -3
  46. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +1 -1
  47. data/lib/contrast/agent/protect/policy/policy.rb +1 -1
  48. data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -5
  49. data/lib/contrast/agent/protect/rule/base.rb +10 -10
  50. data/lib/contrast/agent/protect/rule/cmd_injection.rb +4 -5
  51. data/lib/contrast/agent/protect/rule/no_sqli.rb +7 -53
  52. data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -5
  53. data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +137 -0
  54. data/lib/contrast/agent/protect/rule/sqli.rb +7 -70
  55. data/lib/contrast/agent/reaction_processor.rb +3 -4
  56. data/lib/contrast/agent/request.rb +13 -7
  57. data/lib/contrast/agent/request_context.rb +36 -34
  58. data/lib/contrast/agent/request_handler.rb +5 -3
  59. data/lib/contrast/agent/response.rb +2 -3
  60. data/lib/contrast/agent/rewriter.rb +4 -3
  61. data/lib/contrast/agent/rule_set.rb +5 -4
  62. data/lib/contrast/agent/scope.rb +32 -20
  63. data/lib/contrast/agent/service_heartbeat.rb +2 -3
  64. data/lib/contrast/agent/static_analysis.rb +7 -6
  65. data/lib/contrast/agent/thread.rb +2 -4
  66. data/lib/contrast/agent/thread_watcher.rb +3 -4
  67. data/lib/contrast/agent/tracepoint_hook.rb +20 -7
  68. data/lib/contrast/agent/version.rb +1 -1
  69. data/lib/contrast/api/communication/messaging_queue.rb +16 -11
  70. data/lib/contrast/api/communication/response_processor.rb +11 -11
  71. data/lib/contrast/api/communication/service_lifecycle.rb +9 -5
  72. data/lib/contrast/api/communication/socket_client.rb +18 -14
  73. data/lib/contrast/api/communication/speedracer.rb +5 -6
  74. data/lib/contrast/api/decorators/address.rb +2 -3
  75. data/lib/contrast/api/decorators/agent_startup.rb +7 -9
  76. data/lib/contrast/api/decorators/application_startup.rb +9 -10
  77. data/lib/contrast/api/decorators/application_update.rb +0 -4
  78. data/lib/contrast/api/decorators/http_request.rb +3 -7
  79. data/lib/contrast/api/decorators/instrumentation_mode.rb +3 -5
  80. data/lib/contrast/api/decorators/message.rb +7 -7
  81. data/lib/contrast/api/decorators/route_coverage.rb +24 -1
  82. data/lib/contrast/api/decorators/trace_event_object.rb +2 -3
  83. data/lib/contrast/components/agent.rb +13 -15
  84. data/lib/contrast/components/app_context.rb +7 -11
  85. data/lib/contrast/components/assess.rb +19 -16
  86. data/lib/contrast/components/base.rb +40 -0
  87. data/lib/contrast/components/config.rb +1 -2
  88. data/lib/contrast/components/contrast_service.rb +8 -11
  89. data/lib/contrast/components/heap_dump.rb +5 -4
  90. data/lib/contrast/components/inventory.rb +2 -7
  91. data/lib/contrast/components/logger.rb +14 -10
  92. data/lib/contrast/components/protect.rb +10 -13
  93. data/lib/contrast/components/sampling.rb +5 -5
  94. data/lib/contrast/components/scope.rb +9 -32
  95. data/lib/contrast/components/settings.rb +1 -5
  96. data/lib/contrast/config/base_configuration.rb +14 -6
  97. data/lib/contrast/configuration.rb +22 -19
  98. data/lib/contrast/extension/assess/array.rb +3 -15
  99. data/lib/contrast/extension/assess/eval_trigger.rb +2 -23
  100. data/lib/contrast/extension/assess/fiber.rb +6 -16
  101. data/lib/contrast/extension/assess/hash.rb +3 -13
  102. data/lib/contrast/extension/assess/kernel.rb +3 -14
  103. data/lib/contrast/extension/assess/marshal.rb +6 -14
  104. data/lib/contrast/extension/assess/regexp.rb +5 -15
  105. data/lib/contrast/extension/assess/string.rb +6 -31
  106. data/lib/contrast/extension/extension.rb +61 -0
  107. data/lib/contrast/extension/kernel.rb +2 -4
  108. data/lib/contrast/extension/protect/kernel.rb +0 -15
  109. data/lib/contrast/framework/grape/support.rb +174 -0
  110. data/lib/contrast/framework/manager.rb +44 -9
  111. data/lib/contrast/framework/rack/patch/session_cookie.rb +6 -6
  112. data/lib/contrast/framework/rack/support.rb +1 -1
  113. data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -8
  114. data/lib/contrast/framework/rails/patch/support.rb +43 -36
  115. data/lib/contrast/framework/rails/railtie.rb +8 -6
  116. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
  117. data/lib/contrast/framework/rails/support.rb +60 -13
  118. data/lib/contrast/framework/sinatra/support.rb +1 -1
  119. data/lib/contrast/funchook/funchook.rb +4 -3
  120. data/lib/contrast/logger/application.rb +1 -6
  121. data/lib/contrast/logger/log.rb +103 -13
  122. data/lib/contrast/logger/request.rb +0 -4
  123. data/lib/contrast/tasks/config.rb +0 -1
  124. data/lib/contrast/tasks/service.rb +1 -6
  125. data/lib/contrast/utils/assess/sampling_util.rb +2 -3
  126. data/lib/contrast/utils/assess/tracking_util.rb +2 -4
  127. data/lib/contrast/utils/class_util.rb +26 -19
  128. data/lib/contrast/utils/heap_dump_util.rb +5 -3
  129. data/lib/contrast/utils/invalid_configuration_util.rb +4 -3
  130. data/lib/contrast/utils/io_util.rb +46 -40
  131. data/lib/contrast/utils/job_servers_running.rb +4 -3
  132. data/lib/contrast/utils/lru_cache.rb +43 -0
  133. data/lib/contrast/utils/os.rb +2 -3
  134. data/lib/contrast/utils/ruby_ast_rewriter.rb +16 -13
  135. data/lib/contrast/utils/string_utils.rb +2 -3
  136. data/lib/contrast/utils/tag_util.rb +26 -19
  137. data/lib/contrast.rb +24 -14
  138. data/resources/assess/policy.json +197 -2
  139. data/resources/deadzone/policy.json +10 -0
  140. data/ruby-agent.gemspec +13 -3
  141. data/service_executables/VERSION +1 -1
  142. data/service_executables/linux/contrast-service +0 -0
  143. data/service_executables/mac/contrast-service +0 -0
  144. metadata +91 -25
  145. data/lib/contrast/components/interface.rb +0 -196
  146. data/lib/contrast/delegators/input_analysis.rb +0 -12
  147. data/lib/contrast/utils/inventory_util.rb +0 -114
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.8.0
4
+ version: 4.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - galen.palmer@contrastsecurity.com
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: exe
15
15
  cert_chain: []
16
- date: 2021-05-20 00:00:00.000000000 Z
16
+ date: 2021-09-23 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: bundler
@@ -71,6 +71,20 @@ dependencies:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
+ - !ruby/object:Gem::Dependency
75
+ name: pry-byebug
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '3.9'
81
+ type: :development
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '3.9'
74
88
  - !ruby/object:Gem::Dependency
75
89
  name: ruby-debug-ide
76
90
  requirement: !ruby/object:Gem::Requirement
@@ -198,33 +212,39 @@ dependencies:
198
212
  - !ruby/object:Gem::Version
199
213
  version: 2.2.0
200
214
  - !ruby/object:Gem::Dependency
201
- name: codecov
215
+ name: simplecov
202
216
  requirement: !ruby/object:Gem::Requirement
203
217
  requirements:
204
218
  - - '='
205
219
  - !ruby/object:Gem::Version
206
- version: 0.5.2
220
+ version: 0.21.2
207
221
  type: :development
208
222
  prerelease: false
209
223
  version_requirements: !ruby/object:Gem::Requirement
210
224
  requirements:
211
225
  - - '='
212
226
  - !ruby/object:Gem::Version
213
- version: 0.5.2
227
+ version: 0.21.2
214
228
  - !ruby/object:Gem::Dependency
215
- name: simplecov
229
+ name: grape
216
230
  requirement: !ruby/object:Gem::Requirement
217
231
  requirements:
218
- - - '='
232
+ - - "~>"
219
233
  - !ruby/object:Gem::Version
220
- version: 0.21.2
234
+ version: '1.5'
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: 1.5.2
221
238
  type: :development
222
239
  prerelease: false
223
240
  version_requirements: !ruby/object:Gem::Requirement
224
241
  requirements:
225
- - - '='
242
+ - - "~>"
226
243
  - !ruby/object:Gem::Version
227
- version: 0.21.2
244
+ version: '1.5'
245
+ - - ">="
246
+ - !ruby/object:Gem::Version
247
+ version: 1.5.2
228
248
  - !ruby/object:Gem::Dependency
229
249
  name: rack-protection
230
250
  requirement: !ruby/object:Gem::Requirement
@@ -296,7 +316,7 @@ dependencies:
296
316
  - !ruby/object:Gem::Version
297
317
  version: '0'
298
318
  - !ruby/object:Gem::Dependency
299
- name: sqlite3
319
+ name: rhino
300
320
  requirement: !ruby/object:Gem::Requirement
301
321
  requirements:
302
322
  - - ">="
@@ -310,7 +330,7 @@ dependencies:
310
330
  - !ruby/object:Gem::Version
311
331
  version: '0'
312
332
  - !ruby/object:Gem::Dependency
313
- name: rhino
333
+ name: sqlite3
314
334
  requirement: !ruby/object:Gem::Requirement
315
335
  requirements:
316
336
  - - ">="
@@ -421,6 +441,20 @@ dependencies:
421
441
  - - ">="
422
442
  - !ruby/object:Gem::Version
423
443
  version: '0'
444
+ - !ruby/object:Gem::Dependency
445
+ name: parallel_tests
446
+ requirement: !ruby/object:Gem::Requirement
447
+ requirements:
448
+ - - ">="
449
+ - !ruby/object:Gem::Version
450
+ version: '0'
451
+ type: :development
452
+ prerelease: false
453
+ version_requirements: !ruby/object:Gem::Requirement
454
+ requirements:
455
+ - - ">="
456
+ - !ruby/object:Gem::Version
457
+ version: '0'
424
458
  - !ruby/object:Gem::Dependency
425
459
  name: rspec
426
460
  requirement: !ruby/object:Gem::Requirement
@@ -491,6 +525,34 @@ dependencies:
491
525
  - - ">="
492
526
  - !ruby/object:Gem::Version
493
527
  version: '0'
528
+ - !ruby/object:Gem::Dependency
529
+ name: warning
530
+ requirement: !ruby/object:Gem::Requirement
531
+ requirements:
532
+ - - ">="
533
+ - !ruby/object:Gem::Version
534
+ version: '0'
535
+ type: :development
536
+ prerelease: false
537
+ version_requirements: !ruby/object:Gem::Requirement
538
+ requirements:
539
+ - - ">="
540
+ - !ruby/object:Gem::Version
541
+ version: '0'
542
+ - !ruby/object:Gem::Dependency
543
+ name: zlib
544
+ requirement: !ruby/object:Gem::Requirement
545
+ requirements:
546
+ - - ">="
547
+ - !ruby/object:Gem::Version
548
+ version: '0'
549
+ type: :development
550
+ prerelease: false
551
+ version_requirements: !ruby/object:Gem::Requirement
552
+ requirements:
553
+ - - ">="
554
+ - !ruby/object:Gem::Version
555
+ version: '0'
494
556
  - !ruby/object:Gem::Dependency
495
557
  name: ougai
496
558
  requirement: !ruby/object:Gem::Requirement
@@ -555,20 +617,20 @@ executables:
555
617
  - contrast_service
556
618
  extensions:
557
619
  - ext/cs__common/extconf.rb
558
- - ext/cs__assess_string/extconf.rb
559
- - ext/cs__assess_kernel/extconf.rb
560
- - ext/cs__protect_kernel/extconf.rb
561
- - ext/cs__assess_module/extconf.rb
562
- - ext/cs__assess_active_record_named/extconf.rb
563
- - ext/cs__assess_fiber_track/extconf.rb
564
620
  - ext/cs__assess_array/extconf.rb
565
- - ext/cs__contrast_patch/extconf.rb
566
- - ext/cs__assess_string_interpolation26/extconf.rb
567
621
  - ext/cs__assess_regexp/extconf.rb
622
+ - ext/cs__protect_kernel/extconf.rb
568
623
  - ext/cs__assess_marshal_module/extconf.rb
569
- - ext/cs__assess_basic_object/extconf.rb
570
- - ext/cs__assess_hash/extconf.rb
571
624
  - ext/cs__assess_yield_track/extconf.rb
625
+ - ext/cs__assess_string_interpolation26/extconf.rb
626
+ - ext/cs__assess_fiber_track/extconf.rb
627
+ - ext/cs__assess_string/extconf.rb
628
+ - ext/cs__assess_hash/extconf.rb
629
+ - ext/cs__assess_kernel/extconf.rb
630
+ - ext/cs__contrast_patch/extconf.rb
631
+ - ext/cs__assess_basic_object/extconf.rb
632
+ - ext/cs__assess_module/extconf.rb
633
+ - ext/cs__assess_active_record_named/extconf.rb
572
634
  extra_rdoc_files: []
573
635
  files:
574
636
  - ".clang-format"
@@ -577,6 +639,7 @@ files:
577
639
  - ".gitignore"
578
640
  - ".gitmodules"
579
641
  - ".rspec"
642
+ - ".rspec_parallel"
580
643
  - ".simplecov"
581
644
  - Gemfile
582
645
  - LICENSE.txt
@@ -828,6 +891,7 @@ files:
828
891
  - lib/contrast/agent/disable_reaction.rb
829
892
  - lib/contrast/agent/exclusion_matcher.rb
830
893
  - lib/contrast/agent/inventory.rb
894
+ - lib/contrast/agent/inventory/database_config.rb
831
895
  - lib/contrast/agent/inventory/dependencies.rb
832
896
  - lib/contrast/agent/inventory/dependency_analysis.rb
833
897
  - lib/contrast/agent/inventory/dependency_usage_analysis.rb
@@ -865,6 +929,7 @@ files:
865
929
  - lib/contrast/agent/protect/rule/no_sqli.rb
866
930
  - lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb
867
931
  - lib/contrast/agent/protect/rule/path_traversal.rb
932
+ - lib/contrast/agent/protect/rule/sql_sample_builder.rb
868
933
  - lib/contrast/agent/protect/rule/sqli.rb
869
934
  - lib/contrast/agent/protect/rule/sqli/default_sql_scanner.rb
870
935
  - lib/contrast/agent/protect/rule/sqli/mysql_sql_scanner.rb
@@ -927,10 +992,10 @@ files:
927
992
  - lib/contrast/components/agent.rb
928
993
  - lib/contrast/components/app_context.rb
929
994
  - lib/contrast/components/assess.rb
995
+ - lib/contrast/components/base.rb
930
996
  - lib/contrast/components/config.rb
931
997
  - lib/contrast/components/contrast_service.rb
932
998
  - lib/contrast/components/heap_dump.rb
933
- - lib/contrast/components/interface.rb
934
999
  - lib/contrast/components/inventory.rb
935
1000
  - lib/contrast/components/logger.rb
936
1001
  - lib/contrast/components/protect.rb
@@ -957,7 +1022,6 @@ files:
957
1022
  - lib/contrast/config/server_configuration.rb
958
1023
  - lib/contrast/config/service_configuration.rb
959
1024
  - lib/contrast/configuration.rb
960
- - lib/contrast/delegators/input_analysis.rb
961
1025
  - lib/contrast/extension/assess.rb
962
1026
  - lib/contrast/extension/assess/array.rb
963
1027
  - lib/contrast/extension/assess/erb.rb
@@ -970,6 +1034,7 @@ files:
970
1034
  - lib/contrast/extension/assess/regexp.rb
971
1035
  - lib/contrast/extension/assess/string.rb
972
1036
  - lib/contrast/extension/delegator.rb
1037
+ - lib/contrast/extension/extension.rb
973
1038
  - lib/contrast/extension/inventory.rb
974
1039
  - lib/contrast/extension/kernel.rb
975
1040
  - lib/contrast/extension/module.rb
@@ -978,6 +1043,7 @@ files:
978
1043
  - lib/contrast/extension/protect/psych.rb
979
1044
  - lib/contrast/extension/thread.rb
980
1045
  - lib/contrast/framework/base_support.rb
1046
+ - lib/contrast/framework/grape/support.rb
981
1047
  - lib/contrast/framework/manager.rb
982
1048
  - lib/contrast/framework/platform_version.rb
983
1049
  - lib/contrast/framework/rack/patch/session_cookie.rb
@@ -1011,9 +1077,9 @@ files:
1011
1077
  - lib/contrast/utils/hash_digest.rb
1012
1078
  - lib/contrast/utils/heap_dump_util.rb
1013
1079
  - lib/contrast/utils/invalid_configuration_util.rb
1014
- - lib/contrast/utils/inventory_util.rb
1015
1080
  - lib/contrast/utils/io_util.rb
1016
1081
  - lib/contrast/utils/job_servers_running.rb
1082
+ - lib/contrast/utils/lru_cache.rb
1017
1083
  - lib/contrast/utils/object_share.rb
1018
1084
  - lib/contrast/utils/os.rb
1019
1085
  - lib/contrast/utils/preflight_util.rb
@@ -1,196 +0,0 @@
1
- # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- require 'delegate'
5
- require 'contrast/extension/module'
6
- require 'contrast/utils/object_share'
7
-
8
- module Contrast
9
- # This is the base module for our components classes. It is intended to
10
- # facilitate the translation of the Common Configuration settings to usable
11
- # Ruby methods. Any class under this namespace should be required here,
12
- # providing a single point of require for this functionality.
13
- module Components
14
- # Include this into your classes and modules,
15
- # and use 'access_component' to define constants that will allow
16
- # interaction with other components.
17
- module Interface
18
- def self.included klass
19
- # Upon inclusion, ComponentInterfaces extends the including with
20
- # these two interfaces.
21
- # Interface provides a class-level method 'access_component'
22
- # that regulates per-class access to agent state.
23
- # (It's a glorified `include MyComponent`).
24
- klass.extend Contrast::Components::ComponentReceiverClassInterface
25
- end
26
- end
27
-
28
- # All component access is gated through delegators.
29
- #
30
- # One delegator is used by the calling class,
31
- # so we can tweak outgoing calls.
32
- #
33
- # The second delegator is used by the receiving component,
34
- # so we can tweak incoming calls.
35
- #
36
- # We use __setobj__ to decide which component implementation to use.
37
- # This is intended to provide flexibility in design and
38
- # simplicity in testing.
39
- class ComponentDelegator < SimpleDelegator
40
- # intentionally left blank
41
- end
42
-
43
- # All components should inherit from this,
44
- # whether Interfaces, InstanceMethods or ClassMethods.
45
- module ComponentBase
46
- def self.included klass
47
- klass.extend Methods
48
- klass.include Methods
49
- end
50
-
51
- module Methods # :nodoc:
52
- # use this to determine if the configuration value is literally boolean
53
- # false or some form of the word `false`, regardless of case. It should
54
- # be used for those values which default to `true` as they should only
55
- # treat a value explicitly set to `false` as such.
56
- #
57
- # @param config_param [Boolean,String] the value to check
58
- # @return [Boolean] should the value be treated as `false`
59
- def false? config_param
60
- return false if config_param == true
61
- return true if config_param == false
62
- return false unless config_param.cs__is_a?(String)
63
-
64
- Contrast::Utils::ObjectShare::FALSE.casecmp?(config_param)
65
- end
66
-
67
- # use this to determine if the configuration value is literally boolean
68
- # true or some form of the word `true`, regardless of case. It should
69
- # be used for those values which default to `false` as they should only
70
- # treat a value explicitly set to `true` as such.
71
- #
72
- # @param config_param [Boolean,String] the value to check
73
- # @return [Boolean] should the value be treated as `true`
74
- def true? config_param
75
- return false if config_param == false
76
- return true if config_param == true
77
- return false unless config_param.cs__is_a?(String)
78
-
79
- Contrast::Utils::ObjectShare::TRUE.casecmp?(config_param)
80
- end
81
- end
82
- end
83
-
84
- def self.component_const_name mod_name
85
- mod_name = mod_name.split('::').last
86
- @cache ||= {}
87
- @cache[mod_name] ||= mod_name. # CamelCaseName
88
- split(/(?=[A-Z])/)&. # ['Camel', 'Case', 'Name']
89
- map(&:upcase)&. # ['CAMEL', 'CASE', 'NAME']
90
- join('_') # 'CAMEL_CASE_NAME'
91
- end
92
-
93
- # Interface to allow for iteration over each of the configuration
94
- # components
95
- module ComponentReceiverClassInterface
96
- # Components are manually required at the end of
97
- # this file, and this constant is then frozen.
98
- # RUBY-535 to handle this better.
99
- COMPONENT_MAP = {} # rubocop:disable Style/MutableConstant
100
-
101
- # TODO: RUBY-535
102
- # This module is used via `extend`, so it can't access
103
- # constants we define here.
104
- def component_map
105
- COMPONENT_MAP
106
- end
107
-
108
- # .access_component
109
- #
110
- # to be used as:
111
- #
112
- # class Abc
113
- # include Contrast::Components::Interface
114
- # access_component :logging, :agent
115
- #
116
- # def function
117
- # if AGENT.disabled?
118
- # 0 / 3
119
- # end
120
- # rescue
121
- # logger.error "this function did error"
122
- # end
123
- # end
124
- #
125
- # `:logger` creates a #logger and .logger method
126
- # `:agent` provides an AGENT constant, analogous to a local singleton.
127
- #
128
- def access_component *component_set_syms
129
- @_access_component ||= {}
130
-
131
- component_set_syms.each do |sym|
132
- next if @_access_component[sym]
133
-
134
- if (mods = component_map[sym]) # rubocop:disable Style/GuardClause
135
- # We may support multiple components via one access request.
136
- mods.each do |m|
137
- name = Contrast::Components.component_const_name(m.cs__name)
138
- cs__const_set(name, m::COMPONENT_INTERFACE) if m.cs__const_defined?(:COMPONENT_INTERFACE)
139
- include m::InstanceMethods if m.cs__const_defined?(:InstanceMethods, false)
140
- extend m::ClassMethods if m.cs__const_defined?(:ClassMethods, false)
141
- end
142
-
143
- @_access_component[sym] = true
144
- else
145
- raise NoMethodError, "#{ self } asked to access undefined component '#{ sym }'."
146
- end
147
- end
148
- end
149
- end
150
- end
151
- end
152
-
153
- # Components can depend on other components, but it should be a
154
- # directed acyclic graph.
155
-
156
- # Scope shouldn't depend on anything.
157
- require 'contrast/components/scope'
158
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:scope] = [Contrast::Components::Scope]
159
-
160
- # Config depends on Scope.
161
- require 'contrast/components/config'
162
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:config] = [Contrast::Components::Config]
163
-
164
- # Settings should not depend on anything but Config.
165
- require 'contrast/components/settings'
166
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:settings] = [Contrast::Components::Settings]
167
-
168
- require 'contrast/components/assess'
169
- require 'contrast/components/protect'
170
- require 'contrast/components/inventory'
171
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:analysis] = [
172
- Contrast::Components::Protect,
173
- Contrast::Components::Assess,
174
- Contrast::Components::Inventory
175
- ]
176
-
177
- require 'contrast/components/logger'
178
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:logging] = [Contrast::Components::Logger]
179
-
180
- require 'contrast/components/agent'
181
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:agent] = [Contrast::Components::Agent]
182
-
183
- require 'contrast/components/contrast_service'
184
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:contrast_service] =
185
- [Contrast::Components::ContrastService]
186
-
187
- require 'contrast/components/app_context'
188
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:app_context] = [Contrast::Components::AppContext]
189
-
190
- require 'contrast/components/heap_dump'
191
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:heap_dump] = [Contrast::Components::HeapDump]
192
-
193
- require 'contrast/components/sampling'
194
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:sampling] = [Contrast::Components::Sampling]
195
-
196
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP.cs__freeze
@@ -1,12 +0,0 @@
1
- # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- module Contrast
5
- module Delegators
6
- # Used to decorate the InputAnalysis protobuf model so it can own the
7
- # Contrast::Agent::Request from which it came.
8
- class InputAnalysis < SimpleDelegator
9
- attr_accessor :request
10
- end
11
- end
12
- end
@@ -1,114 +0,0 @@
1
- # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- require 'contrast/utils/timer'
5
- require 'contrast/utils/object_share'
6
- require 'contrast/components/interface'
7
-
8
- module Contrast
9
- module Utils
10
- # Utilities for getting inventory information from the application
11
- class InventoryUtil
12
- include Contrast::Components::Interface
13
- access_component :logging
14
-
15
- # TeamServer only accepts certain values for ArchitectureComponents.
16
- # DO NOT CHANGE THIS!
17
- AC_TYPE_DB = 'db'
18
- # TeamServer only accepts certain values for FlowMap Services.
19
- # DO NOT CHANGE THIS
20
- ADAPTER = 'adapter'
21
- HOST = 'host'
22
- PORT = 'port'
23
- DATABASE = 'database'
24
- DEFAULT = 'default'
25
- LOCALHOST = 'localhost'
26
-
27
- def self.active_record_config
28
- return @_active_record_config if instance_variable_defined?(:@_active_record_config)
29
-
30
- @_active_record_config = ActiveRecord::Base.connection_config rescue nil # rubocop:disable Style/RescueModifier
31
- end
32
-
33
- def self.append_db_config activity_or_update, hash_or_str = Contrast::Utils::InventoryUtil.active_record_config
34
- arr = build_from_db_config(hash_or_str)
35
- return unless arr&.any?
36
-
37
- arr.each do |a|
38
- next unless a
39
-
40
- if activity_or_update.is_a?(Contrast::Api::Dtm::Activity)
41
- activity_or_update.architectures << a
42
- else
43
- activity_or_update.components << a
44
- end
45
- end
46
- rescue StandardError => e
47
- logger.error('Unable to append db config', e)
48
- nil
49
- end
50
-
51
- def self.build_from_db_config hash_or_str
52
- return unless hash_or_str
53
-
54
- if hash_or_str.is_a?(Hash)
55
- build_from_db_hash(hash_or_str)
56
- else
57
- build_from_db_string(hash_or_str.to_s)
58
- end
59
- end
60
-
61
- def self.build_from_db_hash hash
62
- ac = Contrast::Api::Dtm::ArchitectureComponent.new
63
- ac.vendor = hash[:adapter] || hash[ADAPTER] || Contrast::Utils::ObjectShare::EMPTY_STRING
64
- ac.remote_host = host_from_hash(hash)
65
- ac.remote_port = port_from_hash(hash)
66
- ac.type = AC_TYPE_DB
67
- ac.url = hash[:database] || hash[DATABASE] || DEFAULT
68
- [ac]
69
- end
70
-
71
- def self.host_from_hash hash
72
- hash[:host] || hash[HOST] || Contrast::Utils::ObjectShare::EMPTY_STRING
73
- end
74
-
75
- def self.port_from_hash hash
76
- p = hash[:port] || hash[PORT] || Contrast::Utils::ObjectShare::EMPTY_STRING
77
- p.to_i
78
- end
79
-
80
- # Examples:
81
- # mongodb://[user:pass@]host1[:port1][,host2[:port2],[,hostN[:portN]]][/[database][?options]]
82
- # postgresql://scott:tiger@localhost/mydatabase
83
- # mysql+mysqlconnector://scott:tiger@localhost/foo
84
- def self.build_from_db_string str
85
- adapter, hosts, database = split_connection_str(str)
86
- acs = []
87
- hosts.split(Contrast::Utils::ObjectShare::COMMA).map do |s|
88
- host, port = s.split(Contrast::Utils::ObjectShare::COLON)
89
-
90
- ac = Contrast::Api::Dtm::ArchitectureComponent.new
91
- ac.vendor = Contrast::Utils::StringUtils.force_utf8(adapter)
92
- ac.remote_host = Contrast::Utils::StringUtils.force_utf8(host)
93
- ac.remote_port = port.to_i
94
- ac.type = AC_TYPE_DB
95
- ac.url = Contrast::Utils::StringUtils.force_utf8(database)
96
- acs << ac
97
- end
98
- acs
99
- end
100
-
101
- def self.split_connection_str str
102
- adapter, str = str.split(Contrast::Utils::ObjectShare::COLON_SLASH_SLASH)
103
- _auth, str = str.split(Contrast::Utils::ObjectShare::AT)
104
- # Not currently used
105
- # user, pass = auth.split(Contrast::Utils::ObjectShare::COLON)
106
- hosts, db_and_options = str.split(Contrast::Utils::ObjectShare::SLASH)
107
- hosts << LOCALHOST if hosts.empty?
108
- database, _options = db_and_options.split(Contrast::Utils::ObjectShare::QUESTION_MARK)
109
-
110
- [adapter, hosts, database]
111
- end
112
- end
113
- end
114
- end