contrast-agent 4.9.1 → 4.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -1
  3. data/.rspec_parallel +6 -0
  4. data/ext/cs__assess_module/cs__assess_module.c +48 -0
  5. data/ext/cs__assess_module/cs__assess_module.h +7 -0
  6. data/ext/cs__common/cs__common.c +24 -7
  7. data/ext/cs__common/cs__common.h +12 -2
  8. data/ext/cs__contrast_patch/cs__contrast_patch.c +48 -12
  9. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -4
  10. data/ext/cs__os_information/cs__os_information.c +31 -0
  11. data/ext/cs__os_information/cs__os_information.h +7 -0
  12. data/ext/{cs__protect_kernel → cs__os_information}/extconf.rb +0 -0
  13. data/lib/contrast/agent/assess/contrast_event.rb +1 -2
  14. data/lib/contrast/agent/assess/contrast_object.rb +1 -4
  15. data/lib/contrast/agent/assess/finalizers/hash.rb +0 -1
  16. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +2 -0
  17. data/lib/contrast/agent/assess/policy/patcher.rb +0 -1
  18. data/lib/contrast/agent/assess/policy/policy_scanner.rb +0 -2
  19. data/lib/contrast/agent/assess/policy/preshift.rb +29 -12
  20. data/lib/contrast/agent/assess/policy/propagation_method.rb +71 -142
  21. data/lib/contrast/agent/assess/policy/propagation_node.rb +4 -4
  22. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +2 -2
  23. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +31 -11
  24. data/lib/contrast/agent/assess/policy/propagator/remove.rb +4 -9
  25. data/lib/contrast/agent/assess/policy/propagator/split.rb +3 -2
  26. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -0
  27. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +0 -1
  28. data/lib/contrast/agent/assess/policy/source_method.rb +15 -88
  29. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +0 -1
  30. data/lib/contrast/agent/assess/policy/trigger_method.rb +45 -172
  31. data/lib/contrast/agent/assess/policy/trigger_node.rb +52 -19
  32. data/lib/contrast/agent/assess/property/evented.rb +2 -1
  33. data/lib/contrast/agent/assess/property/tagged.rb +15 -132
  34. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +0 -1
  35. data/lib/contrast/agent/deadzone/policy/policy.rb +6 -0
  36. data/lib/contrast/agent/disable_reaction.rb +1 -1
  37. data/lib/contrast/agent/exclusion_matcher.rb +0 -4
  38. data/lib/contrast/agent/inventory/database_config.rb +117 -0
  39. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +7 -5
  40. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
  41. data/lib/contrast/agent/metric_telemetry_event.rb +26 -0
  42. data/lib/contrast/agent/middleware.rb +23 -0
  43. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -0
  44. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +17 -12
  45. data/lib/contrast/agent/patching/policy/method_policy.rb +54 -9
  46. data/lib/contrast/agent/patching/policy/module_policy.rb +2 -4
  47. data/lib/contrast/agent/patching/policy/patch.rb +42 -238
  48. data/lib/contrast/agent/patching/policy/patch_status.rb +3 -7
  49. data/lib/contrast/agent/patching/policy/patcher.rb +10 -49
  50. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +1 -1
  51. data/lib/contrast/agent/protect/rule/no_sqli.rb +7 -53
  52. data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +137 -0
  53. data/lib/contrast/agent/protect/rule/sqli.rb +7 -70
  54. data/lib/contrast/agent/reaction_processor.rb +1 -1
  55. data/lib/contrast/agent/request.rb +9 -4
  56. data/lib/contrast/agent/request_context.rb +51 -33
  57. data/lib/contrast/agent/request_handler.rb +7 -3
  58. data/lib/contrast/agent/rule_set.rb +2 -4
  59. data/lib/contrast/agent/scope.rb +32 -20
  60. data/lib/contrast/agent/startup_metrics_telemetry_event.rb +71 -0
  61. data/lib/contrast/agent/static_analysis.rb +5 -3
  62. data/lib/contrast/agent/telemetry.rb +129 -0
  63. data/lib/contrast/agent/telemetry_event.rb +34 -0
  64. data/lib/contrast/agent/thread_watcher.rb +43 -14
  65. data/lib/contrast/agent/tracepoint_hook.rb +16 -3
  66. data/lib/contrast/agent/version.rb +1 -1
  67. data/lib/contrast/agent.rb +6 -1
  68. data/lib/contrast/api/communication/messaging_queue.rb +12 -6
  69. data/lib/contrast/api/communication/service_lifecycle.rb +4 -1
  70. data/lib/contrast/api/communication/socket_client.rb +4 -4
  71. data/lib/contrast/api/decorators/agent_startup.rb +4 -4
  72. data/lib/contrast/api/decorators/application_startup.rb +6 -5
  73. data/lib/contrast/api/decorators/route_coverage.rb +24 -1
  74. data/lib/contrast/components/agent.rb +5 -2
  75. data/lib/contrast/components/api.rb +34 -0
  76. data/lib/contrast/components/app_context.rb +24 -0
  77. data/lib/contrast/components/assess.rb +13 -3
  78. data/lib/contrast/components/base.rb +2 -2
  79. data/lib/contrast/components/config.rb +91 -11
  80. data/lib/contrast/components/contrast_service.rb +10 -2
  81. data/lib/contrast/components/logger.rb +13 -8
  82. data/lib/contrast/components/scope.rb +9 -28
  83. data/lib/contrast/config/api_configuration.rb +22 -0
  84. data/lib/contrast/config/assess_configuration.rb +1 -0
  85. data/lib/contrast/config/base_configuration.rb +14 -6
  86. data/lib/contrast/config/env_variables.rb +25 -0
  87. data/lib/contrast/config/root_configuration.rb +1 -0
  88. data/lib/contrast/config/service_configuration.rb +2 -1
  89. data/lib/contrast/config.rb +1 -0
  90. data/lib/contrast/configuration.rb +22 -15
  91. data/lib/contrast/extension/assess/array.rb +1 -11
  92. data/lib/contrast/extension/assess/eval_trigger.rb +0 -20
  93. data/lib/contrast/extension/assess/fiber.rb +0 -11
  94. data/lib/contrast/extension/assess/hash.rb +0 -10
  95. data/lib/contrast/extension/assess/kernel.rb +1 -10
  96. data/lib/contrast/extension/assess/marshal.rb +3 -11
  97. data/lib/contrast/extension/assess/regexp.rb +0 -11
  98. data/lib/contrast/extension/assess/string.rb +1 -26
  99. data/lib/contrast/extension/extension.rb +61 -0
  100. data/lib/contrast/framework/grape/support.rb +174 -0
  101. data/lib/contrast/framework/manager.rb +56 -18
  102. data/lib/contrast/framework/rack/support.rb +1 -1
  103. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +9 -6
  104. data/lib/contrast/framework/rails/patch/assess_configuration.rb +0 -1
  105. data/lib/contrast/framework/rails/patch/support.rb +35 -30
  106. data/lib/contrast/framework/rails/railtie.rb +1 -1
  107. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +1 -0
  108. data/lib/contrast/framework/rails/support.rb +60 -13
  109. data/lib/contrast/framework/sinatra/support.rb +1 -1
  110. data/lib/contrast/logger/application.rb +4 -0
  111. data/lib/contrast/logger/log.rb +89 -15
  112. data/lib/contrast/utils/assess/propagation_method_utils.rb +129 -0
  113. data/lib/contrast/utils/assess/property/tagged_utils.rb +142 -0
  114. data/lib/contrast/utils/assess/source_method_utils.rb +83 -0
  115. data/lib/contrast/utils/assess/trigger_method_utils.rb +138 -0
  116. data/lib/contrast/utils/class_util.rb +58 -44
  117. data/lib/contrast/utils/exclude_key.rb +20 -0
  118. data/lib/contrast/utils/io_util.rb +43 -35
  119. data/lib/contrast/utils/lru_cache.rb +45 -0
  120. data/lib/contrast/utils/metrics_hash.rb +59 -0
  121. data/lib/contrast/utils/os.rb +23 -0
  122. data/lib/contrast/utils/patching/policy/patch_utils.rb +232 -0
  123. data/lib/contrast/utils/patching/policy/patcher_utils.rb +54 -0
  124. data/lib/contrast/utils/requests_client.rb +150 -0
  125. data/lib/contrast/utils/ruby_ast_rewriter.rb +16 -13
  126. data/lib/contrast/utils/tag_util.rb +2 -1
  127. data/lib/contrast/utils/telemetry.rb +78 -0
  128. data/lib/contrast/utils/telemetry_identifier.rb +137 -0
  129. data/lib/contrast.rb +19 -1
  130. data/resources/assess/policy.json +208 -7
  131. data/resources/deadzone/policy.json +91 -0
  132. data/ruby-agent.gemspec +12 -2
  133. data/service_executables/VERSION +1 -1
  134. data/service_executables/linux/contrast-service +0 -0
  135. data/service_executables/mac/contrast-service +0 -0
  136. metadata +102 -18
  137. data/ext/cs__protect_kernel/cs__protect_kernel.c +0 -47
  138. data/ext/cs__protect_kernel/cs__protect_kernel.h +0 -12
  139. data/lib/contrast/extension/protect/kernel.rb +0 -39
  140. data/lib/contrast/utils/inventory_util.rb +0 -113
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.13.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-11-09 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
- - ext/cs__assess_fiber_track/extconf.rb
560
- - ext/cs__assess_marshal_module/extconf.rb
561
- - ext/cs__protect_kernel/extconf.rb
620
+ - ext/cs__os_information/extconf.rb
621
+ - ext/cs__assess_regexp/extconf.rb
562
622
  - ext/cs__assess_string_interpolation26/extconf.rb
