contrast-agent 4.7.0 → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) 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/finalizers/hash.rb +2 -5
  10. data/lib/contrast/agent/assess/policy/patcher.rb +5 -4
  11. data/lib/contrast/agent/assess/policy/policy.rb +1 -1
  12. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -6
  13. data/lib/contrast/agent/assess/policy/preshift.rb +11 -8
  14. data/lib/contrast/agent/assess/policy/propagation_method.rb +102 -59
  15. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +2 -7
  16. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +31 -11
  17. data/lib/contrast/agent/assess/policy/propagator/rack_protection.rb +73 -0
  18. data/lib/contrast/agent/assess/policy/propagator/split.rb +10 -6
  19. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +3 -3
  20. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  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 +61 -86
  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 +8 -9
  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 +9 -5
  57. data/lib/contrast/agent/request_context.rb +28 -31
  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/service_heartbeat.rb +2 -3
  63. data/lib/contrast/agent/static_analysis.rb +7 -6
  64. data/lib/contrast/agent/thread.rb +2 -4
  65. data/lib/contrast/agent/thread_watcher.rb +3 -4
  66. data/lib/contrast/agent/tracepoint_hook.rb +10 -5
  67. data/lib/contrast/agent/version.rb +1 -1
  68. data/lib/contrast/api/communication/messaging_queue.rb +16 -11
  69. data/lib/contrast/api/communication/response_processor.rb +11 -11
  70. data/lib/contrast/api/communication/service_lifecycle.rb +9 -5
  71. data/lib/contrast/api/communication/socket_client.rb +18 -14
  72. data/lib/contrast/api/communication/speedracer.rb +5 -6
  73. data/lib/contrast/api/decorators/address.rb +2 -3
  74. data/lib/contrast/api/decorators/agent_startup.rb +7 -9
  75. data/lib/contrast/api/decorators/application_startup.rb +9 -10
  76. data/lib/contrast/api/decorators/application_update.rb +0 -4
  77. data/lib/contrast/api/decorators/http_request.rb +3 -7
  78. data/lib/contrast/api/decorators/instrumentation_mode.rb +3 -5
  79. data/lib/contrast/api/decorators/message.rb +7 -7
  80. data/lib/contrast/api/decorators/route_coverage.rb +24 -1
  81. data/lib/contrast/api/decorators/trace_event_object.rb +2 -3
  82. data/lib/contrast/components/agent.rb +13 -15
  83. data/lib/contrast/components/app_context.rb +7 -11
  84. data/lib/contrast/components/assess.rb +19 -16
  85. data/lib/contrast/components/base.rb +40 -0
  86. data/lib/contrast/components/config.rb +1 -2
  87. data/lib/contrast/components/contrast_service.rb +8 -11
  88. data/lib/contrast/components/heap_dump.rb +5 -4
  89. data/lib/contrast/components/inventory.rb +2 -7
  90. data/lib/contrast/components/logger.rb +14 -10
  91. data/lib/contrast/components/protect.rb +10 -13
  92. data/lib/contrast/components/sampling.rb +5 -5
  93. data/lib/contrast/components/scope.rb +9 -32
  94. data/lib/contrast/components/settings.rb +1 -5
  95. data/lib/contrast/config/base_configuration.rb +14 -6
  96. data/lib/contrast/configuration.rb +22 -19
  97. data/lib/contrast/extension/assess/array.rb +3 -15
  98. data/lib/contrast/extension/assess/eval_trigger.rb +2 -23
  99. data/lib/contrast/extension/assess/fiber.rb +6 -16
  100. data/lib/contrast/extension/assess/hash.rb +3 -13
  101. data/lib/contrast/extension/assess/kernel.rb +3 -14
  102. data/lib/contrast/extension/assess/marshal.rb +6 -14
  103. data/lib/contrast/extension/assess/regexp.rb +5 -15
  104. data/lib/contrast/extension/assess/string.rb +6 -31
  105. data/lib/contrast/extension/extension.rb +61 -0
  106. data/lib/contrast/extension/kernel.rb +2 -4
  107. data/lib/contrast/extension/protect/kernel.rb +0 -15
  108. data/lib/contrast/framework/grape/support.rb +174 -0
  109. data/lib/contrast/framework/manager.rb +44 -9
  110. data/lib/contrast/framework/rack/patch/session_cookie.rb +6 -6
  111. data/lib/contrast/framework/rack/support.rb +1 -1
  112. data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -8
  113. data/lib/contrast/framework/rails/patch/support.rb +44 -37
  114. data/lib/contrast/framework/rails/railtie.rb +34 -0
  115. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
  116. data/lib/contrast/framework/rails/support.rb +60 -13
  117. data/lib/contrast/framework/sinatra/support.rb +1 -1
  118. data/lib/contrast/funchook/funchook.rb +4 -3
  119. data/lib/contrast/logger/application.rb +1 -6
  120. data/lib/contrast/logger/log.rb +103 -13
  121. data/lib/contrast/logger/request.rb +0 -4
  122. data/lib/contrast/tasks/config.rb +0 -1
  123. data/lib/contrast/tasks/service.rb +1 -6
  124. data/lib/contrast/utils/assess/sampling_util.rb +2 -3
  125. data/lib/contrast/utils/assess/tracking_util.rb +2 -4
  126. data/lib/contrast/utils/heap_dump_util.rb +5 -3
  127. data/lib/contrast/utils/invalid_configuration_util.rb +4 -3
  128. data/lib/contrast/utils/io_util.rb +3 -5
  129. data/lib/contrast/utils/job_servers_running.rb +4 -3
  130. data/lib/contrast/utils/os.rb +2 -3
  131. data/lib/contrast/utils/ruby_ast_rewriter.rb +16 -13
  132. data/lib/contrast/utils/string_utils.rb +2 -3
  133. data/lib/contrast/utils/tag_util.rb +26 -19
  134. data/lib/contrast.rb +24 -14
  135. data/resources/assess/policy.json +252 -2
  136. data/resources/deadzone/policy.json +10 -0
  137. data/ruby-agent.gemspec +14 -3
  138. data/service_executables/VERSION +1 -1
  139. data/service_executables/linux/contrast-service +0 -0
  140. data/service_executables/mac/contrast-service +0 -0
  141. metadata +104 -24
  142. data/lib/contrast/agent/railtie.rb +0 -31
  143. data/lib/contrast/components/interface.rb +0 -196
  144. data/lib/contrast/delegators/input_analysis.rb +0 -12
  145. data/lib/contrast/utils/inventory_util.rb +0 -114
