mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
Security hardening and OpenID Connect single sign-on
- 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>
This commit is contained in:
1 parent
2bfcb845ca
commit
ac4da93aaf
27 files changed
+708
-47
No files matched your search
@@ -3,14 +3,31 @@ class ProfilesController < ApplicationController
|
||||
@user = current_user
|
||||
end
|
||||
|
||||
# Changing the email or password needs the current password, so a session
|
||||
# left open somewhere can't be turned into a takeover of the account.
|
||||
def update
|
||||
@user = current_user
|
||||
attrs = params.require(:user).permit(:name, :email_address, :password, :password_confirmation)
|
||||
attrs = attrs.except(:password, :password_confirmation) if attrs[:password].blank?
|
||||
if @user.update(attrs)
|
||||
new_email = User.normalize_value_for(:email_address, attrs[:email_address].to_s) if attrs.key?(:email_address)
|
||||
sensitive = (new_email && new_email != @user.email_address) || attrs.key?(:password)
|
||||
# Checked before assigning: setting a new password replaces the digest at once.
|
||||
if sensitive && !@user.authenticate_password(params.dig(:user, :current_password).to_s)
|
||||
@user.assign_attributes(attrs.except(:password, :password_confirmation))
|
||||
@user.errors.add(:base, "Enter your current password to change your email or password")
|
||||
return render :edit, status: :unprocessable_entity
|
||||
end
|
||||
@user.assign_attributes(attrs)
|
||||
if @user.save
|
||||
@user.sessions.where.not(id: Current.session.id).destroy_all if attrs.key?(:password)
|
||||
redirect_to root_path, notice: "Profile updated."
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def sign_out_others
|
||||
count = current_user.sessions.where.not(id: Current.session.id).destroy_all.size
|
||||
redirect_to edit_profile_path, notice: "Signed out #{helpers.pluralize(count, 'other session')}."
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user