563
- - ext/cs__assess_basic_object/extconf.rb
623
+ - ext/cs__contrast_patch/extconf.rb
564
624
  - ext/cs__assess_active_record_named/extconf.rb
565
- - ext/cs__assess_yield_track/extconf.rb
566
- - ext/cs__assess_kernel/extconf.rb
625
+ - ext/cs__assess_module/extconf.rb
567
626
  - ext/cs__assess_array/extconf.rb
568
- - ext/cs__assess_regexp/extconf.rb
627
+ - ext/cs__assess_kernel/extconf.rb
628
+ - ext/cs__assess_basic_object/extconf.rb
569
629
  - ext/cs__assess_hash/extconf.rb
570
- - ext/cs__contrast_patch/extconf.rb
571
- - ext/cs__assess_module/extconf.rb
630
+ - ext/cs__assess_fiber_track/extconf.rb
631
+ - ext/cs__assess_marshal_module/extconf.rb
632
+ - ext/cs__assess_string/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
@@ -625,9 +688,9 @@ files:
625
688
  - ext/cs__contrast_patch/cs__contrast_patch.c
626
689
  - ext/cs__contrast_patch/cs__contrast_patch.h
627
690
  - ext/cs__contrast_patch/extconf.rb
628
- - ext/cs__protect_kernel/cs__protect_kernel.c
629
- - ext/cs__protect_kernel/cs__protect_kernel.h
630
- - ext/cs__protect_kernel/extconf.rb
691
+ - ext/cs__os_information/cs__os_information.c
692
+ - ext/cs__os_information/cs__os_information.h
693
+ - ext/cs__os_information/extconf.rb
631
694
  - ext/extconf_common.rb
