contrast-agent 4.9.1 → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -1
  3. data/.rspec_parallel +6 -0
  4. data/ext/cs__contrast_patch/cs__contrast_patch.c +0 -1
  5. data/ext/cs__contrast_patch/cs__contrast_patch.h +0 -2
  6. data/lib/contrast/agent/assess/contrast_event.rb +0 -1
  7. data/lib/contrast/agent/assess/finalizers/hash.rb +0 -1
  8. data/lib/contrast/agent/assess/policy/patcher.rb +0 -1
  9. data/lib/contrast/agent/assess/policy/policy_scanner.rb +0 -2
  10. data/lib/contrast/agent/assess/policy/preshift.rb +8 -5
  11. data/lib/contrast/agent/assess/policy/propagation_method.rb +100 -57
  12. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +0 -2
  13. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +31 -11
  14. data/lib/contrast/agent/assess/policy/propagator/split.rb +3 -2
  15. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -0
  16. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +0 -1
  17. data/lib/contrast/agent/assess/policy/source_method.rb +13 -17
  18. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +0 -1
  19. data/lib/contrast/agent/assess/policy/trigger_method.rb +59 -83
  20. data/lib/contrast/agent/assess/property/evented.rb +2 -1
  21. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +0 -1
  22. data/lib/contrast/agent/disable_reaction.rb +1 -1
  23. data/lib/contrast/agent/exclusion_matcher.rb +0 -4
  24. data/lib/contrast/agent/inventory/database_config.rb +117 -0
  25. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +5 -4
  26. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
  27. data/lib/contrast/agent/middleware.rb +1 -0
  28. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -0
  29. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +18 -12
  30. data/lib/contrast/agent/patching/policy/module_policy.rb +2 -4
  31. data/lib/contrast/agent/patching/policy/patch.rb +5 -0
  32. data/lib/contrast/agent/patching/policy/patch_status.rb +3 -7
  33. data/lib/contrast/agent/patching/policy/patcher.rb +8 -8
  34. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +1 -1
  35. data/lib/contrast/agent/protect/rule/no_sqli.rb +7 -53
  36. data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +137 -0
  37. data/lib/contrast/agent/protect/rule/sqli.rb +7 -70
  38. data/lib/contrast/agent/reaction_processor.rb +1 -1
  39. data/lib/contrast/agent/request.rb +5 -2
  40. data/lib/contrast/agent/request_context.rb +19 -22
  41. data/lib/contrast/agent/static_analysis.rb +1 -1
  42. data/lib/contrast/agent/tracepoint_hook.rb +6 -1
  43. data/lib/contrast/agent/version.rb +1 -1
  44. data/lib/contrast/api/communication/messaging_queue.rb +12 -6
  45. data/lib/contrast/api/communication/service_lifecycle.rb +4 -1
  46. data/lib/contrast/api/communication/socket_client.rb +4 -4
  47. data/lib/contrast/api/decorators/agent_startup.rb +4 -4
  48. data/lib/contrast/api/decorators/application_startup.rb +6 -5
  49. data/lib/contrast/api/decorators/route_coverage.rb +24 -1
  50. data/lib/contrast/components/agent.rb +5 -2
  51. data/lib/contrast/components/assess.rb +6 -3
  52. data/lib/contrast/components/base.rb +2 -2
  53. data/lib/contrast/components/config.rb +1 -0
  54. data/lib/contrast/components/contrast_service.rb +4 -2
  55. data/lib/contrast/components/logger.rb +13 -8
  56. data/lib/contrast/components/scope.rb +9 -28
  57. data/lib/contrast/config/base_configuration.rb +14 -6
  58. data/lib/contrast/configuration.rb +19 -15
  59. data/lib/contrast/extension/assess/array.rb +1 -11
  60. data/lib/contrast/extension/assess/eval_trigger.rb +0 -20
  61. data/lib/contrast/extension/assess/fiber.rb +0 -11
  62. data/lib/contrast/extension/assess/hash.rb +0 -10
  63. data/lib/contrast/extension/assess/kernel.rb +1 -10
  64. data/lib/contrast/extension/assess/marshal.rb +3 -11
  65. data/lib/contrast/extension/assess/regexp.rb +0 -11
  66. data/lib/contrast/extension/assess/string.rb +1 -26
  67. data/lib/contrast/extension/extension.rb +61 -0
  68. data/lib/contrast/extension/protect/kernel.rb +0 -10
  69. data/lib/contrast/framework/grape/support.rb +174 -0
  70. data/lib/contrast/framework/manager.rb +42 -6
  71. data/lib/contrast/framework/rack/support.rb +1 -1
  72. data/lib/contrast/framework/rails/patch/assess_configuration.rb +0 -1
  73. data/lib/contrast/framework/rails/patch/support.rb +6 -3
  74. data/lib/contrast/framework/rails/railtie.rb +1 -1
  75. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +1 -0
  76. data/lib/contrast/framework/rails/support.rb +60 -13
  77. data/lib/contrast/framework/sinatra/support.rb +1 -1
  78. data/lib/contrast/logger/log.rb +89 -15
  79. data/lib/contrast/utils/io_util.rb +1 -1
  80. data/lib/contrast/utils/ruby_ast_rewriter.rb +16 -13
  81. data/lib/contrast/utils/tag_util.rb +2 -1
  82. data/resources/assess/policy.json +197 -2
  83. data/resources/deadzone/policy.json +10 -0
  84. data/ruby-agent.gemspec +10 -1
  85. metadata +78 -12
  86. data/lib/contrast/utils/inventory_util.rb +0 -113
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "deadzones":[
3
3
  {
4
+ "class_name":"Rspec::Core::BacktraceFormatter",
5
+ "instance_method":true,
6
+ "method_visibility": "private",
7
+ "method_name":"matches?"
8
+ },{
9
+ "class_name":"Rspec::Core::Example",
10
+ "instance_method":true,
11
+ "method_visibility": "private",
12
+ "method_name":"finish"
13
+ },{
4
14
  "class_name":"Rack::Request::Helpers",
5
15
  "instance_method":true,
6
16
  "method_visibility": "public",
data/ruby-agent.gemspec CHANGED
@@ -24,6 +24,7 @@ def self.add_dev_dependencies spec
24
24
  add_debuggers(spec)
25
25
  add_linters(spec) # if RUBY_VERSION >= '2.6.0' # TODO: RUBY-714 remove guard w/ EOL of 2.5
26
26
  add_specs(spec)
27
+ add_custom_dependencies(spec)
27
28
  end
28
29
 
29
30
  # Dependencies used to build the agent during development.
@@ -33,14 +34,21 @@ def self.add_builders spec
33
34
  spec.add_development_dependency 'rake-compiler', '~> 0'
34
35
  end
35
36
 
37
+ # Dependencies that are required during testing in actual application
38
+ def self.add_custom_dependencies spec
39
+ spec.add_development_dependency 'zlib'
40
+ end
41
+
36
42
  # Dependencies used for local debugging during development.
37
43
  def self.add_debuggers spec
38
44
  spec.add_development_dependency 'pry'
45
+ spec.add_development_dependency 'pry-byebug', '>= 3.9'
39
46
  spec.add_development_dependency 'ruby-debug-ide'
40
47
  end
41
48
 
42
49
  # Dependencies used for framework testing.
43
50
  def self.add_frameworks spec
51
+ spec.add_development_dependency 'grape', '~> 1.5', '>= 1.5.2'
44
52
  spec.add_development_dependency 'rack-protection', '>= 2'
45
53
  spec.add_development_dependency 'rails', '6.0.3.5'
46
54
  spec.add_development_dependency 'sinatra', '>= 2'
@@ -66,12 +74,13 @@ def self.add_specs spec
66
74
  spec.add_development_dependency 'factory_bot'
67
75
  spec.add_development_dependency 'fake_ftp'
68
76
  spec.add_development_dependency 'openssl'
77
+ spec.add_development_dependency 'parallel_tests'
69
78
  spec.add_development_dependency 'rspec', '~> 3.0'
70
79
  spec.add_development_dependency 'rspec-benchmark'
71
80
  spec.add_development_dependency 'rspec_junit_formatter', '0.3.0'
72
81
  spec.add_development_dependency 'rspec-rails', '5.0'
73
- spec.add_development_dependency 'warning'
74
82
  spec.add_development_dependency 'tzinfo-data' # Alpine rspec-rails requirement.
83
+ spec.add_development_dependency 'warning'
75
84
  end
76
85
 
77
86
  def self.add_coverage spec
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.9.1
4
+ version: 4.10.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-07-15 00:00:00.000000000 Z
16
+ date: 2021-08-31 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
@@ -211,6 +225,26 @@ dependencies:
211
225
  - - '='
212
226
  - !ruby/object:Gem::Version
213
227
  version: 0.21.2
228
+ - !ruby/object:Gem::Dependency
229
+ name: grape
230
+ requirement: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - "~>"
233
+ - !ruby/object:Gem::Version
234
+ version: '1.5'
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: 1.5.2
238
+ type: :development
239
+ prerelease: false
240
+ version_requirements: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - "~>"
243
+ - !ruby/object:Gem::Version
244
+ version: '1.5'
245
+ - - ">="
246
+ - !ruby/object:Gem::Version
247
+ version: 1.5.2
214
248
  - !ruby/object:Gem::Dependency
215
249
  name: rack-protection
216
250
  requirement: !ruby/object:Gem::Requirement
@@ -407,6 +441,20 @@ dependencies:
407
441
  - - ">="
408
442
  - !ruby/object:Gem::Version
409
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'
410
458
  - !ruby/object:Gem::Dependency
411
459
  name: rspec
412
460
  requirement: !ruby/object:Gem::Requirement
@@ -463,6 +511,20 @@ dependencies:
463
511
  - - '='
464
512
  - !ruby/object:Gem::Version
465
513
  version: '5.0'
514
+ - !ruby/object:Gem::Dependency
515
+ name: tzinfo-data
516
+ requirement: !ruby/object:Gem::Requirement
517
+ requirements:
518
+ - - ">="
519
+ - !ruby/object:Gem::Version
520
+ version: '0'
521
+ type: :development
522
+ prerelease: false
523
+ version_requirements: !ruby/object:Gem::Requirement
524
+ requirements:
525
+ - - ">="
526
+ - !ruby/object:Gem::Version
527
+ version: '0'
466
528
  - !ruby/object:Gem::Dependency
467
529
  name: warning
468
530
  requirement: !ruby/object:Gem::Requirement
@@ -478,7 +540,7 @@ dependencies:
478
540
  - !ruby/object:Gem::Version
479
541
  version: '0'
480
542
  - !ruby/object:Gem::Dependency
481
- name: tzinfo-data
543
+ name: zlib
482
544
  requirement: !ruby/object:Gem::Requirement
483
545
  requirements:
484
546
  - - ">="
@@ -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
620
  - ext/cs__assess_fiber_track/extconf.rb
560
621
  - ext/cs__assess_marshal_module/extconf.rb
561
- - ext/cs__protect_kernel/extconf.rb
562
- - ext/cs__assess_string_interpolation26/extconf.rb
563
- - ext/cs__assess_basic_object/extconf.rb
564
- - ext/cs__assess_active_record_named/extconf.rb
565
- - ext/cs__assess_yield_track/extconf.rb
566
622
  - ext/cs__assess_kernel/extconf.rb
567
- - ext/cs__assess_array/extconf.rb
623
+ - ext/cs__assess_basic_object/extconf.rb
624
+ - ext/cs__assess_string/extconf.rb
568
625
  - ext/cs__assess_regexp/extconf.rb
569
- - ext/cs__assess_hash/extconf.rb
626
+ - ext/cs__protect_kernel/extconf.rb
570
627
  - ext/cs__contrast_patch/extconf.rb
628
+ - ext/cs__assess_active_record_named/extconf.rb
571
629
  - ext/cs__assess_module/extconf.rb
630
+ - ext/cs__assess_hash/extconf.rb
631
+ - ext/cs__assess_string_interpolation26/extconf.rb
632
+ - ext/cs__assess_array/extconf.rb
633
+ - ext/cs__assess_yield_track/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
@@ -969,6 +1034,7 @@ files:
969
1034
  - lib/contrast/extension/assess/regexp.rb
970
1035
  - lib/contrast/extension/assess/string.rb
971
1036
  - lib/contrast/extension/delegator.rb
1037
+ - lib/contrast/extension/extension.rb
972
1038
  - lib/contrast/extension/inventory.rb
973
1039
  - lib/contrast/extension/kernel.rb
974
1040
  - lib/contrast/extension/module.rb
@@ -977,6 +1043,7 @@ files:
977
1043
  - lib/contrast/extension/protect/psych.rb
978
1044
  - lib/contrast/extension/thread.rb
979
1045
  - lib/contrast/framework/base_support.rb
1046
+ - lib/contrast/framework/grape/support.rb
980
1047
  - lib/contrast/framework/manager.rb
981
1048
  - lib/contrast/framework/platform_version.rb
982
1049
  - lib/contrast/framework/rack/patch/session_cookie.rb
@@ -1010,7 +1077,6 @@ files:
1010
1077
  - lib/contrast/utils/hash_digest.rb
1011
1078
  - lib/contrast/utils/heap_dump_util.rb
1012
1079
  - lib/contrast/utils/invalid_configuration_util.rb
1013
- - lib/contrast/utils/inventory_util.rb
1014
1080
  - lib/contrast/utils/io_util.rb
1015
1081
  - lib/contrast/utils/job_servers_running.rb
1016
1082
  - lib/contrast/utils/object_share.rb
@@ -1,113 +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/logger'
7
-
8
- module Contrast
9
- module Utils
10
- # Utilities for getting inventory information from the application
11
- class InventoryUtil
12
- extend Contrast::Components::Logger::InstanceMethods
13
-
14
- # TeamServer only accepts certain values for ArchitectureComponents.
15
- # DO NOT CHANGE THIS!
16
- AC_TYPE_DB = 'db'
17
- # TeamServer only accepts certain values for FlowMap Services.
18
- # DO NOT CHANGE THIS
19
- ADAPTER = 'adapter'
20
- HOST = 'host'
21
- PORT = 'port'
22
- DATABASE = 'database'
23
- DEFAULT = 'default'
24
- LOCALHOST = 'localhost'
25
-
26
- def self.active_record_config
27
- return @_active_record_config if instance_variable_defined?(:@_active_record_config)
28
-
29
- @_active_record_config = ActiveRecord::Base.connection_config rescue nil # rubocop:disable Style/RescueModifier
30
- end
31
-
32
- def self.append_db_config activity_or_update, hash_or_str = Contrast::Utils::InventoryUtil.active_record_config
33
- arr = build_from_db_config(hash_or_str)
34
- return unless arr&.any?
35
-
36
- arr.each do |a|
37
- next unless a
38
-
39
- if activity_or_update.is_a?(Contrast::Api::Dtm::Activity)
40
- activity_or_update.architectures << a
41
- else
42
- activity_or_update.components << a
43
- end
44
- end
45
- rescue StandardError => e
46
- logger.error('Unable to append db config', e)
47
- nil
48
- end
49
-
50
- def self.build_from_db_config hash_or_str
51
- return unless hash_or_str
52
-
53
- if hash_or_str.is_a?(Hash)
54
- build_from_db_hash(hash_or_str)
55
- else
56
- build_from_db_string(hash_or_str.to_s)
57
- end
58
- end
59
-
60
- def self.build_from_db_hash hash
61
- ac = Contrast::Api::Dtm::ArchitectureComponent.new
62
- ac.vendor = hash[:adapter] || hash[ADAPTER] || Contrast::Utils::ObjectShare::EMPTY_STRING
63
- ac.remote_host = host_from_hash(hash)
64
- ac.remote_port = port_from_hash(hash)
65
- ac.type = AC_TYPE_DB
66
- ac.url = hash[:database] || hash[DATABASE] || DEFAULT
67
- [ac]
68
- end
69
-
70
- def self.host_from_hash hash
71
- hash[:host] || hash[HOST] || Contrast::Utils::ObjectShare::EMPTY_STRING
72
- end
73
-
74
- def self.port_from_hash hash
75
- p = hash[:port] || hash[PORT] || Contrast::Utils::ObjectShare::EMPTY_STRING
76
- p.to_i
77
- end
78
-
79
- # Examples:
80
- # mongodb://[user:pass@]host1[:port1][,host2[:port2],[,hostN[:portN]]][/[database][?options]]
81
- # postgresql://scott:tiger@localhost/mydatabase
82
- # mysql+mysqlconnector://scott:tiger@localhost/foo
83
- def self.build_from_db_string str
84
- adapter, hosts, database = split_connection_str(str)
85
- acs = []
86
- hosts.split(Contrast::Utils::ObjectShare::COMMA).map do |s|
87
- host, port = s.split(Contrast::Utils::ObjectShare::COLON)
88
-
89
- ac = Contrast::Api::Dtm::ArchitectureComponent.new
90
- ac.vendor = Contrast::Utils::StringUtils.force_utf8(adapter)
91
- ac.remote_host = Contrast::Utils::StringUtils.force_utf8(host)
92
- ac.remote_port = port.to_i
93
- ac.type = AC_TYPE_DB
94
- ac.url = Contrast::Utils::StringUtils.force_utf8(database)
95
- acs << ac
96
- end
97
- acs
98
- end
99
-
100
- def self.split_connection_str str
101
- adapter, str = str.split(Contrast::Utils::ObjectShare::COLON_SLASH_SLASH)
102
- _auth, str = str.split(Contrast::Utils::ObjectShare::AT)
103
- # Not currently used
104
- # user, pass = auth.split(Contrast::Utils::ObjectShare::COLON)
105
- hosts, db_and_options = str.split(Contrast::Utils::ObjectShare::SLASH)
106
- hosts << LOCALHOST if hosts.empty?
107
- database, _options = db_and_options.split(Contrast::Utils::ObjectShare::QUESTION_MARK)
108
-
109
- [adapter, hosts, database]
110
- end
111
- end
112
- end
113
- end