From 38aee16b66545a05e8080095fe1545570e9a24f0 Mon Sep 17 00:00:00 2001 From: Jon Froehlich Date: Thu, 26 Nov 2026 06:43:05 -0700 Subject: [PATCH 1/3] Bump to 2.35.5: explain each django-axes admin page Access attempts, Access logs and Access failures had no description, and their names don't say what they record. These pages get read during a lockout, so each now opens with a short explanation: what the rows are, how to unlock someone, why the IP is always the proxy's, and why unknown usernames appear as hashes. One template, admin/axes/change_list.html: the admin looks for an app-level changelist template before its default and axes ships none, so no ModelAdmin is re-registered. Styled with the admin's custom properties so it follows the dark-mode toggle. Tests check each page shows only its own text and pin the numbers the text hard-codes (10, 30 min, 1,000). Part of #1460. Co-Authored-By: Claude Opus 5.5 --- makeabilitylab/settings.py | 4 +- website/templates/admin/axes/change_list.html | 61 +++++++++++++++++++ website/tests/test_login_throttle.py | 33 ++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 website/templates/admin/axes/change_list.html diff --git a/makeabilitylab/settings.py b/makeabilitylab/settings.py index 6d42769c..720c1a2d 100644 --- a/makeabilitylab/settings.py +++ b/makeabilitylab/settings.py @@ -228,8 +228,8 @@ def parse_allowed_hosts(value, django_env): CSRF_COOKIE_SECURE = True # Makeability Lab Global Variables, including Makeability Lab version -ML_WEBSITE_VERSION = "2.35.4" # Keep this updated with each release and also change the short description below -ML_WEBSITE_VERSION_DESCRIPTION = "Admin login throttling: after 10 wrong passwords a username is locked out of /admin for 30 minutes (django-axes). Superusers can unlock an account under Administration > Access attempts." +ML_WEBSITE_VERSION = "2.35.5" # Keep this updated with each release and also change the short description below +ML_WEBSITE_VERSION_DESCRIPTION = "Admin login throttling: after 10 wrong passwords a username is locked out of /admin for 30 minutes (django-axes). Superusers can unlock an account under Administration > Access attempts; each of the three Access pages now explains what it records." DATE_MAKEABILITYLAB_FORMED = datetime.date(2012, 1, 1) # Date Makeability Lab was formed MAX_BANNERS = 7 # Maximum number of banners on a page diff --git a/website/templates/admin/axes/change_list.html b/website/templates/admin/axes/change_list.html new file mode 100644 index 00000000..5656165f --- /dev/null +++ b/website/templates/admin/axes/change_list.html @@ -0,0 +1,61 @@ +{% extends "admin/change_list.html" %} + +{% comment %} + Changelist for django-axes' three login-record models (#1460). Axes ships no + admin templates, and the admin looks for admin//change_list.html + before its default, so this one template covers all three pages without + re-registering axes' ModelAdmins. It only adds a short explanation under the + page title, because names like "Access attempts" don't say what is in them, + and these pages get read during a lockout. + + The numbers (10 wrong passwords, 30 minutes, 1,000 rows) mirror AXES_* in + settings.py and axes' own failure-log cap; test_login_throttle.py fails if + they drift. All three pages are superuser-only (axes' permissions). +{% endcomment %} + +{% block content_title %} + {{ block.super }} +
+ {% if opts.model_name == "accessattempt" %} +

Usernames that are currently building up wrong passwords. Ten in a row locks + that username out of /admin for 30 minutes, and a correct + password clears its count, so this page is usually empty.

+

To unlock someone now, tick their row, choose + “Delete selected access attempts” and click Go.

+ {% elif opts.model_name == "accesslog" %} +

Every successful sign-in to /admin, with the time the person + signed out. A blank logout time means they are still signed in, or their + session expired without signing out.

+

The IP address is the CSE web proxy's, not the person's own, which is why + the throttle counts by username rather than address.

+ {% elif opts.model_name == "accessfailurelog" %} +

Every wrong password, kept after the count on Access attempts resets (up to + 1,000 per username). A burst of failures for one username means someone is + guessing its password.

+

A username that matches no account is stored as a hash, so a password typed + into the username box by mistake is never saved.

+ {% endif %} +
+{% endblock %} + +{% block extrastyle %} + {{ block.super }} + +{% endblock %} diff --git a/website/tests/test_login_throttle.py b/website/tests/test_login_throttle.py index d2ea46a8..0a07e710 100644 --- a/website/tests/test_login_throttle.py +++ b/website/tests/test_login_throttle.py @@ -182,6 +182,39 @@ def test_axes_admin_is_superuser_only(self): self.assertEqual(editor_client.get(url).status_code, 403, model) +class AxesChangelistHelpTests(TestCase): + """Each axes changelist explains what it records (templates/admin/axes/change_list.html).""" + + PAGES = { + "accessattempt": "To unlock someone now,", + "accesslog": "Every successful sign-in", + "accessfailurelog": "Every wrong password", + } + + def setUp(self): + user = get_user_model().objects.create_superuser("alice", "", PASSWORD) + self.client.force_login(user) + + def test_each_page_has_its_own_explanation(self): + for model, own_text in self.PAGES.items(): + with self.subTest(model=model): + response = self.client.get(reverse(f"admin:axes_{model}_changelist")) + self.assertContains(response, 'class="ml-axes-help"') + self.assertContains(response, own_text) + for other, other_text in self.PAGES.items(): + if other != model: + self.assertNotContains(response, other_text) + + def test_numbers_in_the_text_match_the_settings(self): + """The template hard-codes them; fail here rather than show stale numbers.""" + from datetime import timedelta + from django.conf import settings + + self.assertEqual(settings.AXES_FAILURE_LIMIT, 10) # "Ten in a row" + self.assertEqual(settings.AXES_COOLOFF_TIME, timedelta(minutes=30)) + self.assertEqual(settings.AXES_ACCESS_FAILURE_LOG_PER_USER_LIMIT, 1000) + + class ThrottleConfigTests(TestCase): """Pin the production policy so a settings edit can't quietly weaken it.""" From a322b197a48daebf4ed1e83be481777cb7fbf9ec Mon Sep 17 00:00:00 2001 From: Jon Froehlich Date: Fri, 27 Nov 2026 07:28:41 -0700 Subject: [PATCH 2/3] Axes help text: correct three claims, test the rendered numbers Review fixes for #1467, checked against django-axes 9.0.0: - Access failures: attempts refused during a lockout are never logged, so it is not "every wrong password". - Access attempts: expired rows linger (still "Locked Out") until the next sign-in; unlocking means deleting every row for the username (rows are per username+IP+user agent), then confirming. Note the "(unknown)" hashed usernames here too. - Access logs: the recorded IP is the server's internal address. - The numbers test now asserts the rendered text against settings instead of pinning settings to exact values. - Shorter version description. Co-Authored-By: Claude Opus 5.5 --- makeabilitylab/settings.py | 2 +- website/templates/admin/axes/change_list.html | 30 ++++++++++++------- website/tests/test_login_throttle.py | 18 +++++++---- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/makeabilitylab/settings.py b/makeabilitylab/settings.py index 720c1a2d..7e7f81f4 100644 --- a/makeabilitylab/settings.py +++ b/makeabilitylab/settings.py @@ -229,7 +229,7 @@ def parse_allowed_hosts(value, django_env): # Makeability Lab Global Variables, including Makeability Lab version ML_WEBSITE_VERSION = "2.35.5" # Keep this updated with each release and also change the short description below -ML_WEBSITE_VERSION_DESCRIPTION = "Admin login throttling: after 10 wrong passwords a username is locked out of /admin for 30 minutes (django-axes). Superusers can unlock an account under Administration > Access attempts; each of the three Access pages now explains what it records." +ML_WEBSITE_VERSION_DESCRIPTION = "Each of the three login-throttle pages under Administration (Access attempts, logs, failures) now explains what it records and how to unlock an account." DATE_MAKEABILITYLAB_FORMED = datetime.date(2012, 1, 1) # Date Makeability Lab was formed MAX_BANNERS = 7 # Maximum number of banners on a page diff --git a/website/templates/admin/axes/change_list.html b/website/templates/admin/axes/change_list.html index 5656165f..02546b86 100644 --- a/website/templates/admin/axes/change_list.html +++ b/website/templates/admin/axes/change_list.html @@ -9,29 +9,37 @@ and these pages get read during a lockout. The numbers (10 wrong passwords, 30 minutes, 1,000 rows) mirror AXES_* in - settings.py and axes' own failure-log cap; test_login_throttle.py fails if - they drift. All three pages are superuser-only (axes' permissions). + settings.py and axes' own failure-log cap; AxesChangelistHelpTests in + test_login_throttle.py renders the pages and fails if they drift. All three + pages are superuser-only (axes' permissions). {% endcomment %} {% block content_title %} {{ block.super }}
{% if opts.model_name == "accessattempt" %} -

Usernames that are currently building up wrong passwords. Ten in a row locks +

Usernames building up wrong passwords. 10 wrong passwords in a row lock that username out of /admin for 30 minutes, and a correct - password clears its count, so this page is usually empty.

-

To unlock someone now, tick their row, choose - “Delete selected access attempts” and click Go.

+ password clears its count. A row whose Attempt Time is more than 30 minutes + ago has already expired, even if it still says “Locked Out”; it is removed + at the next sign-in.

+

To unlock someone now, tick every row with their username, + choose “Delete selected access attempts”, click Go, then confirm.

+

A username shown as “(unknown) …” matched no account and is stored as a + hash.

{% elif opts.model_name == "accesslog" %}

Every successful sign-in to /admin, with the time the person signed out. A blank logout time means they are still signed in, or their session expired without signing out.

-

The IP address is the CSE web proxy's, not the person's own, which is why - the throttle counts by username rather than address.

+

The IP address is the web server's internal address, the same for everyone, + not the person's own, which is why the throttle counts by username rather + than address.

{% elif opts.model_name == "accessfailurelog" %} -

Every wrong password, kept after the count on Access attempts resets (up to - 1,000 per username). A burst of failures for one username means someone is - guessing its password.

+

Wrong passwords, kept after the count on Access attempts resets (up to + 1,000 per username). Attempts made while a username is locked out are not + recorded, so one locked-out username may stand for many more guesses than + it shows. A burst of failures for one username means someone is guessing + its password.

A username that matches no account is stored as a hash, so a password typed into the username box by mistake is never saved.

{% endif %} diff --git a/website/tests/test_login_throttle.py b/website/tests/test_login_throttle.py index 0a07e710..03993f13 100644 --- a/website/tests/test_login_throttle.py +++ b/website/tests/test_login_throttle.py @@ -188,7 +188,7 @@ class AxesChangelistHelpTests(TestCase): PAGES = { "accessattempt": "To unlock someone now,", "accesslog": "Every successful sign-in", - "accessfailurelog": "Every wrong password", + "accessfailurelog": "Attempts made while a username is locked out are not", } def setUp(self): @@ -207,12 +207,20 @@ def test_each_page_has_its_own_explanation(self): def test_numbers_in_the_text_match_the_settings(self): """The template hard-codes them; fail here rather than show stale numbers.""" - from datetime import timedelta from django.conf import settings - self.assertEqual(settings.AXES_FAILURE_LIMIT, 10) # "Ten in a row" - self.assertEqual(settings.AXES_COOLOFF_TIME, timedelta(minutes=30)) - self.assertEqual(settings.AXES_ACCESS_FAILURE_LOG_PER_USER_LIMIT, 1000) + msg = "update templates/admin/axes/change_list.html to match settings" + minutes = int(settings.AXES_COOLOFF_TIME.total_seconds() // 60) + attempts = self.client.get(reverse("admin:axes_accessattempt_changelist")) + self.assertContains( + attempts, f"{settings.AXES_FAILURE_LIMIT} wrong passwords in a row", msg_prefix=msg) + self.assertContains(attempts, f"for {minutes} minutes", msg_prefix=msg) + self.assertContains(attempts, f"more than {minutes} minutes", msg_prefix=msg) + # Axes' own default (axes/conf.py), not a repo setting: guards an upgrade. + failures = self.client.get(reverse("admin:axes_accessfailurelog_changelist")) + self.assertContains( + failures, f"{settings.AXES_ACCESS_FAILURE_LOG_PER_USER_LIMIT:,} per username", + msg_prefix=msg) class ThrottleConfigTests(TestCase): From e4fdbfac1f277021c2b7e260d393217080be6cbd Mon Sep 17 00:00:00 2001 From: Jon Froehlich Date: Fri, 27 Nov 2026 07:31:31 -0700 Subject: [PATCH 3/3] Axes help text: final-review wording fixes - Access attempts: a lockout sums Failed Logins across a username's rows, so no single row may say "Locked Out"; expired rows go the next time anyone signs in. - Access failures: a burst may also be an owner who forgot the password. Co-Authored-By: Claude Opus 5.5 --- website/templates/admin/axes/change_list.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/website/templates/admin/axes/change_list.html b/website/templates/admin/axes/change_list.html index 02546b86..00480486 100644 --- a/website/templates/admin/axes/change_list.html +++ b/website/templates/admin/axes/change_list.html @@ -20,9 +20,12 @@ {% if opts.model_name == "accessattempt" %}

Usernames building up wrong passwords. 10 wrong passwords in a row lock that username out of /admin for 30 minutes, and a correct - password clears its count. A row whose Attempt Time is more than 30 minutes + password clears its count.

+

A username can have several rows (one per browser or address), and its + lockout adds up the Failed Logins on all of them, so a locked-out username + may have no row that says “Locked Out”. A row whose Attempt Time is more than 30 minutes ago has already expired, even if it still says “Locked Out”; it is removed - at the next sign-in.

+ the next time anyone signs in.

To unlock someone now, tick every row with their username, choose “Delete selected access attempts”, click Go, then confirm.

A username shown as “(unknown) …” matched no account and is stored as a @@ -38,8 +41,8 @@

Wrong passwords, kept after the count on Access attempts resets (up to 1,000 per username). Attempts made while a username is locked out are not recorded, so one locked-out username may stand for many more guesses than - it shows. A burst of failures for one username means someone is guessing - its password.

+ it shows. A burst of failures for one username usually means someone is + guessing its password, or its owner has forgotten it.

A username that matches no account is stored as a hash, so a password typed into the username box by mistake is never saved.

{% endif %}