@@ -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,22 @@ 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'
52
+ spec.add_development_dependency 'rack-protection', '>= 2'
44
53
  spec.add_development_dependency 'rails', '6.0.3.5'
45
54
  spec.add_development_dependency 'sinatra', '>= 2'
46
55
  end
@@ -50,6 +59,7 @@ def self.add_linters spec
50
59
  spec.add_development_dependency 'debride', '1.8.2'
51
60
  spec.add_development_dependency 'fasterer', '0.9.0'
52
61
  spec.add_development_dependency 'flay', '2.12.1'
62
+ # spec.add_development_dependency 'steep', '0.44.1' # TODO: RUBY-714 uncomment w/ EOL of 2.5
53
63
  add_rubocop(spec)
54
64
  end
55
65
 
@@ -64,15 +74,16 @@ def self.add_specs spec
64
74
  spec.add_development_dependency 'factory_bot'
65
75
  spec.add_development_dependency 'fake_ftp'
66
76
  spec.add_development_dependency 'openssl'
77
+ spec.add_development_dependency 'parallel_tests'
67
78
  spec.add_development_dependency 'rspec', '~> 3.0'
68
79
  spec.add_development_dependency 'rspec-benchmark'
69
80
  spec.add_development_dependency 'rspec_junit_formatter', '0.3.0'
