Skip to content

PhoenixKit 2.31.0: Failed sign-ins are recorded and reported

PhoenixKit 2.31.0 keeps a record of failed sign-ins and shows it to the site’s admins and to the people whose accounts are targeted. It also fixes a rate limit that locked out users who simply signed in often.

Failed sign-ins on record

Until now a wrong password left no trace except a short-lived counter. Failed attempts are now stored, grouped per account, network and hour, so a long attack on one account becomes one row per hour with a rising count. An attempt with the correct password for a deactivated account is kept apart. The page’s answer and timing stay the same whether the account exists or not.

Recording is on by default, with a 90-day retention and a daily cleanup job. Both are set on Settings → Authorization, with Record failed sign-ins.

Who sees them

  • /admin/users/sessions has a panel with the last 24 hours: attempts, distinct networks, targeted accounts and the heaviest groups.
  • An account holder’s own settings page lists recent failed attempts below the active sessions, by device and network.
  • The new sign-in alert email now adds how many failed attempts there were in the last 24 hours, says the device was unrecognized, marks the location as approximate and shows the time in the reader’s own time zone.
  • An optional alert, off by default, emails users when failures on their account cross a threshold, 10 in an hour by default, at most once a day.

Rate limit fixed

The login rate limit counted successful sign-ins too, so five ordinary sign-ins in the window locked the account out of the sixth. Only failures count now.

Annotation tools reset

Profile settings have an Annotation tools section with Reset annotation settings. It puts the drawing tools back as they ship, on the server and in the browser. The annotations themselves are untouched.

Upgrading

Run mix phoenix_kit.update for migration V197, which adds the failed sign-in table and the daily cleanup job. Etcher 0.15 is now the minimum. Recording starts on its own; the email alert stays off until it is turned on.

Full release notes: PhoenixKit 2.31.0

2.31.0 · 18 September 2026

