contrast-agent 3.15.0 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/lib/contrast/agent.rb +2 -9
  3. data/lib/contrast/agent/assess/contrast_event.rb +142 -70
  4. data/lib/contrast/agent/assess/events/source_event.rb +1 -1
  5. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +10 -3
  6. data/lib/contrast/agent/assess/policy/policy_node.rb +15 -10
  7. data/lib/contrast/agent/assess/policy/policy_scanner.rb +7 -1
  8. data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -1
  9. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +0 -3
  10. data/lib/contrast/agent/assess/policy/propagator/select.rb +1 -3
  11. data/lib/contrast/agent/assess/policy/propagator/splat.rb +0 -5
  12. data/lib/contrast/agent/assess/policy/propagator/split.rb +12 -13
  13. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +21 -14
  14. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +4 -5
  15. data/lib/contrast/agent/assess/policy/trigger_method.rb +39 -14
  16. data/lib/contrast/agent/assess/policy/trigger_node.rb +31 -37
  17. data/lib/contrast/agent/assess/property/evented.rb +5 -18
  18. data/lib/contrast/agent/assess/property/tagged.rb +9 -3
  19. data/lib/contrast/agent/assess/property/updated.rb +0 -5
  20. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
  21. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +23 -8
  22. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +82 -14
  23. data/lib/contrast/agent/assess/tag.rb +1 -1
  24. data/lib/contrast/agent/at_exit_hook.rb +5 -5
  25. data/lib/contrast/agent/patching/policy/after_load_patch.rb +5 -5
  26. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +20 -20
  27. data/lib/contrast/agent/patching/policy/module_policy.rb +10 -10
  28. data/lib/contrast/agent/patching/policy/policy.rb +16 -2
  29. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -5
  30. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
  31. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
  32. data/lib/contrast/agent/request.rb +34 -34
  33. data/lib/contrast/agent/static_analysis.rb +6 -6
  34. data/lib/contrast/agent/version.rb +1 -1
  35. data/lib/contrast/api/communication/socket_client.rb +36 -1
  36. data/lib/contrast/api/decorators/address.rb +13 -13
  37. data/lib/contrast/api/decorators/message.rb +1 -0
  38. data/lib/contrast/api/decorators/trace_event.rb +20 -18
  39. data/lib/contrast/components/app_context.rb +39 -30
  40. data/lib/contrast/components/contrast_service.rb +9 -9
  41. data/lib/contrast/components/settings.rb +20 -23
  42. data/lib/contrast/config/service_configuration.rb +4 -2
  43. data/lib/contrast/configuration.rb +1 -1
  44. data/lib/contrast/extension/assess/array.rb +7 -3
  45. data/lib/contrast/extension/assess/erb.rb +5 -0
  46. data/lib/contrast/extension/assess/eval_trigger.rb +6 -6
  47. data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
  48. data/lib/contrast/extension/assess/fiber.rb +3 -3
  49. data/lib/contrast/extension/assess/hash.rb +3 -3
  50. data/lib/contrast/extension/assess/kernel.rb +18 -20
  51. data/lib/contrast/extension/assess/marshal.rb +8 -4
  52. data/lib/contrast/extension/assess/regexp.rb +3 -3
  53. data/lib/contrast/extension/assess/string.rb +13 -11
  54. data/lib/contrast/extension/protect/kernel.rb +3 -3
  55. data/lib/contrast/framework/base_support.rb +1 -1
  56. data/lib/contrast/framework/manager.rb +3 -3
  57. data/lib/contrast/framework/rack/patch/session_cookie.rb +9 -9
  58. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
  59. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +10 -10
  60. data/lib/contrast/framework/rails/patch/support.rb +1 -1
  61. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
  62. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
  63. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -3
  64. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
  65. data/lib/contrast/framework/sinatra/patch/base.rb +11 -11
  66. data/lib/contrast/framework/sinatra/support.rb +4 -4
  67. data/lib/contrast/logger/log.rb +7 -2
  68. data/lib/contrast/utils/invalid_configuration_util.rb +2 -5
  69. data/resources/assess/policy.json +31 -12
  70. data/ruby-agent.gemspec +4 -3
  71. data/service_executables/VERSION +1 -1
  72. data/service_executables/linux/contrast-service +0 -0
  73. data/service_executables/mac/contrast-service +0 -0
  74. metadata +31 -17