70
81
  spec.add_development_dependency 'rspec-rails', '5.0'
71
82
  spec.add_development_dependency 'tzinfo-data' # Alpine rspec-rails requirement.
83
+ spec.add_development_dependency 'warning'
72
84
  end
73
85
 
74
86
  def self.add_coverage spec
75
- spec.add_development_dependency 'codecov', '0.5.2'
76
87
  spec.add_development_dependency 'simplecov', '0.21.2'
77
88
  end
78
89
 
@@ -89,8 +100,8 @@ end
89
100
  def self.add_tested_gems spec
90
101
  spec.add_development_dependency 'async'
91
102
  spec.add_development_dependency 'execjs'
103
+ spec.add_development_dependency 'rhino'
92
104
  spec.add_development_dependency 'sqlite3'
93
- spec.add_development_dependency 'therubyracer'
94
105
  spec.add_development_dependency 'tilt'
95
106
  spec.add_development_dependency 'xpath'
96
107
  end
@@ -113,7 +124,7 @@ def self.add_files spec
113
124
  # Directories used for testing:
114
125
  f.match(%r{^(spec|test)/}) ||
115
126
  # Directories used in pipelines
116
- f.match(%r{^(\.github|bin|internal_resources|vendor)/}) ||
127
+ f.match(%r{^(\.github|bin|internal_resources|sig|vendor)/}) ||
117
128
  # Configuration and other files that don't belong to one directory
118
129
  f.match(/(Dockerfile)/) ||
119
130
  f.match(/(.*\.csv)/) ||
@@ -1 +1 @@
1
- 2.19.0
1
+ 2.21.2
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.7.0
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-05-10 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
@@ -198,33 +212,53 @@ 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
248
+ - !ruby/object:Gem::Dependency
249
+ name: rack-protection
250
+ requirement: !ruby/object:Gem::Requirement
251
+ requirements:
252
+ - - ">="
253
+ - !ruby/object:Gem::Version
254
+ version: '2'
255
+ type: :development
256
+ prerelease: false
257
+ version_requirements: !ruby/object:Gem::Requirement
258
+ requirements:
259
+ - - ">="
260
+ - !ruby/object:Gem::Version
261
+ version: '2'
228
262
  - !ruby/object:Gem::Dependency
229
263
  name: rails
230
264
  requirement: !ruby/object:Gem::Requirement
@@ -282,7 +316,7 @@ dependencies:
282
316
  - !ruby/object:Gem::Version
283
317
  version: '0'
284
318
  - !ruby/object:Gem::Dependency
285
- name: sqlite3
319
+ name: rhino
286
320
  requirement: !ruby/object:Gem::Requirement
287
321
  requirements:
288
322
  - - ">="
@@ -296,7 +330,7 @@ dependencies:
296
330
  - !ruby/object:Gem::Version
297
331
  version: '0'
298
332
  - !ruby/object:Gem::Dependency
299
- name: therubyracer
333
+ name: sqlite3
300
334
  requirement: !ruby/object:Gem::Requirement
301
335
  requirements:
302
336
  - - ">="
@@ -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
@@ -477,6 +525,34 @@ dependencies:
477
525
  - - ">="
478
526
  - !ruby/object:Gem::Version
479
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'
480
556
  - !ruby/object:Gem::Dependency
481
557
  name: ougai
482
558
  requirement: !ruby/object:Gem::Requirement
@@ -541,20 +617,20 @@ executables:
541
617
  - contrast_service
542
618
  extensions:
543
619
  - ext/cs__common/extconf.rb
544
- - ext/cs__assess_string/extconf.rb
545
- - ext/cs__protect_kernel/extconf.rb
546
- - ext/cs__assess_regexp/extconf.rb
547
- - ext/cs__contrast_patch/extconf.rb
548
- - ext/cs__assess_array/extconf.rb
549
- - ext/cs__assess_yield_track/extconf.rb
550
620
  - ext/cs__assess_fiber_track/extconf.rb