632
695
  - funchook/LICENSE
633
696
  - funchook/Makefile.in
@@ -828,12 +891,14 @@ 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
834
898
  - lib/contrast/agent/inventory/policy/datastores.rb
835
899
  - lib/contrast/agent/inventory/policy/policy.rb
836
900
  - lib/contrast/agent/inventory/policy/trigger_node.rb
901
+ - lib/contrast/agent/metric_telemetry_event.rb
837
902
  - lib/contrast/agent/middleware.rb
838
903
  - lib/contrast/agent/module_data.rb
839
904
  - lib/contrast/agent/patching/policy/after_load_patch.rb
@@ -865,6 +930,7 @@ files:
865
930
  - lib/contrast/agent/protect/rule/no_sqli.rb
866
931
  - lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb
867
932
  - lib/contrast/agent/protect/rule/path_traversal.rb
933
+ - lib/contrast/agent/protect/rule/sql_sample_builder.rb
868
934
  - lib/contrast/agent/protect/rule/sqli.rb
869
935
  - lib/contrast/agent/protect/rule/sqli/default_sql_scanner.rb
870
936
  - lib/contrast/agent/protect/rule/sqli/mysql_sql_scanner.rb
@@ -883,7 +949,10 @@ files:
883
949
  - lib/contrast/agent/rule_set.rb
884
950
  - lib/contrast/agent/scope.rb
885
951
  - lib/contrast/agent/service_heartbeat.rb
952
+ - lib/contrast/agent/startup_metrics_telemetry_event.rb
886
953
  - lib/contrast/agent/static_analysis.rb
954
+ - lib/contrast/agent/telemetry.rb
955
+ - lib/contrast/agent/telemetry_event.rb
887
956
  - lib/contrast/agent/thread.rb
