mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
- SSO via OmniAuth OpenID Connect (Authentik, Keycloak, …): link by stable subject, by verified email, or from the profile; optional auto-create, admin-group sync, and turning password sign-in off - Current password required to change email or password; password changes and resets sign out other sessions; idle sessions expire after 30 days; "sign out everywhere else"; session reset on sign-in - Rate-limit password resets; scope squawk components to the aircraft - Strict Content Security Policy with nonces (inline handlers removed), Permissions-Policy and COOP headers; file links expire after an hour Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.5 KiB
Ruby
34 lines
1.5 KiB
Ruby
# Content Security Policy: scripts only from this site, plus inline scripts
|
|
# carrying the per-session nonce (the theme snippet, the importmap, Chartkick).
|
|
# Inline style attributes stay allowed (Chartkick sizes and a few views use them).
|
|
Rails.application.configure do
|
|
config.content_security_policy do |policy|
|
|
policy.default_src :self
|
|
policy.script_src :self
|
|
policy.style_src :self, :unsafe_inline
|
|
policy.img_src :self, :data, :blob
|
|
policy.font_src :self, :data
|
|
policy.connect_src :self
|
|
policy.media_src :self, :blob
|
|
policy.frame_src :self # PDFs in the document viewer
|
|
policy.worker_src :self
|
|
policy.manifest_src :self
|
|
policy.object_src :none
|
|
policy.base_uri :self
|
|
policy.frame_ancestors :self
|
|
# Signing in with SSO posts here, then redirects to the provider.
|
|
policy.form_action(*[ :self, (ENV["OIDC_ISSUER"].present? ? ENV["OIDC_ISSUER"][%r{\Ahttps?://[^/]+}i] : nil) ].compact)
|
|
end
|
|
|
|
# Stable for a session, so pages Turbo swaps in keep matching the policy
|
|
# the browser got with the first page load.
|
|
config.content_security_policy_nonce_generator = ->(request) { request.session[:csp_nonce] ||= SecureRandom.base64(16) }
|
|
config.content_security_policy_nonce_directives = %w[script-src]
|
|
end
|
|
|
|
# Uploaded files are served as they are (PDFs need the browser's viewer);
|
|
# dangerous types are already sent as downloads, with nosniff.
|
|
Rails.application.config.to_prepare do
|
|
ActiveStorage::BaseController.content_security_policy false
|
|
end
|