@@ -58,9 +58,9 @@ module Contrast
58
58
 
59
59
  def instrument
60
60
  @_instrument_named_track ||= begin
61
- require 'cs__assess_active_record_named/cs__assess_active_record_named'
62
- true
63
- end
61
+ require 'cs__assess_active_record_named/cs__assess_active_record_named'
62
+ true
63
+ end
64
64
  rescue StandardError, LoadError => e
65
65
  logger.error('Error loading active record named track patch', e)
66
66
  false
@@ -12,19 +12,19 @@ module Contrast
12
12
  class ActiveRecordTimeZoneInherited
13
13
  def self.instrument
14
14
  @_instrument ||= begin
15
- ::ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods.class_eval do
16
- private
15
+ ::ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods.class_eval do
16
+ private
17
17
 
18
- alias_method :cs__patched_inherited, :inherited
19
- def inherited klass # rubocop:disable Lint/MissingSuper
20
- klass&.instance_variable_set(:@cs__defining_class, true)
21
- cs__patched_inherited(klass) # This calls the original inherited, which should handle super as needed.
22
- ensure
23
- klass&.instance_variable_set(:@cs__defining_class, false)
24
- end
25
- end
26
- true
27
- end
18
+ alias_method :cs__patched_inherited, :inherited
19
+ def inherited klass # rubocop:disable Lint/MissingSuper
20
+ klass&.instance_variable_set(:@cs__defining_class, true)
21
+ cs__patched_inherited(klass) # This calls the original inherited, which should handle super as needed.
22
+ ensure
23
+ klass&.instance_variable_set(:@cs__defining_class, false)
24
+ end
25
+ end
26
+ true
27
+ end
28
28
  end
29
29
  end
30
30
  end
@@ -34,17 +34,17 @@ module Contrast
34
34
 
35
35
  def instrument
36
36
  @_instrument ||= begin
37
- ::Sinatra::Base.class_eval do
38
- alias_method :cs__patched_sinatra_base_call!, :call!
39
- # publicly available method for Sinatra::Base things -- unfortunately,
40
- # getting the routes appear to require a lookup every time
41
- def call! *args
42
- Contrast::Framework::Sinatra::Patch::Base.map_route(cs__class, settings, *args)
43
- cs__patched_sinatra_base_call!(*args)
44
- end
45
- end
46
- true
47
- end
37
+ ::Sinatra::Base.class_eval do
38
+ alias_method :cs__patched_sinatra_base_call!, :call!
39
+ # publicly available method for Sinatra::Base things -- unfortunately,
40
+ # getting the routes appear to require a lookup every time
41
+ def call! *args
42
+ Contrast::Framework::Sinatra::Patch::Base.map_route(cs__class, settings, *args)
43
+ cs__patched_sinatra_base_call!(*args)
44
+ end
45
+ end
46
+ true
47
+ end
48
48
  end
49
49
 
50
50
  private
@@ -70,10 +70,10 @@ module Contrast
70
70
  return nil unless defined?(::Sinatra) && defined?(::Sinatra::Base)
71
71
 
72
72
  @_app_class ||= begin
73
- sinatra_layers = ObjectSpace.each_object(::Sinatra::Base).to_a
74
- result_layer = sinatra_layers.find { |layer| layer.app.nil? }
75
- result_layer
76
- end
73
+ sinatra_layers = ObjectSpace.each_object(::Sinatra::Base).to_a
74
+ result_layer = sinatra_layers.find { |layer| layer.app.nil? }
75
+ result_layer
76
+ end
77
77
  end
78
78
 
79
79
  # Iterate over every class that extends Sinatra::Base, pull out its routes
