contrast-agent 3.11.0 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/.flayignore +1 -0
  3. data/ext/cs__assess_active_record_named/cs__active_record_named.c +7 -2
  4. data/ext/cs__assess_active_record_named/cs__active_record_named.h +1 -0
  5. data/ext/cs__assess_array/cs__assess_array.c +2 -1
  6. data/ext/cs__assess_array/cs__assess_array.h +1 -0
  7. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +3 -7
  8. data/ext/cs__assess_basic_object/cs__assess_basic_object.h +2 -1
  9. data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -1
  10. data/ext/cs__assess_module/cs__assess_module.c +5 -7
  11. data/ext/cs__assess_module/cs__assess_module.h +3 -0
  12. data/ext/cs__common/cs__common.c +1 -1
  13. data/ext/cs__protect_kernel/cs__protect_kernel.c +4 -2
  14. data/ext/cs__protect_kernel/cs__protect_kernel.h +1 -0
  15. data/funchook/autom4te.cache/output.0 +13 -1
  16. data/funchook/autom4te.cache/requests +49 -48
  17. data/funchook/autom4te.cache/traces.0 +3 -0
  18. data/funchook/config.log +217 -378
  19. data/funchook/config.status +24 -23
  20. data/funchook/configure +13 -1
  21. data/funchook/src/Makefile +7 -7
  22. data/funchook/src/config.h +2 -2
  23. data/funchook/src/decoder.o +0 -0
  24. data/funchook/src/distorm.o +0 -0
  25. data/funchook/src/funchook.o +0 -0
  26. data/funchook/src/funchook_io.o +0 -0
  27. data/funchook/src/funchook_syscall.o +0 -0
  28. data/funchook/src/funchook_unix.o +0 -0
  29. data/funchook/src/funchook_x86.o +0 -0
  30. data/funchook/src/instructions.o +0 -0
  31. data/funchook/src/insts.o +0 -0
  32. data/funchook/src/libfunchook.so +0 -0
  33. data/funchook/src/mnemonics.o +0 -0
  34. data/funchook/src/operands.o +0 -0
  35. data/funchook/src/os_func.o +0 -0
  36. data/funchook/src/os_func_unix.o +0 -0
  37. data/funchook/src/prefix.o +0 -0
  38. data/funchook/src/printf_base.o +0 -0
  39. data/funchook/src/textdefs.o +0 -0
  40. data/funchook/src/wstring.o +0 -0
  41. data/funchook/test/Makefile +2 -2
  42. data/funchook/test/funchook_test +0 -0
  43. data/funchook/test/libfunchook_test.so +0 -0
  44. data/funchook/test/test_main.o +0 -0
  45. data/funchook/test/x86_64_test.o +0 -0
  46. data/lib/contrast.rb +0 -1
  47. data/lib/contrast/agent.rb +19 -22
  48. data/lib/contrast/agent/assess.rb +0 -9
  49. data/lib/contrast/agent/assess/policy/patcher.rb +1 -0
  50. data/lib/contrast/agent/assess/policy/policy_node.rb +1 -1
  51. data/lib/contrast/agent/assess/policy/policy_scanner.rb +1 -1
  52. data/lib/contrast/agent/assess/policy/propagation_method.rb +3 -0
  53. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  54. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
  55. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +90 -0
  56. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +57 -0
  57. data/lib/contrast/agent/assess/policy/trigger_method.rb +3 -7
  58. data/lib/contrast/agent/assess/policy/trigger_node.rb +4 -1
  59. data/lib/contrast/agent/assess/rule/base.rb +0 -15
  60. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +22 -5
  61. data/lib/contrast/agent/assess/rule/redos.rb +0 -1
  62. data/lib/contrast/agent/at_exit_hook.rb +2 -2
  63. data/lib/contrast/agent/class_reopener.rb +9 -4
  64. data/lib/contrast/agent/exclusion_matcher.rb +0 -1
  65. data/lib/contrast/agent/inventory/policy/datastores.rb +54 -0
  66. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  67. data/lib/contrast/agent/middleware.rb +38 -34
  68. data/lib/contrast/agent/patching/policy/after_load_patch.rb +11 -2
  69. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +51 -56
  70. data/lib/contrast/agent/patching/policy/patch.rb +2 -1
  71. data/lib/contrast/agent/patching/policy/patcher.rb +10 -12
  72. data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
  73. data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
  74. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +63 -0
  75. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +52 -0
  76. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +68 -0
  77. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +117 -0
  78. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +54 -0
  79. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +129 -0
  80. data/lib/contrast/agent/protect/policy/policy.rb +6 -6
  81. data/lib/contrast/agent/protect/policy/rule_applicator.rb +51 -0
  82. data/lib/contrast/agent/protect/rule.rb +0 -5
  83. data/lib/contrast/agent/protect/rule/base.rb +6 -5
  84. data/lib/contrast/agent/protect/rule/cmd_injection.rb +3 -3
  85. data/lib/contrast/agent/protect/rule/path_traversal.rb +2 -7
  86. data/lib/contrast/agent/protect/rule/sqli.rb +4 -4
  87. data/lib/contrast/agent/railtie.rb +1 -0
  88. data/lib/contrast/agent/request.rb +2 -6
  89. data/lib/contrast/agent/request_context.rb +5 -6
  90. data/lib/contrast/agent/request_handler.rb +2 -2
  91. data/lib/contrast/agent/response.rb +0 -69
  92. data/lib/contrast/agent/service_heartbeat.rb +2 -2
  93. data/lib/contrast/agent/socket_client.rb +8 -8
  94. data/lib/contrast/agent/static_analysis.rb +2 -3
  95. data/lib/contrast/agent/version.rb +1 -1
  96. data/lib/contrast/api/decorators/application_settings.rb +1 -1
  97. data/lib/contrast/api/speedracer.rb +1 -1
  98. data/lib/contrast/components/agent.rb +17 -12
  99. data/lib/contrast/components/app_context.rb +33 -1
  100. data/lib/contrast/components/assess.rb +25 -15
  101. data/lib/contrast/components/contrast_service.rb +23 -67
  102. data/lib/contrast/components/interface.rb +4 -12
  103. data/lib/contrast/components/inventory.rb +5 -1
  104. data/lib/contrast/components/logger.rb +2 -2
  105. data/lib/contrast/components/protect.rb +40 -4
  106. data/lib/contrast/components/scope.rb +2 -52
  107. data/lib/contrast/components/settings.rb +24 -18
  108. data/lib/contrast/config/protect_rules_configuration.rb +0 -1
  109. data/lib/contrast/{extensions/ruby_core → extension}/assess.rb +12 -14
  110. data/lib/contrast/extension/assess/array.rb +77 -0
  111. data/lib/contrast/{extensions/ruby_core → extension}/assess/assess_extension.rb +2 -2
  112. data/lib/contrast/{extensions/ruby_core → extension}/assess/erb.rb +0 -0
  113. data/lib/contrast/extension/assess/eval_trigger.rb +78 -0
  114. data/lib/contrast/{extensions/ruby_core → extension}/assess/exec_trigger.rb +1 -1
  115. data/lib/contrast/{extensions/ruby_core → extension}/assess/fiber.rb +6 -5
  116. data/lib/contrast/{extensions/ruby_core → extension}/assess/hash.rb +2 -2
  117. data/lib/contrast/extension/assess/kernel.rb +110 -0
  118. data/lib/contrast/{extensions/ruby_core → extension}/assess/regexp.rb +4 -4
  119. data/lib/contrast/{extensions/ruby_core → extension}/assess/string.rb +5 -5
  120. data/lib/contrast/{extensions/ruby_core → extension}/delegator.rb +0 -0
  121. data/lib/contrast/{extensions/ruby_core → extension}/inventory.rb +2 -2
  122. data/lib/contrast/extension/kernel.rb +54 -0
  123. data/lib/contrast/{extensions/ruby_core → extension}/module.rb +0 -0
  124. data/lib/contrast/{extensions/ruby_core → extension}/protect.rb +2 -2
  125. data/lib/contrast/extension/protect/kernel.rb +44 -0
  126. data/lib/contrast/{extensions/ruby_core → extension}/protect/psych.rb +1 -1
  127. data/lib/contrast/{extensions/ruby_core → extension}/thread.rb +0 -0
  128. data/lib/contrast/framework/base_support.rb +22 -0
  129. data/lib/contrast/framework/manager.rb +33 -8
  130. data/lib/contrast/framework/rack/patch/session_cookie.rb +126 -0
  131. data/lib/contrast/framework/rack/patch/support.rb +24 -0
  132. data/lib/contrast/framework/rack/support.rb +22 -0
  133. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +43 -0
  134. data/lib/contrast/framework/rails/patch/assess_configuration.rb +103 -0
  135. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +31 -0
  136. data/lib/contrast/framework/rails/patch/support.rb +67 -0
  137. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +34 -0
  138. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +39 -0
  139. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +73 -0
  140. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +33 -0
  141. data/lib/contrast/framework/rails/support.rb +115 -0
  142. data/lib/contrast/framework/sinatra/application_helper.rb +51 -0
  143. data/lib/contrast/framework/sinatra/patch/base.rb +83 -0
  144. data/lib/contrast/framework/sinatra/patch/support.rb +27 -0
  145. data/lib/contrast/framework/sinatra/support.rb +109 -0
  146. data/lib/contrast/logger/application.rb +80 -0
  147. data/lib/contrast/{agent/logger.rb → logger/log.rb} +23 -54
  148. data/lib/contrast/logger/time.rb +50 -0
  149. data/lib/contrast/tasks/config.rb +54 -0
  150. data/lib/contrast/tasks/service.rb +1 -5
  151. data/lib/contrast/utils/class_util.rb +1 -1
  152. data/lib/contrast/utils/gemfile_reader.rb +2 -2
  153. data/lib/contrast/utils/hash_digest.rb +2 -7
  154. data/lib/contrast/utils/invalid_configuration_util.rb +3 -3
  155. data/lib/contrast/utils/job_servers_running.rb +4 -2
  156. data/lib/contrast/utils/object_share.rb +0 -1
  157. data/lib/contrast/utils/service_response_util.rb +14 -12
  158. data/lib/contrast/utils/service_sender_util.rb +78 -21
  159. data/resources/assess/policy.json +9 -50
  160. data/resources/inventory/policy.json +2 -2
  161. data/resources/protect/policy.json +6 -6
  162. data/ruby-agent.gemspec +5 -1
  163. data/service_executables/VERSION +1 -1
  164. data/service_executables/linux/contrast-service +0 -0
  165. data/service_executables/mac/contrast-service +0 -0
  166. metadata +69 -83
  167. data/funchook/src/libfunchook.dylib +0 -0
  168. data/funchook/test/libfunchook_test.so.dSYM/Contents/Info.plist +0 -20
  169. data/funchook/test/libfunchook_test.so.dSYM/Contents/Resources/DWARF/libfunchook_test.so +0 -0
  170. data/lib/contrast/agent/assess/rule/csrf.rb +0 -66
  171. data/lib/contrast/agent/assess/rule/csrf/csrf_action.rb +0 -28
  172. data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +0 -53
  173. data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +0 -136
  174. data/lib/contrast/agent/assess/rule/response_scanning_rule.rb +0 -47
  175. data/lib/contrast/agent/assess/rule/response_watcher.rb +0 -36
  176. data/lib/contrast/agent/assess/rule/watcher.rb +0 -36
  177. data/lib/contrast/agent/feature_state.rb +0 -346
  178. data/lib/contrast/agent/protect/rule/csrf.rb +0 -119
  179. data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +0 -100
  180. data/lib/contrast/agent/protect/rule/csrf/csrf_token_injector.rb +0 -85
  181. data/lib/contrast/agent/settings_state.rb +0 -88
  182. data/lib/contrast/api/decorators/exclusion.rb +0 -20
  183. data/lib/contrast/extensions/framework/rack/cookie.rb +0 -24
  184. data/lib/contrast/extensions/framework/rack/request.rb +0 -24
  185. data/lib/contrast/extensions/framework/rack/response.rb +0 -23
  186. data/lib/contrast/extensions/framework/rails/action_controller_inheritance.rb +0 -39
  187. data/lib/contrast/extensions/framework/rails/action_controller_railties_helper_inherited.rb +0 -20
  188. data/lib/contrast/extensions/framework/rails/active_record.rb +0 -26
  189. data/lib/contrast/extensions/framework/rails/active_record_named.rb +0 -58
  190. data/lib/contrast/extensions/framework/rails/active_record_time_zone_inherited.rb +0 -21
  191. data/lib/contrast/extensions/framework/rails/buffer.rb +0 -28
  192. data/lib/contrast/extensions/framework/rails/configuration.rb +0 -27
  193. data/lib/contrast/extensions/framework/sinatra/base.rb +0 -59
  194. data/lib/contrast/extensions/ruby_core/assess/array.rb +0 -59
  195. data/lib/contrast/extensions/ruby_core/assess/basic_object.rb +0 -15
  196. data/lib/contrast/extensions/ruby_core/assess/kernel.rb +0 -96
  197. data/lib/contrast/extensions/ruby_core/assess/module.rb +0 -14
  198. data/lib/contrast/extensions/ruby_core/assess/tilt_template_trigger.rb +0 -78
  199. data/lib/contrast/extensions/ruby_core/assess/xpath_library_trigger.rb +0 -40
  200. data/lib/contrast/extensions/ruby_core/eval_trigger.rb +0 -51
  201. data/lib/contrast/extensions/ruby_core/inventory/datastores.rb +0 -37
  202. data/lib/contrast/extensions/ruby_core/protect/applies_command_injection_rule.rb +0 -61
  203. data/lib/contrast/extensions/ruby_core/protect/applies_deserialization_rule.rb +0 -50
  204. data/lib/contrast/extensions/ruby_core/protect/applies_no_sqli_rule.rb +0 -66
  205. data/lib/contrast/extensions/ruby_core/protect/applies_path_traversal_rule.rb +0 -115
  206. data/lib/contrast/extensions/ruby_core/protect/applies_sqli_rule.rb +0 -53
  207. data/lib/contrast/extensions/ruby_core/protect/applies_xxe_rule.rb +0 -127
  208. data/lib/contrast/extensions/ruby_core/protect/kernel.rb +0 -30
  209. data/lib/contrast/extensions/ruby_core/protect/rule_applicator.rb +0 -50
  210. data/lib/contrast/framework/rails_support.rb +0 -104
  211. data/lib/contrast/framework/sinatra_application_helper.rb +0 -49
  212. data/lib/contrast/framework/sinatra_support.rb +0 -104
  213. data/lib/contrast/utils/data_store_util.rb +0 -23
  214. data/lib/contrast/utils/rack_assess_session_cookie.rb +0 -104
  215. data/lib/contrast/utils/rails_assess_configuration.rb +0 -95
  216. data/lib/contrast/utils/random_util.rb +0 -22
  217. data/resources/csrf/inject.js +0 -44
