Sign-in hardening: lockout, stronger passwords, authenticator codes

- 10 failed sign-ins in a row (password, authenticator code, or password
  at signing) lock an account for 15 minutes from any address; the user
  is emailed; admins can unlock. Same message as a wrong password.
- Passwords: at least 12 characters (max 72), refused if found in Have I
  Been Pwned (k-anonymity range API; fails open; PWNED_PASSWORDS_CHECK=false)
- Optional TOTP (authenticator app) with 10 recovery codes for password
  and emailed-link sign-in, and at signing (auth method password_totp);
  codes accepted once; admins can reset; SSO sign-in unaffected
- Demo/test passwords updated; guide, README and procedures document

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 15:17:56 -05:00
1 parent a6bfe922be
commit 14316bb60f
41 files changed
+600 -45

No files matched your search

@@ -62,7 +62,7 @@
<ol class="<%= p_ %> list-decimal pl-5">
<li>The signer opens the entry and chooses Sign. The entry is shown in full exactly as it will be certified (AC 2.2.4).</li>
<li>They choose one of their own current certificates. The statement they will certify is shown with it, under the heading “Certified by” (2.2.2): for maintenance, “I certify that the work described in this entry was performed in accordance with 14 CFR Part 43, and I approve it for return to service with respect to that work”; for inspections, the 43.11(a)(5) statement; for preventive maintenance by a pilot, the corresponding statement.</li>
<li>They prove who they are again: their password, or signing in again with single sign-on within the last five minutes (2.2.6), and confirm that they are signing with intent to sign (2.1.2.4–5).</li>
<li>They prove who they are again: their password (with a code from their authenticator app, if they use one), or signing in again with single sign-on within the last five minutes (2.2.6), and confirm that they are signing with intent to sign (2.1.2.4–5).</li>
<li>The system records the signer, the certificate (kind and number), the statement, the time (UTC), how they authenticated, their network address and browser, a SHA-256 fingerprint of the entry's content and a readable copy of it, and a server seal (HMAC) over the signature record (2.1.2.6, 2.2.5). The signer is told on screen and by email (2.2.3).</li>
<li>Once signed, the entry and its components can't be edited or deleted (2.1.2.7–8, 2.2.7). A correction is made as a new entry that, once signed, supersedes the original; the original and its signature are kept and marked superseded (2.2.8).</li>
<li>When someone no longer needs access, the responsible person disables their account: they can no longer sign in or sign, and their past signatures stay valid (2.2.6.4).</li>
@@ -71,7 +71,7 @@
<h2 class="<%= h2 %>">7. Recordkeeping system controls</h2>
<ul class="<%= p_ %> list-disc pl-5">
<li><strong>Controlled access (3.2.1):</strong> personal accounts; roles per aircraft; sessions end after 30 days unused; rate-limited sign-in; changing an email or password needs the current password.</li>
<li><strong>Controlled access (3.2.1):</strong> personal accounts; roles per aircraft; passwords of at least 12 characters, refused if known from a data breach; optional authenticator-app codes; accounts locked for 15 minutes after 10 failed sign-ins (the user is emailed); rate-limited sign-in; sessions end after 30 days unused; changing an email or password needs the current password.</li>
<li><strong>Record preservation (3.2.2):</strong> every change to a maintenance record is kept with who, when and what changed, in a hash chain per aircraft that can't be edited; signed entries are locked.</li>
<li><strong>Confidential information (3.2.3):</strong> records are visible only to the aircraft's users, and to share links an owner creates (scoped and optionally expiring).</li>
<li><strong>Data corruption (3.2.4):</strong> nightly, the history chains and every signature's seal and fingerprint are checked; administrators are emailed on any problem.</li>
+1 -1
View File
@@ -2,7 +2,7 @@
<%= f.errors_summary %>
<%= f.field :name %>
<%= f.field :email_address, as: :email, label: "Email", required: true %>
<%= f.field :password, as: :password, hint: (user.persisted? ? "Leave blank to keep current password." : "At least 8 characters."), autocomplete: "new-password" %>
<%= f.field :password, as: :password, hint: (user.persisted? ? "Leave blank to keep current password." : "At least #{User::PASSWORD_MIN} characters; not one known from a data breach."), autocomplete: "new-password" %>
<%= f.field :password_confirmation, as: :password %>
<%= f.field :admin, as: :checkbox, label: "Administrator", hint: "Admins can see and edit every aircraft and manage users." %>
<div class="flex gap-2"><%= f.submit "Save" %><%= link_to "Cancel", admin_users_path, class: "btn-secondary" %></div>
+3 -1
View File
@@ -3,13 +3,15 @@
<section class="card"><table class="table">
<thead><tr><th>Name</th><th>Email</th><th>Aircraft</th><th>Last sign-in</th><th></th></tr></thead>
<tbody><% @users.each do |u| %><tr>
<td><%= u.name %> <% if u.admin? %><span class="badge-blue">Admin</span><% end %><% if u.sso_uid? %> <span class="badge-gray" title="Signs in with <%= Sso.label %>"><%= Sso.label %></span><% end %></td>
<td><%= u.name %> <% if u.admin? %><span class="badge-blue">Admin</span><% end %><% if u.sso_uid? %> <span class="badge-gray" title="Signs in with <%= Sso.label %>"><%= Sso.label %></span><% end %><% if u.otp_enabled? %> <span class="badge-green" title="Authenticator app on">2FA</span><% end %><% if u.locked? %> <span class="badge-red" title="Too many failed sign-ins">Locked</span><% end %></td>
<td><%= u.email_address %><% if u.certificates.any? %><div class="text-xs text-slate-500"><%= u.certificates.map { "#{_1.short_label} #{_1.number}" }.join(", ") %></div><% end %></td>
<td class="text-xs"><%= u.aircraft_roles.map { "#{_1.aircraft.tail_number} (#{_1.role})" }.join(", ").presence || "—" %></td>
<td class="text-xs text-slate-500"><%= u.last_signed_in_at ? "#{time_ago_in_words(u.last_signed_in_at)} ago" : "never" %></td>
<td class="whitespace-nowrap text-right">
<% if u.disabled? %><span class="badge-red mr-1">Disabled</span><%= button_to "Enable", enable_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline" } %>
<% elsif u != current_user %><%= button_to "Disable", disable_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline", data: { turbo_confirm: "Disable #{u.email_address}? They'll be signed out and can't sign in or sign entries. Their past signatures are kept." } } %><% end %>
<% if u.locked? %><%= button_to "Unlock", unlock_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline" } %><% end %>
<% if u.otp_enabled? %><%= button_to "Reset 2FA", reset_two_factor_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", title: "Turn off their authenticator app (lost phone)", form: { class: "inline", data: { turbo_confirm: "Turn off two-factor for #{u.email_address}? Only do this after confirming it's really them." } } %><% end %>
<%= link_to "Edit", edit_admin_user_path(u), class: "btn-secondary btn-sm" %></td>
</tr><% end %></tbody>
</table></section>
@@ -32,6 +32,12 @@
<%= password_field_tag :password, nil, class: "input", autocomplete: "current-password" %>
<p class="hint">Proves it's you signing, not someone at your keyboard.<%= " Or sign in again with #{Sso.label} below." if Sso.enabled? && current_user.sso_uid? %></p>
</div>
<% if current_user.otp_enabled? %>
<div class="max-w-xs">
<%= label_tag :otp_code, "Authenticator code", class: "label" %>
<%= text_field_tag :otp_code, nil, class: "input w-32 tracking-widest", autocomplete: "one-time-code", inputmode: "numeric", maxlength: 20 %>
</div>
<% end %>
<% end %>
<% if Sso.enabled? && current_user.sso_uid? %>
<% fresh = session[:reauthenticated_at] && Time.zone.at(session[:reauthenticated_at]) > EntrySigner::REAUTH_WINDOW.ago %>
+3
View File
@@ -10,3 +10,6 @@
</section>
<% end %>
<%= render "entry_signatures/form", entry: @entry, url: invited_signing_path(params[:token]), cancel_path: root_path %>
<% unless current_user.otp_enabled? %>
<p class="mx-auto mt-4 max-w-3xl text-sm text-slate-600">Recommended: <%= link_to "add an authenticator app", new_two_factor_path(return_to: request.path), class: "link" %> to your account, so your signature can't be made with a stolen password alone.</p>
<% end %>
+1 -1
View File
@@ -11,7 +11,7 @@
<% if @account_errors.present? %><div class="rounded-md bg-red-50 p-2 text-sm text-red-700"><%= @account_errors.to_sentence %></div><% end %>
<div><label class="label">Email</label><input class="input" value="<%= @invitation.email %>" disabled></div>
<div><%= label_tag :name, "Your name", class: "label" %><%= text_field_tag :name, params[:name], class: "input", required: true %></div>
<div><%= label_tag :password, "Password", class: "label" %><%= password_field_tag :password, nil, class: "input", required: true, autocomplete: "new-password" %></div>
<div><%= label_tag :password, "Password", class: "label" %><%= password_field_tag :password, nil, class: "input", required: true, autocomplete: "new-password", minlength: User::PASSWORD_MIN, maxlength: 72 %><p class="hint">At least <%= User::PASSWORD_MIN %> characters; not one known from a data breach.</p></div>
<div><%= label_tag :password_confirmation, "Confirm password", class: "label" %><%= password_field_tag :password_confirmation, nil, class: "input", required: true, autocomplete: "new-password" %></div>
<%= submit_tag "Create account", class: "btn-secondary" %>
<% end %>
+16 -1
View File
@@ -5,7 +5,7 @@
<%= f.field :email_address, as: :email, label: "Email" %>
<%= f.field :reminder_emails, as: :checkbox, label: "Weekly maintenance reminders",
hint: "A Monday email about overdue and upcoming inspections, ADs, parts and documents on aircraft you own, and certificates of yours about to expire. Only sent when something needs attention#{' (once email is set up)' unless MailSettings.configured?}." %>
<%= f.field :password, as: :password, label: "New password", hint: "Leave blank to keep your current password.", autocomplete: "new-password" %>
<%= f.field :password, as: :password, label: "New password", hint: "Leave blank to keep your current password. At least #{User::PASSWORD_MIN} characters; not one known from a data breach.", autocomplete: "new-password" %>
<%= f.field :password_confirmation, as: :password, label: "Confirm new password", autocomplete: "new-password" %>
<div>
<%= label_tag "user[current_password]", "Current password", class: "label" %>
@@ -31,6 +31,21 @@
</section>
<% end %>
<section class="card card-body mt-5 max-w-md" id="two-factor">
<h2 class="card-title">Two-factor sign-in</h2>
<% if @user.otp_enabled? %>
<p class="mt-1 text-sm text-slate-600"><span class="badge-green">On</span> since <%= @user.otp_enabled_at.to_date %>: signing in with your password or an emailed link also asks for a code from your authenticator app. <%= @user.recovery_codes_left %> recovery codes left.</p>
<%= form_with url: two_factor_path, class: "mt-3 flex flex-wrap items-end gap-2" do |f| %>
<div><%= label_tag :code, "Current code or a recovery code", class: "label" %><%= text_field_tag :code, nil, required: true, autocomplete: "one-time-code", class: "input w-44" %></div>
<%= button_tag "New recovery codes", type: "submit", formaction: recovery_codes_two_factor_path, class: "btn-secondary btn-sm" %>
<%= button_tag "Turn off", type: "submit", name: "_method", value: "delete", class: "btn-secondary btn-sm", data: { turbo_confirm: "Turn off two-factor sign-in?" } %>
<% end %>
<% else %>
<p class="mt-1 text-sm text-slate-600">Add a code from an authenticator app on your phone to password and emailed-link sign-in, so a stolen password alone can't get in.<%= " (Signing in with #{Sso.label} uses its own second factor.)" if Sso.enabled? %></p>
<div class="mt-3"><%= link_to "Set up", new_two_factor_path, class: "btn-secondary btn-sm" %></div>
<% end %>
</section>
<section class="card card-body mt-5 max-w-md" id="certificates">
<h2 class="card-title">Certificates</h2>
<p class="mt-1 text-sm text-slate-600">Your FAA certificates, for signing logbook entries: “Sign as” fills in your name, the kind of certificate and its number.</p>
+11
View File
@@ -0,0 +1,11 @@
<% content_for :title, "Sign in" %>
<div class="mx-auto max-w-sm">
<h1 class="mb-4 text-2xl font-bold">Authenticator code</h1>
<%= form_with url: two_factor_session_path, class: "card card-body space-y-4" do |form| %>
<p class="text-sm text-slate-600">Enter the 6-digit code from your authenticator app. Lost your phone? Enter one of your recovery codes instead.</p>
<div><%= form.label :code, "Code", class: "label" %>
<%= form.text_field :code, required: true, autofocus: true, autocomplete: "one-time-code", inputmode: "text", maxlength: 20, class: "input text-lg tracking-widest" %></div>
<%= form.submit "Continue", class: "btn-primary w-full justify-center" %>
<p class="text-center text-sm"><%= link_to "Start again", new_session_path, class: "link" %></p>
<% end %>
</div>
@@ -0,0 +1,2 @@
<p>Your Simple Aircraft Manager account (<%= @user.email_address %>) was locked for <%= User::LOCK_FOR.inspect %> after <%= User::LOCK_AFTER %> failed sign-in attempts in a row.</p>
<p>If that was you, wait and try again. If it wasn't, someone may be guessing your password: change it once you're back in (Profile), turn on an authenticator app, and tell your administrator.</p>
@@ -0,0 +1,3 @@
Your Simple Aircraft Manager account (<%= @user.email_address %>) was locked for <%= User::LOCK_FOR.inspect %> after <%= User::LOCK_AFTER %> failed sign-in attempts in a row.
If that was you, wait and try again. If it wasn't, someone may be guessing your password: change it once you're back in (Profile), turn on an authenticator app, and tell your administrator.
+1 -1
View File
@@ -5,7 +5,7 @@
<%= f.errors_summary %>
<%= f.field :name %>
<%= f.field :email_address, as: :email, label: "Email", required: true %>
<%= f.field :password, as: :password, required: true, hint: "At least 8 characters." %>
<%= f.field :password, as: :password, required: true, hint: "At least #{User::PASSWORD_MIN} characters; not one known from a data breach." %>
<%= f.field :password_confirmation, as: :password, required: true %>
<%= f.submit "Create Admin Account", class: "btn-primary w-full justify-center" %>
<% end %>
+9
View File
@@ -0,0 +1,9 @@
<% content_for :title, "Recovery codes" %>
<section class="card card-body mx-auto max-w-md space-y-4">
<h1 class="text-2xl font-bold">Save your recovery codes</h1>
<p class="text-sm text-slate-600">Two-factor is on. If you lose your phone, each of these codes signs you in once in place of an authenticator code. Print them or keep them in a password manager: they won't be shown again.</p>
<ul class="grid grid-cols-2 gap-2 rounded-md bg-slate-50 p-4 font-mono text-sm ring-1 ring-slate-200">
<% @codes.each do |c| %><li><%= c %></li><% end %>
</ul>
<%= link_to "Done", back_path, class: "btn-primary self-start" %>
</section>
+17
View File
@@ -0,0 +1,17 @@
<% content_for :title, "Set up two-factor" %>
<section class="card card-body mx-auto max-w-md space-y-4">
<h1 class="text-2xl font-bold">Set up an authenticator app</h1>
<p class="text-sm text-slate-600">After your password (or an emailed sign-in link) you'll also enter a 6-digit code from an app on your phone, so a stolen password alone can't get in. Any authenticator app works: Google Authenticator, Microsoft Authenticator, 1Password, Authy…</p>
<ol class="list-decimal space-y-3 pl-5 text-sm">
<li>In the app, add an account and scan this code:
<div class="mt-2 inline-block rounded bg-white p-2"><%= image_tag @qr_data_uri, alt: "QR code for your authenticator app", class: "h-48 w-48" %></div>
<p class="mt-1 text-xs text-slate-500">Can't scan it? Enter this key instead: <code class="break-all"><%= @secret.scan(/.{4}/).join(" ") %></code></p></li>
<li>Enter the code the app shows:
<%= form_with url: two_factor_path, class: "mt-2 flex flex-wrap items-end gap-2" do |f| %>
<%= hidden_field_tag :return_to, params[:return_to] %>
<%= f.text_field :code, required: true, autocomplete: "one-time-code", inputmode: "numeric", maxlength: 7, class: "input w-32 text-lg tracking-widest", "aria-label": "Code" %>
<%= f.submit "Turn on", class: "btn-primary" %>
<% end %></li>
</ol>
<p class="text-sm"><%= link_to "Not now", back_path, class: "link" %></p>
</section>