888
957
  - lib/contrast/agent/thread_watcher.rb
889
958
  - lib/contrast/agent/tracepoint_hook.rb
@@ -925,6 +994,7 @@ files:
925
994
  - lib/contrast/api/dtm.pb.rb
926
995
  - lib/contrast/api/settings.pb.rb
927
996
  - lib/contrast/components/agent.rb
997
+ - lib/contrast/components/api.rb
928
998
  - lib/contrast/components/app_context.rb
929
999
  - lib/contrast/components/assess.rb
930
1000
  - lib/contrast/components/base.rb
@@ -939,11 +1009,13 @@ files:
939
1009
  - lib/contrast/components/settings.rb
940
1010
  - lib/contrast/config.rb
941
1011
  - lib/contrast/config/agent_configuration.rb
1012
+ - lib/contrast/config/api_configuration.rb
942
1013
  - lib/contrast/config/application_configuration.rb
943
1014
  - lib/contrast/config/assess_configuration.rb
944
1015
  - lib/contrast/config/assess_rules_configuration.rb
945
1016
  - lib/contrast/config/base_configuration.rb
946
1017
  - lib/contrast/config/default_value.rb
1018
+ - lib/contrast/config/env_variables.rb
947
1019
  - lib/contrast/config/exception_configuration.rb
948
1020
  - lib/contrast/config/heap_dump_configuration.rb
949
1021
  - lib/contrast/config/inventory_configuration.rb
@@ -969,14 +1041,15 @@ files:
969
1041
  - lib/contrast/extension/assess/regexp.rb
970
1042
  - lib/contrast/extension/assess/string.rb
971
1043
  - lib/contrast/extension/delegator.rb
1044
+ - lib/contrast/extension/extension.rb
972
1045
  - lib/contrast/extension/inventory.rb
973
1046
  - lib/contrast/extension/kernel.rb
974
1047
  - lib/contrast/extension/module.rb
975
1048
  - lib/contrast/extension/protect.rb
976
- - lib/contrast/extension/protect/kernel.rb
977
1049
  - lib/contrast/extension/protect/psych.rb
978
1050
  - lib/contrast/extension/thread.rb
979
1051
  - lib/contrast/framework/base_support.rb
1052
+ - lib/contrast/framework/grape/support.rb
980
1053
  - lib/contrast/framework/manager.rb
981
1054
  - lib/contrast/framework/platform_version.rb
982
1055
  - lib/contrast/framework/rack/patch/session_cookie.rb
@@ -1002,26 +1075,37 @@ files:
1002
1075
  - lib/contrast/security_exception.rb
1003
1076
  - lib/contrast/tasks/config.rb
1004
1077
  - lib/contrast/tasks/service.rb
1078
+ - lib/contrast/utils/assess/propagation_method_utils.rb
1079
+ - lib/contrast/utils/assess/property/tagged_utils.rb
1005
1080
  - lib/contrast/utils/assess/sampling_util.rb
1081
+ - lib/contrast/utils/assess/source_method_utils.rb
1006
1082
  - lib/contrast/utils/assess/tracking_util.rb
1083
+ - lib/contrast/utils/assess/trigger_method_utils.rb
1007
1084
  - lib/contrast/utils/class_util.rb
1008
1085
  - lib/contrast/utils/duck_utils.rb
1009
1086
  - lib/contrast/utils/env_configuration_item.rb
1087
+ - lib/contrast/utils/exclude_key.rb
1010
1088
  - lib/contrast/utils/hash_digest.rb
1011
1089
  - lib/contrast/utils/heap_dump_util.rb
1012
1090
  - lib/contrast/utils/invalid_configuration_util.rb
1013
- - lib/contrast/utils/inventory_util.rb
1014
1091
  - lib/contrast/utils/io_util.rb
1015
1092
  - lib/contrast/utils/job_servers_running.rb
1093
+ - lib/contrast/utils/lru_cache.rb
1094
+ - lib/contrast/utils/metrics_hash.rb
1016
1095
  - lib/contrast/utils/object_share.rb
1017
1096
  - lib/contrast/utils/os.rb
1097
+ - lib/contrast/utils/patching/policy/patch_utils.rb
1098
+ - lib/contrast/utils/patching/policy/patcher_utils.rb
1018
1099
  - lib/contrast/utils/preflight_util.rb
1100
+ - lib/contrast/utils/requests_client.rb
1019
1101
  - lib/contrast/utils/resource_loader.rb