@@ -1,23 +0,0 @@
1
- # Copyright (c) 2020 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 Utils
6
- # Utility class used to determine information about the current data store
7
- # on which a query was executed or to which the application is connected.
8
- module DataStoreUtil
9
- def self.report_data_store data_store
10
- return unless data_store
11
-
12
- context = Contrast::Agent::REQUEST_TRACKER.current
13
- return unless context&.activity
14
-
15
- context.activity.technologies[data_store] = true
16
- context.activity.query_count += 1
17
- return unless context.activity.query_count == 1
18
-
19
- Contrast::Utils::InventoryUtil.append_db_config(context.activity)
20
- end
21
- end
22
- end
23
- end
@@ -1,104 +0,0 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- cs__scoped_require 'contrast/components/interface'
5
-
6
- module Contrast
7
- module Utils
8
- # This module is used to analyze non-rails session storage configuration for assess vulnerabilities
9
- module RackAssessSessionCookie
10
- include Contrast::Components::Interface
11
-
12
- access_component :analysis, :logging, :scope
13
-
14
- CS__SECURE_RULE_NAME = 'secure-flag-missing'
15
- CS__HTTPONLY_NAME = 'rails-http-only-disabled'
16
- CS__SESSION_TIMEOUT_NAME = 'session-timeout'
17
- SAFE_SESSION_TIMEOUT = (30 * 60 * 60)
18
- class << self
19
- include Contrast::Utils::InvalidConfigurationUtil
20
-
21
- def analyze_cookie_initialization options
22
- return if PROTECT.enabled?
23
-
24
- apply_session_timeout(options)
25
- apply_httponly(options)
26
- apply_secure_session(options)
27
- end
28
-
29
- def vulnerable_setting?(setting_key,
30
- safe_settings_value,
31
- options, safe_default: true,
32
- comparison_type: nil)
33
- # In most cases, Rack is pretty nice and the default value is safe
34
- return !safe_default unless options&.key?(setting_key)
35
-
36
- value = options[setting_key]
37
-
38
- return value.to_i > safe_settings_value.to_i if comparison_type&.to_sym == :greater_than
39
-
40
- value != safe_settings_value
41
- end
42
-
43
- def apply_secure_session options
44
- return unless vulnerable_setting?(
45
- :secure,
46
- true,
47
- options,
48
- safe_default: false)
49
-
50
- with_contrast_scope do
51
- cs__report_finding(
52
- CS__SECURE_RULE_NAME,
53
- options,
54
- caller_locations(10, 9)[0])
55
- end
56
- rescue StandardError => e
57
- begin
58
- logger.error('Unable to track call to secure session', e)
59
- rescue StandardError
60
- nil
61
- end
62
- end
63
-
64
- def apply_session_timeout options
65
- return unless vulnerable_setting?(:expire_after,
66
- SAFE_SESSION_TIMEOUT,
67
- options,
68
- safe_default: false,
69
- comparison_type: :greater_than)
70
-
71
- with_contrast_scope do
72
- cs__report_finding(
73
- CS__SESSION_TIMEOUT_NAME,
74
- options,
75
- caller_locations(10, 9)[0])
76
- end
77
- rescue StandardError => e
78
- begin
79
- logger.error('Unable to track call to set session timeout', e)
80
- rescue StandardError
81
- nil
82
- end
83
- end
84
-
85
- def apply_httponly options
86
- return unless vulnerable_setting?(:httponly, true, options)
87
-
88
- with_contrast_scope do
89
- cs__report_finding(
90
- CS__HTTPONLY_NAME,
91
- options,
92
- caller_locations(10, 9)[0])
93
- end
94
- rescue StandardError => e
95
- begin
96
- logger.error('Unable to track call to httponly', e)
97
- rescue StandardError
98
- nil
99
- end
100
- end
101
- end
102
- end
103
- end
104
- end
@@ -1,95 +0,0 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- cs__scoped_require 'contrast/components/interface'
5
-
6
- module Contrast
7
- module Utils
8
- # This module is used to analyze rails session storage configuration for assess vulnerabilities
9
- module RailsAssessConfiguration
10
- include Contrast::Components::Interface
11
-
12
- access_component :analysis, :logging, :scope
13
-
14
- CS__SESSION_TIMEOUT_NAME = 'session-timeout'
15
- SAFE_SESSION_TIMEOUT = (30 * 60 * 1000)
16
- CS__SECURE_RULE_NAME = 'secure-flag-missing'
17
- CS__HTTPONLY_RULE_NAME = 'rails-http-only-disabled'
18
-
19
- class << self
20
- include Contrast::Utils::InvalidConfigurationUtil
21
-
22
- def analyze_session_store *args
23
- return if PROTECT.enabled?
24
-
25
- apply_httponly_disabled(*args)
26
- apply_secure_cookie_disabled(*args)
27
- apply_session_timeout(*args)
28
- end
29
-
30
- def vulnerable_setting? setting_key, safe_settings_value, original_args, safe_default: true, comparison_type: nil
31
- # In most cases, Rails is pretty nice and the default value is safe
32
- return !safe_default unless original_args && original_args.length > 1
33
-
34
- # If the user overrode some args, but not ours, fall back on the default
35
- rails_session_settings = original_args[1]
36
- return !safe_default unless rails_session_settings&.key?(setting_key)
37
-
38
- value = rails_session_settings[setting_key]
39
-
40
- return value.to_i > safe_settings_value.to_i if comparison_type&.to_sym == :greater_than
41
-
42
- value != safe_settings_value
43
- end
44
-
45
- def apply_session_timeout *args
46
- return if ASSESS.rule_disabled? CS__SESSION_TIMEOUT_NAME
47
- return unless vulnerable_setting?(:expire_after, SAFE_SESSION_TIMEOUT, args, comparison_type: :greater_than, safe_default: false)
48
-
49
- rails_session_settings = args[1]
50
- with_contrast_scope do
51
- cs__report_finding(CS__SESSION_TIMEOUT_NAME, rails_session_settings, caller_locations(5, 4)[0])
52
- end
53
- rescue StandardError => e
54
- begin
55
- logger.error('Unable to track call to set session timeout', e)
56
- rescue StandardError
57
- nil
58
- end
59
- end
60
-
61
- def apply_secure_cookie_disabled *args
62
- return if ASSESS.rule_disabled? CS__SECURE_RULE_NAME
63
- return unless vulnerable_setting?(:secure, true, args)
64
-
65
- rails_session_settings = args[1]
66
- with_contrast_scope do
67
- cs__report_finding(CS__SECURE_RULE_NAME, rails_session_settings, caller_locations(5, 4)[0])
68
- end
69
- rescue StandardError => e
70
- begin
71
- logger.error('Unable to track call to disable secure cookies', e)
72
- rescue StandardError
73
- nil
74
- end
75
- end
76
-
77
- def apply_httponly_disabled *args
78
- return if ASSESS.rule_disabled? CS__HTTPONLY_RULE_NAME
79
- return unless vulnerable_setting?(:httponly, true, args)
80
-
81
- rails_session_settings = args[1]
82
- with_contrast_scope do
83
- cs__report_finding(CS__HTTPONLY_RULE_NAME, rails_session_settings, caller_locations(5, 4)[0])
84
- end
85
- rescue StandardError => e
86
- begin
87
- logger.error('Unable to track call to disable httponly in session cookie', e)
88
- rescue StandardError
89
- nil
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end
@@ -1,22 +0,0 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- cs__scoped_require 'securerandom'
5
-
6
- module Contrast
7
- module Utils
8
- # Utilites for generating random strings
9
- class RandomUtil
10
- RANDOM_CHARS = (('0'..'9').to_a + ('A'..'Z').to_a).cs__freeze
11
- RANDOM_LENGTH = RANDOM_CHARS.length
12
-
13
- def self.secure_random_string len
14
- arr = []
15
- len.to_i.times do
16
- arr << RANDOM_CHARS[SecureRandom.random_number(RANDOM_LENGTH)]
17
- end
18
- arr.join
19
- end
20
- end
21
- end
22
- end
@@ -1,44 +0,0 @@
1
- <script>
2
- function _contrast_isSameOrigin(action) {
3
- var thisDomain = document.domain;
4
- var parser = document.createElement('a');
5
- parser.href = action;
6
- return parser.hostname == thisDomain;
7
- }
8
-
9
- function _contrast_addTokenToForms() {
10
- for(var i=0;i<document.forms.length;i++) {
11
- var form = document.forms[i];
12
- var action = form.action;
13
- if(!!action || _contrast_isSameOrigin(action)) {
14
- if(!form._contrast_tokenized) {
15
- var input = document.createElement("input");
16
- input.setAttribute("type", "hidden");
17
- input.setAttribute("name", "!TOKEN_NAME!");
18
- input.setAttribute("value", "!TOKEN_VALUE!");
19
- form.appendChild(input);
20
- form._contrast_tokenized = true;
21
- }
22
- }
23
- }
24
- }
25
-
26
- (function() {_contrast_addTokenToForms();})();
27
-
28
- var _contrast_watchNewForms = (function() {
29
- var MutationObserver = window.MutationObserver || window.WebKitMutationObserver, eventListenerSupported = window.addEventListener;
30
- return function(obj, callback) {
31
- if(MutationObserver) {
32
- var obs = new MutationObserver(function(mutations, observer) {
33
- if( mutations[0].addedNodes.length )
34
- callback();
35
- });
36
- obs.observe(obj, { childList:true, subtree:true });
37
- } else if(eventListenerSupported) {
38
- obj.addEventListener('DOMNodeInserted', callback, false);
39
- }
40
- }
41
- })();
42
-
43
- _contrast_watchNewForms(document.body, function() { _contrast_addTokenToForms(); });
44
- </script>