Added

  • Failed sign-ins are recorded. Until now a wrong password produced a flash and nothing else — no row, no activity entry, nothing the targeted account holder or the site owner could ever see. The only trace was Hammer’s in-memory rate-limit counter, which is node-local, lost on restart, counts successful logins too, and says nothing at all until a bucket overflows. The case that motivates it: an attacker who guesses right on attempt 400 triggers only the new-device email, which is indistinguishable from “I signed in from my new laptop” — the 399 failures before it are what tell those apart.
    • V197 migration — phoenix_kit_login_attempts. Rows are aggregated at write time on (identifier, ip_network, outcome, bucket_start), where the bucket is the hour, so a sustained attack against one account from one network collapses to one row per hour with a rising attempt_count rather than thousands of rows. The write is a single INSERT ... ON CONFLICT DO UPDATE with no preceding read.
    • PhoenixKit.Users.LoginAttempts — record/4, count_for_user_since/2, recent_for_user/2, stats/1, top_since/2, prune/1. Every entry point swallows its own failures with both rescue and catch :exit: a security log that takes the login form down with it is worse than no security log.
    • Recorded on all three failing branches of the login form, with the outcome that matters most kept distinct — "inactive" means somebody had the correct password for a deactivated account. The HTTP response is unchanged on every branch, and the two that share the deliberately generic “Invalid email/username or password” flash do the same work, so neither the response nor the timing tells a real account from a fictitious one.
    • Settings login_attempt_logging_enabled (default on, unlike new_login_alert_enabled: it writes one bounded row, sends nothing, and the data is useless retroactively) and login_attempt_retention_days (default 90). Daily PhoenixKit.Users.LoginAttemptsPruneWorker, added to the generated crontab AND to the backfill list, so an existing host gets it on mix phoenix_kit.update instead of never pruning.
  • The new-login alert email reports recent failures. “There were also 12 failed sign-in attempts on your account in the last 24 hours.” This is the line that separates “my new laptop” from “someone finally guessed it” — the email already reached the right person at the right moment and said nothing about it. Omitted entirely when the count is zero, rather than printing a 0.
  • A burst of failures warns the account holder. failed_login_alert_enabled (default off — it sends mail) plus failed_login_alert_threshold (default 10 failures within an hour). Capped to one alert per account per 24 hours, so a sustained attack cannot be turned into a mail flood against the person being attacked; the cooldown stamp is written before the send, so a send that raises still burns it.
  • The account holder’s own settings page lists recent failed attempts, under Active Sessions — the two answer the same question from opposite sides. Described by device and network, never by the stored identifier. Hidden entirely when there is nothing to show.
  • /admin/users/sessions gained a failed sign-in panel — attempts, distinct networks and distinct targeted accounts over the last 24 hours, plus the heaviest buckets. Attempts vs buckets is the distinction that matters: a large attempt count over few buckets is one concentrated attack, the reverse is a spray. The attacker-controlled identifier is shown here (it is what makes “someone is hammering admin@” visible) and is escaped by HEEx; a regression test asserts a <script> identifier renders as text. Each row also names the outcome, so "inactive" (correct password, deactivated account) is visible instead of looking like just another wrong password.
  • Authorization settings for the new keys, on /admin/settings/authorization. failed_login_alert_enabled defaults off because it sends mail; without a control it was unreachable except by writing the settings table directly.
  • “Annotation tools” on /profile/settings: one button that puts the drawing tools back to how they ship (PR #832). A person’s annotation settings live in two places, and clearing one without the other leaves them half-fixed — the palette and ink the Etcher toolbar saves are on the user row (etcher_colors, etcher_line_params), while the background dots, connector anchors, toolbar layout, style-panel state and per-tool colours are Etcher’s own etcher:prefs answers in the browser. The reset clears the row server-side and pushes phoenix_kit:etcher-reset on the same socket, which the new EtcherReset hook answers by removing the browser’s copy. The annotations themselves are untouched. Rendered last on the page: a reset is what you reach for when something is wrong, not part of the daily settings.

Fixed

  • A bucket that opened against no account stayed unattached for the rest of the hour even after that identifier became a real user. ON CONFLICT only incremented the count and last_at, so the account holder never saw those attempts and the threshold alert undercounted them. The upsert now COALESCEs user_uuid from the incoming row.

  • Add-account (the multi-session password form) recorded nothing. A wrong password, a rate-limited try, and a deactivated account with the right password now write the same three outcomes as the login form.

  • The threshold alert could fire when the insert had failed, and a custom_fields stamp that failed still sent the email — so every later failure retried it. The alert now runs only after a successful write, and only after the cooldown stamp commits.

  • The add-account fallback clause was unreachable. Dialyzer proves MultiSession.add_account/3 returns only three reasons, so the defensive catch-all could never match — but deleting it would mean a fourth reason added later raises FunctionClauseError on the sign-in path. It is a map lookup now, which keeps the fallback reachable and the guarantee intact.

  • Null bytes in the identifier crashed the insert (Postgres rejects \\x00 even though it is valid UTF-8) and truncation used graphemes against a varchar(160) that counts codepoints. Both are normalized before write so an attacker-controlled identifier cannot skip recording.

  • The login rate limiter counted successful sign-ins. check_login_rate_limit/2 runs before the password is verified, and it incremented the bucket — so five ordinary logins inside the window locked the account out of the sixth, and the bucket a brute-force attempt fills was the same one legitimate use drained. The check now peeks; the new RateLimiter.record_failed_login/2 fills the bucket, on the failure branch where the outcome is actually known. A correct password — even for a deactivated account — no longer counts against the limit.

Changed

  • The Etcher floor is ~> 0.15.0 (PR #833), with the jsDelivr pin in phoenix_kit.js moved to v0.15.0 to match. 0.15 is where a thickness stopped meaning document pixels and started meaning a weight against a 1000-pixel reference canvas, so an older Etcher renders a host’s saved etcher_line_params at a different weight on every image — a floor, not a preference. The weight range is still 1–40, which is exactly what MediaCanvasViewer’s sanitizer clamps to, so a saved value keeps its meaning end to end and no host data needs migrating.

  • Post-merge review of #832: the EtcherReset hook had landed under the FolderDropUpload banner in phoenix_kit.js, leaving that banner labelling the wrong hook; the reset’s comment claimed a delete of an unsaved key answers :not_found, when jsonb - key is simply a no-op and :not_found means the user row is gone; and the hook shipped without a test/js case, which now covers the event name, the storage key (pinned against Etcher’s own _prefsKey) and a storage that refuses to write.

  • PhoenixKitWeb.Gettext no longer compiles translations as function clauses. split_module_by: [:locale] brought a clean compile of this file from ~58s to ~13s, but 13s still trips Elixir’s “>10s” notice: each locale module is ~2.7k binary-matching clauses, which the Erlang compiler handles superlinearly, and wall-clock is the slowest of those modules. The backend now parses priv/gettext into a nested map at compile time and embeds it as a compressed binary (~0.3s for the file). Lookups go through Map.get/2 and runtime interpolation; Gettext.dgettext/3 and the extract-surface (__gettext__/1, __mix_recompile__?) are unchanged.

  • The backend reads :priv, :interpolation and :default_domain from the merged opts. They were declared as bare defaults before Application.compile_env(:phoenix_kit, PhoenixKitWeb.Gettext, []) was folded in, so a host that configured priv: got a catalogue built from its own directory while __gettext__(:priv) still pointed mix gettext.extract and mix gettext.merge at priv/gettext, and a configured interpolation: module was ignored at runtime. Gettext.Backend.__using__ derives all three from the merge; so does this backend now.

  • Plural forms come from each PO file’s Plural-Forms: header again. The first cut always called Gettext.Plural.plural(locale, n), i.e. Gettext’s built-in locale table, which silently ignored both a translator-authored header and config :gettext, :plural_forms. The compiler now stores Gettext.Plural.plural_info/3 per locale/domain alongside the catalogue — the same resolution Gettext.Compiler performs. No shipped locale changes behaviour: the five headers we carry agree with the built-in table, and the other three have no header.

  • PhoenixKitWeb.Gettext.warm_catalog/0, called from PhoenixKit.Application.start/2. Decoding the embedded catalogue costs ~20ms and :persistent_term.put/2 scans every process; leaving it to the first gettext call put both on a random request instead of on boot.

  • Plural Gettext.PluralFormError now reports the PO source line, and a missing plural form is logged at compile time the same way Gettext.Compiler does. strip_meta: true still keeps source_line on the message, so the dummy line: 1 was unnecessary.

  • The new-login alert email timestamps the sign-in in the recipient’s own timezone. It rendered 2026-09-18 16:23 UTC for every reader, which is the one thing nobody can check an unfamiliar sign-in against. It now uses the recipient’s user_timezone (else the site’s time_zone), formatted with the site’s date/time settings and named — 2026-09-18 18:23 CEST, or UTC+05:30 where the preference is a legacy numeric offset rather than an IANA zone. DST is resolved for the instant shown, so the same account reads CEST in July and CET in January.

  • That email also says the device was unrecognized, and marks the location approximate. “We noticed a new login to your account” became “…from an unrecognized device”, and a resolved place now renders as Paris, France (approximate) — IP geolocation is city-accurate at best, and an unqualified city invites a reader to dismiss a real alert because it looks wrong. An unresolved location still degrades to a bare Unknown.

  • The alert’s variables are now built inside the recipient’s locale, like the body they are substituted into. Unknown previously rendered in whatever locale the signing-in request happened to be served in.

i18n

  • The annotation-reset copy — six new msgids — translated by hand in all seven locales, grounded in each catalogue’s own terms for annotation and toolbar (de Anmerkung / Werkzeugleiste, pl adnotacja / pasek narzędzi, ru аннотация / панель инструментов) and in its address form.

  • Could not read the current figures had never been extracted either, and the merge that caught it carried “Could not reach the storage endpoint” onto it in all seven locales — a wrong sentence, served, where an empty msgstr would at least have fallen back to correct English. Rewritten by hand in all seven. grep -rc fuzzy is 0 across every translated catalogue and --check-up-to-date passes.

  • mix gettext.extract --check-up-to-date passes again. The media viewer’s "Title & description" heading (added in 2.30.0, from media_canvas_viewer.html.heex) had never been extracted, so it was in no .pot and no catalogue and rendered as English everywhere. The extract that caught it fuzzy-matched it onto “Edit description” in all seven translated locales — de Beschreibung bearbeiten, ru Изменить описание — and Gettext serves fuzzy entries, so that wording would have shipped. Rewritten by hand in all seven, following the catalogues’ own convention of spelling out a UI & (Titel und Beschreibung, Título y descripción, Pealkiri ja kirjeldus, Titre et description, Titolo e descrizione, Tytuł i opis, Название и описание) while & is kept only inside a third-party product’s literal menu path. grep -rc fuzzy is 0 again across every translated catalogue.

  • The failed-sign-in copy — 14 new msgids, including two ngettext entries — translated by hand in all seven locales, with the three-form plurals written out for pl and ru.

  • A fuzzy carryover silently deleted {{failed_attempts}} from the new-login body in all seven catalogues. The count would have rendered in English and vanished in every other language, with nothing failing. The placeholder was restored structurally (anchored to {{browser_os}}, not to each locale’s wording) and a test now asserts the substitution survives translation. Two other carryovers were rewritten: %{count} attempt had arrived as ru событие (“event”) and Last seen as Последняя генерация (“last generation”).

  • The new-login alert body and the new %{location} (approximate) string translated by hand in all seven locales, following each catalogue’s own address form and device wording (de von einem unbekannten Gerät, fr depuis un appareil non reconnu, pl z nierozpoznanego urządzenia). The body’s msgid change fuzzy-matched onto its own previous translation, which was corrected rather than accepted.


PhoenixKit 2.31.0. Install or update: {:phoenix_kit, "~> 2.31"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.