mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Harden installs reachable from the internet without a proxy
- 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>
This commit is contained in:
1 parent
faae719b12
commit
5876c07a1a
20 files changed
+319
-29
No files matched your search
@@ -100,12 +100,26 @@ Rails.application.configure do
|
||||
# Only use :id for inspections in production.
|
||||
config.active_record.attributes_for_inspect = [ :id ]
|
||||
|
||||
# Enable DNS rebinding protection and other `Host` header attacks.
|
||||
# config.hosts = [
|
||||
# "example.com", # Allow requests from example.com
|
||||
# /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
|
||||
# ]
|
||||
#
|
||||
# Skip DNS rebinding protection for the default health check endpoint.
|
||||
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
|
||||
# Answer only for the app's own names (stops DNS rebinding and forged Host
|
||||
# headers): APP_HOST, the APP_URL host, ALLOWED_HOSTS, localhost and IP
|
||||
# addresses (a rebinding attack needs a name). Off when APP_HOST isn't set.
|
||||
if ENV["APP_HOST"].present?
|
||||
config.hosts = [
|
||||
ENV["APP_HOST"].sub(/:\d+\z/, ""),
|
||||
(URI.parse(ENV["APP_URL"]).host if ENV["APP_URL"].present?),
|
||||
*ENV.fetch("ALLOWED_HOSTS", "").split(",").map(&:strip),
|
||||
"localhost",
|
||||
IPAddr.new("0.0.0.0/0"),
|
||||
IPAddr.new("::/0")
|
||||
].compact_blank
|
||||
config.host_authorization = {
|
||||
exclude: ->(request) { request.path == "/up" },
|
||||
# Say why, rather than a blank page: usually a name that's simply missing.
|
||||
response_app: ->(env) {
|
||||
host = ActionDispatch::Request.new(env).host.to_s.gsub(/[^a-z0-9.\-:\[\]]/i, "").first(253)
|
||||
[ 403, { "content-type" => "text/plain; charset=utf-8" },
|
||||
[ "This server doesn't answer for \"#{host}\". If that's a name for this app, add it to ALLOWED_HOSTS (comma-separated) and restart.\n" ] ]
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user