mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
- Refuse to start with a placeholder or short SECRET_KEY_BASE (under 32 characters); warn and fail sam:doctor under 64. .env.example no longer ships a placeholder. - First-run setup needs a one-time code printed only in the server log, so only whoever runs the server can create the admin account. - AirTrail: the server resolves the address and connects to exactly that; never the server itself or link-local addresses (cloud metadata); private-network addresses only for admins or hosts in AIRTRAIL_ALLOWED_HOSTS. - Host authorization when APP_HOST is set: APP_HOST, the APP_URL host, ALLOWED_HOSTS, localhost and IP addresses; /up exempt. A blocked name gets a short explanation instead of a blank 403. - docker-compose.direct.yml: HTTPS without a proxy via Thruster's built-in Let's Encrypt (TLS_DOMAIN). - Notes' Markdown no longer allows the unused class attribute. - README, .env.example and the user guide updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.2 KiB
Ruby
28 lines
1.2 KiB
Ruby
# The application secret key signs the sign-in cookie and protects stored
|
|
# secrets (two-factor keys, API keys), so anyone who can guess it can sign in
|
|
# as anyone. A placeholder or short key stops the app from starting; one
|
|
# shorter than what `bin/rails secret` makes is reported by sam:doctor.
|
|
module SecretKeyCheck
|
|
MIN = 32 # below this, refuse to start
|
|
RECOMMENDED = 64 # below this, warn
|
|
PLACEHOLDERS = %w[change-me changeme change_me secret password your-secret-key replace-me example].freeze
|
|
|
|
module_function
|
|
|
|
# :ok, :weak or :unsafe
|
|
def strength(key = ENV["SECRET_KEY_BASE"].to_s)
|
|
return :unsafe if PLACEHOLDERS.include?(key.strip.downcase) || key.length < MIN || key.chars.uniq.size < 10
|
|
key.length < RECOMMENDED ? :weak : :ok
|
|
end
|
|
|
|
def verify!(key = ENV["SECRET_KEY_BASE"].to_s)
|
|
case strength(key)
|
|
when :unsafe
|
|
abort "SECRET_KEY_BASE is a placeholder or too short (#{key.length} characters). " \
|
|
"Set it to the output of `bin/rails secret` (128 random characters) and start again."
|
|
when :weak
|
|
Rails.logger.warn("[security] SECRET_KEY_BASE is only #{key.length} characters; `bin/rails secret` makes 128.")
|
|
end
|
|
end
|
|
end
|