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/sessionshas 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 risingattempt_countrather than thousands of rows. The write is a singleINSERT ... ON CONFLICT DO UPDATEwith 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 bothrescueandcatch :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, unlikenew_login_alert_enabled: it writes one bounded row, sends nothing, and the data is useless retroactively) andlogin_attempt_retention_days(default 90). DailyPhoenixKit.Users.LoginAttemptsPruneWorker, added to the generated crontab AND to the backfill list, so an existing host gets it onmix phoenix_kit.updateinstead of never pruning.
- V197 migration —
- 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) plusfailed_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/sessionsgained 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 hammeringadmin@” 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_enableddefaults 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 ownetcher:prefsanswers in the browser. The reset clears the row server-side and pushesphoenix_kit:etcher-reseton the same socket, which the newEtcherResethook 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 CONFLICTonly incremented the count andlast_at, so the account holder never saw those attempts and the threshold alert undercounted them. The upsert nowCOALESCEsuser_uuidfrom 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_fieldsstamp 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/3returns only three reasons, so the defensive catch-all could never match — but deleting it would mean a fourth reason added later raisesFunctionClauseErroron 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
\\x00even though it is valid UTF-8) and truncation used graphemes against avarchar(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/2runs 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 newRateLimiter.record_failed_login/2fills 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 inphoenix_kit.jsmoved tov0.15.0to 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 savedetcher_line_paramsat a different weight on every image — a floor, not a preference. The weight range is still 1–40, which is exactly whatMediaCanvasViewer’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
EtcherResethook had landed under theFolderDropUploadbanner inphoenix_kit.js, leaving that banner labelling the wrong hook; the reset’s comment claimed a delete of an unsaved key answers:not_found, whenjsonb - keyis simply a no-op and:not_foundmeans the user row is gone; and the hook shipped without atest/jscase, which now covers the event name, the storage key (pinned against Etcher’s own_prefsKey) and a storage that refuses to write. -
PhoenixKitWeb.Gettextno 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 parsespriv/gettextinto a nested map at compile time and embeds it as a compressed binary (~0.3s for the file). Lookups go throughMap.get/2and runtime interpolation;Gettext.dgettext/3and the extract-surface (__gettext__/1,__mix_recompile__?) are unchanged. -
The backend reads
:priv,:interpolationand:default_domainfrom the merged opts. They were declared as bare defaults beforeApplication.compile_env(:phoenix_kit, PhoenixKitWeb.Gettext, [])was folded in, so a host that configuredpriv:got a catalogue built from its own directory while__gettext__(:priv)still pointedmix gettext.extractandmix gettext.mergeatpriv/gettext, and a configuredinterpolation: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 calledGettext.Plural.plural(locale, n), i.e. Gettext’s built-in locale table, which silently ignored both a translator-authored header andconfig :gettext, :plural_forms. The compiler now storesGettext.Plural.plural_info/3per locale/domain alongside the catalogue — the same resolutionGettext.Compilerperforms. 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 fromPhoenixKit.Application.start/2. Decoding the embedded catalogue costs ~20ms and:persistent_term.put/2scans every process; leaving it to the firstgettextcall put both on a random request instead of on boot. -
Plural
Gettext.PluralFormErrornow reports the PO source line, and a missing plural form is logged at compile time the same wayGettext.Compilerdoes.strip_meta: truestill keepssource_lineon the message, so the dummyline: 1was unnecessary. -
The new-login alert email timestamps the sign-in in the recipient’s own timezone. It rendered
2026-09-18 16:23 UTCfor every reader, which is the one thing nobody can check an unfamiliar sign-in against. It now uses the recipient’suser_timezone(else the site’stime_zone), formatted with the site’s date/time settings and named —2026-09-18 18:23 CEST, orUTC+05:30where the preference is a legacy numeric offset rather than an IANA zone. DST is resolved for the instant shown, so the same account readsCESTin July andCETin 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 bareUnknown. -
The alert’s
variablesare now built inside the recipient’s locale, like the body they are substituted into.Unknownpreviously 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 figureshad 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 fuzzyis 0 across every translated catalogue and--check-up-to-datepasses. -
mix gettext.extract --check-up-to-datepasses again. The media viewer’s"Title & description"heading (added in 2.30.0, frommedia_canvas_viewer.html.heex) had never been extracted, so it was in no.potand 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 fuzzyis 0 again across every translated catalogue. -
The failed-sign-in copy — 14 new msgids, including two
ngettextentries — translated by hand in all seven locales, with the three-form plurals written out forplandru. -
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} attempthad arrived as ru событие (“event”) andLast seenas Последняя генерация (“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.