lib/rails/application.rb in railties-7.2.0.beta2 vs lib/rails/application.rb in railties-7.2.0.beta3
- old
+ new
@@ -205,21 +205,24 @@
# This verifier can be used to generate and verify signed messages in the application.
#
# It is recommended not to use the same verifier for different things, so you can get different
# verifiers passing the +verifier_name+ argument.
#
+ # For instance, +ActiveStorage::Blob.signed_id_verifier+ is implemented using this feature, which assures that
+ # the IDs strings haven't been tampered with and are safe to use in a finder.
+ #
+ # See the ActiveSupport::MessageVerifier documentation for more information.
+ #
# ==== Parameters
#
# * +verifier_name+ - the name of the message verifier.
#
# ==== Examples
#
- # message = Rails.application.message_verifier('sensitive_data').generate('my sensible data')
- # Rails.application.message_verifier('sensitive_data').verify(message)
- # # => 'my sensible data'
- #
- # See the ActiveSupport::MessageVerifier documentation for more information.
+ # message = Rails.application.message_verifier('my_purpose').generate('data to sign against tampering')
+ # Rails.application.message_verifier('my_purpose').verify(message)
+ # # => 'data to sign against tampering'
def message_verifier(verifier_name)
message_verifiers[verifier_name]
end
# A managed collection of deprecators (ActiveSupport::Deprecation::Deprecators).
@@ -455,17 +458,11 @@
#
# In all other environments, we look for it first in <tt>ENV["SECRET_KEY_BASE"]</tt>,
# then +credentials.secret_key_base+. For most applications, the correct place to store it is in the
# encrypted credentials file.
def secret_key_base
- if Rails.env.local? || ENV["SECRET_KEY_BASE_DUMMY"]
- config.secret_key_base ||= generate_local_secret
- else
- validate_secret_key_base(
- ENV["SECRET_KEY_BASE"] || credentials.secret_key_base
- )
- end
+ config.secret_key_base
end
# Returns an ActiveSupport::EncryptedConfiguration instance for the
# credentials file specified by +config.credentials.content_path+.
#
@@ -614,42 +611,15 @@
def default_middleware_stack # :nodoc:
default_stack = DefaultMiddlewareStack.new(self, config, paths)
default_stack.build_stack
end
- def validate_secret_key_base(secret_key_base)
- if secret_key_base.is_a?(String) && secret_key_base.present?
- secret_key_base
- elsif secret_key_base
- raise ArgumentError, "`secret_key_base` for #{Rails.env} environment must be a type of String`"
- else
- raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
- end
- end
-
def ensure_generator_templates_added
configured_paths = config.generators.templates
configured_paths.unshift(*(paths["lib/templates"].existent - configured_paths))
end
private
- def generate_local_secret
- if config.secret_key_base.nil?
- key_file = Rails.root.join("tmp/local_secret.txt")
-
- if File.exist?(key_file)
- config.secret_key_base = File.binread(key_file)
- else
- random_key = SecureRandom.hex(64)
- FileUtils.mkdir_p(key_file.dirname)
- File.binwrite(key_file, random_key)
- config.secret_key_base = File.binread(key_file)
- end
- end
-
- config.secret_key_base
- end
-
def build_request(env)
req = super
env["ORIGINAL_FULLPATH"] = req.fullpath
env["ORIGINAL_SCRIPT_NAME"] = req.script_name
req