@@ -49,14 +49,19 @@ module Contrast
49
49
  path = valid_path(config_path || log_file)
50
50
  level_const = valid_level(config_level || log_level)
51
51
 
52
+ path_change = path != previous_path
53
+ level_change = level_const != previous_level
54
+
52
55
  # don't needlessly recreate logger
53
- return if @_logger && (path == previous_path) && (level_const == previous_level)
56
+ return if @_logger && !(path_change || level_change)
54
57
 
55
58
  @previous_path = path
56
59
  @previous_level = level_const
57
60
 
58
61
  @_logger = build(path: path, level_const: level_const)
59
- log_update
62
+ # If we're logging to a new path, then let's start it w/ our helpful
63
+ # data gathering messages
64
+ log_update if path_change
60
65
  rescue StandardError => e
61
66
  if logger
62
67
  logger.error('Unable to process update to LoggerManager.', e)
@@ -1,6 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'contrast/agent/assess/policy/trigger_method'
4
5
  require 'contrast/components/interface'
5
6
 
6
7
  module Contrast
@@ -41,11 +42,7 @@ module Contrast
41
42
  hash = Contrast::Utils::HashDigest.generate_config_hash(finding)
42
43
  finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash)
43
44
  finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
44
-
45
- activity = Contrast::Api::Dtm::Activity.new
46
- activity.findings << finding
47
-
48
- Contrast::Agent.messaging_queue.send_event_eventually(activity)
45
+ Contrast::Agent::Assess::Policy::TriggerMethod.report_finding(finding)
49
46
  end
50
47
  rescue StandardError => e
51
48
  logger.error('Unable to build a finding', e, rule: rule_id)
@@ -275,7 +275,7 @@
275
275
  "instance_method": true,
276
276
  "method_visibility": "public",
277
277
  "method_name":"insert",
278
- "source":"P1",
278
+ "source":"O,P1",
279
279
  "target":"O",
280
280
  "action":"INSERT"