551
621
  - ext/cs__assess_marshal_module/extconf.rb
622
+ - ext/cs__assess_kernel/extconf.rb
552
623
  - ext/cs__assess_basic_object/extconf.rb
624
+ - ext/cs__assess_string/extconf.rb
625
+ - ext/cs__assess_regexp/extconf.rb
626
+ - ext/cs__protect_kernel/extconf.rb
627
+ - ext/cs__contrast_patch/extconf.rb
628
+ - ext/cs__assess_active_record_named/extconf.rb
553
629
  - ext/cs__assess_module/extconf.rb
554
- - ext/cs__assess_kernel/extconf.rb
555
630
  - ext/cs__assess_hash/extconf.rb
556
- - ext/cs__assess_active_record_named/extconf.rb
557
631
  - ext/cs__assess_string_interpolation26/extconf.rb
632
+ - ext/cs__assess_array/extconf.rb
633
+ - ext/cs__assess_yield_track/extconf.rb
558
634
  extra_rdoc_files: []
559
635
  files:
560
636
  - ".clang-format"
@@ -563,6 +639,7 @@ files:
563
639
  - ".gitignore"
564
640
  - ".gitmodules"
565
641
  - ".rspec"
642
+ - ".rspec_parallel"
566
643
  - ".simplecov"
567
644
  - Gemfile
568
645
  - LICENSE.txt
@@ -775,6 +852,7 @@ files:
775
852
  - lib/contrast/agent/assess/policy/propagator/match_data.rb
776
853
  - lib/contrast/agent/assess/policy/propagator/next.rb
777
854
  - lib/contrast/agent/assess/policy/propagator/prepend.rb
855
+ - lib/contrast/agent/assess/policy/propagator/rack_protection.rb
778
856
  - lib/contrast/agent/assess/policy/propagator/remove.rb
779
857
  - lib/contrast/agent/assess/policy/propagator/replace.rb
780
858
  - lib/contrast/agent/assess/policy/propagator/reverse.rb
@@ -813,6 +891,7 @@ files:
813
891
  - lib/contrast/agent/disable_reaction.rb
814
892
  - lib/contrast/agent/exclusion_matcher.rb
815
893
  - lib/contrast/agent/inventory.rb
894
+ - lib/contrast/agent/inventory/database_config.rb
816
895
  - lib/contrast/agent/inventory/dependencies.rb
817
896
  - lib/contrast/agent/inventory/dependency_analysis.rb
818
897
  - lib/contrast/agent/inventory/dependency_usage_analysis.rb
@@ -850,6 +929,7 @@ files:
850
929
  - lib/contrast/agent/protect/rule/no_sqli.rb
851
930
  - lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb
852
931
  - lib/contrast/agent/protect/rule/path_traversal.rb
932
+ - lib/contrast/agent/protect/rule/sql_sample_builder.rb
853
933
  - lib/contrast/agent/protect/rule/sqli.rb
854
934
  - lib/contrast/agent/protect/rule/sqli/default_sql_scanner.rb
855
935
  - lib/contrast/agent/protect/rule/sqli/mysql_sql_scanner.rb
@@ -859,7 +939,6 @@ files:
859
939
  - lib/contrast/agent/protect/rule/xss.rb
860
940
  - lib/contrast/agent/protect/rule/xxe.rb
861
941
  - lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb
862
- - lib/contrast/agent/railtie.rb
863
942
  - lib/contrast/agent/reaction_processor.rb
864
943
  - lib/contrast/agent/request.rb
865
944
  - lib/contrast/agent/request_context.rb
@@ -913,10 +992,10 @@ files:
913
992
  - lib/contrast/components/agent.rb
914
993
  - lib/contrast/components/app_context.rb
915
994
  - lib/contrast/components/assess.rb
995
+ - lib/contrast/components/base.rb
916
996
  - lib/contrast/components/config.rb