1020
1102
  - lib/contrast/utils/ruby_ast_rewriter.rb
1021
1103
  - lib/contrast/utils/sha256_builder.rb
1022
1104
  - lib/contrast/utils/stack_trace_utils.rb
1023
1105
  - lib/contrast/utils/string_utils.rb
1024
1106
  - lib/contrast/utils/tag_util.rb
1107
+ - lib/contrast/utils/telemetry.rb
1108
+ - lib/contrast/utils/telemetry_identifier.rb
1025
1109
  - lib/contrast/utils/thread_tracker.rb
1026
1110
  - lib/contrast/utils/timer.rb
1027
1111
  - resources/assess/policy.json
@@ -1,47 +0,0 @@
1
- /* Copyright (c) 2021 Contrast Security, Inc. See
2
- * https://www.contrastsecurity.com/enduser-terms-0317a for more details. */
3
-
4
- #include "cs__protect_kernel.h"
5
- #include "../cs__common/cs__common.h"
6
- #include <ruby.h>
7
-
8
- static VALUE contrast_protect_fork(const int argc, const VALUE *argv,
9
- const VALUE self) {
10
- VALUE ret;
11
- if (rb_block_given_p()) {
12
- /* We call our hook, but it's a little complicated.
13
- * We wrap the fork block with our own lambda in
14
- * order to instrument it. There are no public
15
- * methods in the Ruby C API to set the prevailing
16
- * block, so we have to use rb_funcall_with_block.
17
- * Also, rb_funcall_with_block does a public call,
18
- * and our method is private.
19
- * So we (as a hack) temporarily set it to public.
20
- */
21
- VALUE wrapper;
22
- wrapper =
23
- rb_funcall_with_block(kernel_protect, rb_sym_protect_kernel_wrapper,
24
- 0, NULL, rb_block_proc());
25
- rb_funcall(rb_mKernel, rb_intern("public"), 1,
26
- ID2SYM(rb_sym_protect_kernel_fork));
27
- ret = rb_funcall_with_block(self, rb_sym_protect_kernel_fork, argc,
28
- argv, wrapper);
29
- rb_funcall(rb_mKernel, rb_intern("private"), 1,
30
- ID2SYM(rb_sym_protect_kernel_fork));
31
- } else {
32
- ret = rb_funcall2(self, rb_sym_protect_kernel_fork, argc, argv);
33
- }
34
- return ret;
35
- }
36
-
37
- void Init_cs__protect_kernel(void) {
38
- VALUE core_protect = rb_define_module_under(core_extensions, "Protect");
39
- kernel_protect = rb_define_module_under(core_protect, "Kernel");
40
- rb_sym_protect_kernel_wrapper = rb_intern("build_wrapper");
41
-
42
- rb_sym_protect_kernel_fork =
43
- contrast_register_patch("Kernel", "fork", &contrast_protect_fork);
44
-
45
- rb_sym_protect_kernel_fork = contrast_register_singleton_patch(
46
- "Kernel", "fork", &contrast_protect_fork);
47
- }
@@ -1,12 +0,0 @@
1
- #include <ruby.h>
2
-
3
- extern VALUE rb_vm_top_self(void);
4
-
5
- static VALUE kernel_protect;
6
- static VALUE rb_sym_protect_kernel_fork;
7
- static VALUE rb_sym_protect_kernel_wrapper;
8
-
9
- static VALUE contrast_protect_fork(const int argc, const VALUE *argv,
10
- const VALUE self);
11
-
12
- void Init_cs__protect_kernel(void);
@@ -1,39 +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 Extension
6
- module Protect
7
- # This Module functions as our patch into the Kernel class for Protect,
8
- # allowing us to track activity as it crosses spawned processes.
9
- module Kernel
10
- class << self
11
- def build_wrapper
12
- lambda {
13
- proc_start
14
- yield
15
- # AtExitHook handles sending any messages generated in the new forked process
16
- }
17
- end
18
-
19
- def proc_start
20
- context = Contrast::Agent::REQUEST_TRACKER.current
21
- return unless context
22
-
23
- context.reset_activity
24
- end
25
-
26
- def instrument
27
- @_instrument ||= begin
28
- require 'cs__protect_kernel/cs__protect_kernel'
29
- true
30
- end
31
- rescue StandardError, LoadError => e
32
- logger.error('Error loading kernel protect patch', e)
33
- false
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -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