281
281
  }, {
@@ -614,7 +614,6 @@
614
614
  "action":"CUSTOM",
615
615
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::MatchData",
616
616
  "patch_method": "captures_tagger"
617
-
618
617
  }, {
619
618
  "class_name":"MatchData",
620
619
  "instance_method": true,
@@ -640,7 +639,9 @@
640
639
  "method_name": "gsub",
641
640
  "action": "CUSTOM",
642
641
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::Substitution",
643
- "patch_method": "gsub_tagger"
642
+ "patch_method": "gsub_tagger",
643
+ "source": "O,P",
644
+ "target": "R"
644
645
  }, {
645
646
  "class_name": "String",
646
647
  "instance_method": true,
@@ -648,7 +649,9 @@
648
649
  "method_name": "gsub!",
649
650
  "action": "CUSTOM",
650
651
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::Substitution",
651
- "patch_method": "gsub_tagger"
652
+ "patch_method": "gsub_tagger",
653
+ "source": "O,P",
654
+ "target": "O"
652
655
  }, {
653
656
  "class_name": "String",
654
657
  "instance_method": true,
@@ -656,7 +659,9 @@
656
659
  "method_name": "sub",
657
660
  "action": "CUSTOM",
658
661
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::Substitution",
659
- "patch_method": "sub_tagger"
662
+ "patch_method": "sub_tagger",
663
+ "source": "O,P",
664
+ "target": "R"
660
665
  }, {
661
666
  "class_name": "String",
662
667
  "instance_method": true,
@@ -664,7 +669,9 @@
664
669
  "method_name": "sub!",
665
670
  "action": "CUSTOM",
666
671
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::Substitution",
667
- "patch_method": "sub_tagger"
672
+ "patch_method": "sub_tagger",
673
+ "source": "O,P",
674
+ "target": "O"
668
675
  }, {
669
676
  "class_name": "String",
670
677
  "instance_method": true,
@@ -672,7 +679,9 @@
672
679
  "method_name": "tr",
673
680
  "action": "CUSTOM",
674
681
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::Trim",
675
- "patch_method": "tr_tagger"
682
+ "patch_method": "tr_tagger",
683
+ "source": "O,P",
684
+ "target": "R"
676
685
  }, {
677
686
  "class_name": "String",
678
687
  "instance_method": true,
@@ -680,7 +689,9 @@
680
689
  "method_name": "tr!",
681
690
  "action": "CUSTOM",
682
691
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::Trim",
683
- "patch_method": "tr_tagger"
692
+ "patch_method": "tr_tagger",
693
+ "source": "O,P",
694
+ "target": "O"
684
695
  }, {
685
696
  "class_name": "String",
686
697
  "instance_method": true,
@@ -688,7 +699,9 @@
688
699
  "method_name": "tr_s",
689
700
  "action": "CUSTOM",
690
701
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::Trim",
691
- "patch_method": "tr_s_tagger"
702
+ "patch_method": "tr_s_tagger",
703
+ "source": "O,P",
704
+ "target": "R"
692
705
  }, {
693
706
  "class_name": "String",
694
707
  "instance_method": true,
@@ -696,7 +709,9 @@
696
709
  "method_name": "tr_s!",
697
710
  "action": "CUSTOM",
698
711
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::Trim",
699
- "patch_method": "tr_s_tagger"
712
+ "patch_method": "tr_s_tagger",
713
+ "source": "O,P",
714
+ "target": "O"
700
715
  }, {
701
716
  "class_name": "String",
702
717
  "instance_method": true,
@@ -704,7 +719,9 @@
704
719
  "method_name": "[]",
705
720
  "action": "CUSTOM",
706
721
  "patch_class": "Contrast::Agent::Assess::Policy::Propagator::Select",
707
- "patch_method": "select_tagger"
722
+ "patch_method": "select_tagger",
723
+ "source": "O",
724
+ "target": "R"
708
725
  }, {
709
726
  "class_name":"CGI::Util",
710
727
  "method_name":"escapeHTML",
@@ -966,7 +983,9 @@
966
983
  "method_name": "sprintf",
967
984
  "action": "CUSTOM",
968
985
  "patch_class": "Contrast::Extension::Assess::KernelPropagator",
969
- "patch_method": "sprintf_tagger"
986
+ "patch_method": "sprintf_tagger",
987
+ "source": "O,P",
988
+ "target": "R"
970
989
  }, {
971
990
  "class_name":"ActiveRecord::ConnectionAdapters::Quoting",
972
991
  "instance_method": true,
@@ -28,6 +28,7 @@ def self.add_dev_dependencies spec
28
28
  spec.add_development_dependency 'factory_bot'
29
29
  spec.add_development_dependency 'fake_ftp'
30
30
  spec.add_development_dependency 'fasterer'
31
+ spec.add_development_dependency 'flay'
31
32
  spec.add_development_dependency 'openssl'
32
33
  spec.add_development_dependency 'parser', '~> 2.6'
33
34
  spec.add_development_dependency 'pry'
@@ -37,9 +38,9 @@ def self.add_dev_dependencies spec
37
38
  spec.add_development_dependency 'rspec', '~> 3.0'
38
39
  spec.add_development_dependency 'rspec-benchmark'
39
40
  spec.add_development_dependency 'rspec_junit_formatter', '0.3.0'
40
- spec.add_development_dependency 'rubocop', '0.89.1'
41
- spec.add_development_dependency 'rubocop-performance', '1.7.1'
42
- spec.add_development_dependency 'rubocop-rspec', '1.42.0'
41
+ spec.add_development_dependency 'rubocop', '0.93.1'
42
+ spec.add_development_dependency 'rubocop-performance', '1.8.1'
43
+ spec.add_development_dependency 'rubocop-rspec', '1.43.2'
43
44
  spec.add_development_dependency 'ruby-debug-ide'
44
45
  spec.add_development_dependency 'simplecov', '~> 0.18'
45
46
  spec.add_development_dependency 'sinatra', '>= 2'
@@ -1 +1 @@
1
- 2.12.0
1
+ 2.14.3
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: 3.15.0
4
+ version: 3.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - galen.palmer@contrastsecurity.com
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2020-09-18 00:00:00.000000000 Z
15
+ date: 2020-10-26 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: amazing_print
@@ -140,6 +140,20 @@ dependencies:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: flay
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
143
157
  - !ruby/object:Gem::Dependency
144
158
  name: openssl
145
159
  requirement: !ruby/object:Gem::Requirement
@@ -272,42 +286,42 @@ dependencies:
272
286
  requirements:
273
287
  - - '='
274
288
  - !ruby/object:Gem::Version
275
- version: 0.89.1
289
+ version: 0.93.1
276
290
  type: :development
277
291
  prerelease: false
278
292
  version_requirements: !ruby/object:Gem::Requirement
279
293
  requirements:
280
294
  - - '='
281
295
  - !ruby/object:Gem::Version
282
- version: 0.89.1
296
+ version: 0.93.1
283
297
  - !ruby/object:Gem::Dependency
284
298
  name: rubocop-performance
285
299
  requirement: !ruby/object:Gem::Requirement
286
300
  requirements:
287
301
  - - '='
288
302
  - !ruby/object:Gem::Version
289
- version: 1.7.1
303
+ version: 1.8.1
290
304
  type: :development
291
305
  prerelease: false
292
306
  version_requirements: !ruby/object:Gem::Requirement
293
307
  requirements:
294
308
  - - '='
295
309
  - !ruby/object:Gem::Version
296
- version: 1.7.1
310
+ version: 1.8.1
297
311
  - !ruby/object:Gem::Dependency
298
312
  name: rubocop-rspec
299
313
  requirement: !ruby/object:Gem::Requirement
300
314
  requirements:
301
315
  - - '='
302
316
  - !ruby/object:Gem::Version
303
- version: 1.42.0
317
+ version: 1.43.2
304
318
  type: :development
305
319
  prerelease: false
306
320
  version_requirements: !ruby/object:Gem::Requirement
307
321
  requirements:
308
322
  - - '='
309
323
  - !ruby/object:Gem::Version
310
- version: 1.42.0
324
+ version: 1.43.2
311
325
  - !ruby/object:Gem::Dependency
312
326
  name: ruby-debug-ide
313
327
  requirement: !ruby/object:Gem::Requirement
@@ -484,18 +498,18 @@ executables:
484
498
  - contrast_service
485
499
  extensions:
486
500
  - ext/cs__common/extconf.rb
487
- - ext/cs__assess_yield_track/extconf.rb
488
501
  - ext/cs__assess_module/extconf.rb
489
- - ext/cs__assess_active_record_named/extconf.rb
490
- - ext/cs__contrast_patch/extconf.rb
491
- - ext/cs__assess_string/extconf.rb
492
- - ext/cs__assess_fiber_track/extconf.rb
493
- - ext/cs__assess_regexp/extconf.rb
494
- - ext/cs__assess_kernel/extconf.rb
502
+ - ext/cs__protect_kernel/extconf.rb
503
+ - ext/cs__assess_array/extconf.rb
495
504
  - ext/cs__assess_hash/extconf.rb
496
505
  - ext/cs__assess_marshal_module/extconf.rb
497
- - ext/cs__assess_array/extconf.rb
498
- - ext/cs__protect_kernel/extconf.rb
506
+ - ext/cs__assess_kernel/extconf.rb
507
+ - ext/cs__assess_regexp/extconf.rb
508
+ - ext/cs__assess_yield_track/extconf.rb
509
+ - ext/cs__assess_string/extconf.rb
510
+ - ext/cs__contrast_patch/extconf.rb
511
+ - ext/cs__assess_active_record_named/extconf.rb
512
+ - ext/cs__assess_fiber_track/extconf.rb
499
513
  - ext/cs__assess_basic_object/extconf.rb
500
514
  - ext/cs__assess_string_interpolation26/extconf.rb
501
515
  extra_rdoc_files: []