917
997
  - lib/contrast/components/contrast_service.rb
918
998
  - lib/contrast/components/heap_dump.rb
919
- - lib/contrast/components/interface.rb
920
999
  - lib/contrast/components/inventory.rb
921
1000
  - lib/contrast/components/logger.rb
922
1001
  - lib/contrast/components/protect.rb
@@ -943,7 +1022,6 @@ files:
943
1022
  - lib/contrast/config/server_configuration.rb
944
1023
  - lib/contrast/config/service_configuration.rb
945
1024
  - lib/contrast/configuration.rb
946
- - lib/contrast/delegators/input_analysis.rb
947
1025
  - lib/contrast/extension/assess.rb
948
1026
  - lib/contrast/extension/assess/array.rb
949
1027
  - lib/contrast/extension/assess/erb.rb
@@ -956,6 +1034,7 @@ files:
956
1034
  - lib/contrast/extension/assess/regexp.rb
957
1035
  - lib/contrast/extension/assess/string.rb
958
1036
  - lib/contrast/extension/delegator.rb
1037
+ - lib/contrast/extension/extension.rb
959
1038
  - lib/contrast/extension/inventory.rb
960
1039
  - lib/contrast/extension/kernel.rb
961
1040
  - lib/contrast/extension/module.rb
@@ -964,6 +1043,7 @@ files:
964
1043
  - lib/contrast/extension/protect/psych.rb
965
1044
  - lib/contrast/extension/thread.rb
966
1045
  - lib/contrast/framework/base_support.rb
1046
+ - lib/contrast/framework/grape/support.rb
967
1047
  - lib/contrast/framework/manager.rb
968
1048
  - lib/contrast/framework/platform_version.rb
969
1049
  - lib/contrast/framework/rack/patch/session_cookie.rb
@@ -973,6 +1053,7 @@ files:
973
1053
  - lib/contrast/framework/rails/patch/assess_configuration.rb
974
1054
  - lib/contrast/framework/rails/patch/rails_application_configuration.rb
975
1055
  - lib/contrast/framework/rails/patch/support.rb
1056
+ - lib/contrast/framework/rails/railtie.rb
976
1057
  - lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb
977
1058
  - lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
978
1059
  - lib/contrast/framework/rails/rewrite/active_record_named.rb
@@ -996,7 +1077,6 @@ files:
996
1077
  - lib/contrast/utils/hash_digest.rb
997
1078
  - lib/contrast/utils/heap_dump_util.rb
998
1079
  - lib/contrast/utils/invalid_configuration_util.rb
999
- - lib/contrast/utils/inventory_util.rb
1000
1080
  - lib/contrast/utils/io_util.rb
1001
1081
  - lib/contrast/utils/job_servers_running.rb
1002
1082
  - lib/contrast/utils/object_share.rb
@@ -1,31 +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/job_servers_running'
5
-
6
- module Contrast
7
- module Agent
8
- # A Railtie to allow for the automatic hooking of the Agent into a Rails
9
- # application.
10
- class Railtie < Rails::Railtie
11
- include Contrast::Components::Interface
12
- access_component :agent, :app_context, :logging
13
-
14
- initializer 'Contrast Ruby Agent Initializer' do |app|
15
- Rails.logger.debug("In railtie ::#{ app.middleware.inspect }") if defined?(Rails) && defined?(Rails.logger)
16
-
17
- if APP_CONTEXT.instrument_middleware_stack?
18
- AGENT.insert_middleware(app)
19
- else
20
- Rails.logger.debug('Detected a running job server, skipping Contrast middleware insertion.')
21
- logger.debug('Disabling Contrast for process', p_id: Process.pid)
22
- end
23
- end
24
-
25
- rake_tasks do
26
- load 'contrast/tasks/service.rb'
27
- load 'contrast/tasks/config.rb'
28
- end
29
- end
30
- end
31
- end
@@ -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