Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions makeabilitylab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "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

Expand Down
72 changes: 72 additions & 0 deletions website/templates/admin/axes/change_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{% 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/<app_label>/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; 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 }}
<div class="ml-axes-help" id="ml-axes-help">
{% if opts.model_name == "accessattempt" %}
<p>Usernames building up wrong passwords. 10 wrong passwords in a row lock
that username out of <code>/admin</code> for 30 minutes, and a correct
password clears its count.</p>
<p>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
the next time anyone signs in.</p>
<p><strong>To unlock someone now,</strong> tick every row with their username,
choose “Delete selected access attempts”, click Go, then confirm.</p>
<p>A username shown as “(unknown) …” matched no account and is stored as a
hash.</p>
{% elif opts.model_name == "accesslog" %}
<p>Every successful sign-in to <code>/admin</code>, with the time the person
signed out. A blank logout time means they are still signed in, or their
session expired without signing out.</p>
<p>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.</p>
{% elif opts.model_name == "accessfailurelog" %}
<p>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 usually means someone is
guessing its password, or its owner has forgotten it.</p>
<p>A username that matches no account is stored as a hash, so a password typed
into the username box by mistake is never saved.</p>
{% endif %}
</div>
{% endblock %}

{% block extrastyle %}
{{ block.super }}
<style>
/* Admin custom properties rather than literal colors, so the box follows
the light/dark theme toggle (same approach as the Grant changelist). */
.ml-axes-help {
background: var(--darkened-bg, #f8f8f8);
border: 1px solid var(--hairline-color, #e8e8e8);
border-left: 4px solid var(--primary, #79aec8);
color: var(--body-fg, #333);
border-radius: 4px;
padding: 10px 15px;
margin: 0 0 20px 0;
max-width: 70em;
font-size: 14px;
line-height: 1.5;
}
.ml-axes-help p { margin: 0; padding: 0; }
.ml-axes-help p + p { margin-top: 8px; }
</style>
{% endblock %}
41 changes: 41 additions & 0 deletions website/tests/test_login_throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,47 @@ 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": "Attempts made while a username is locked out are not",
}

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 django.conf import settings

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):
"""Pin the production policy so a settings edit can't quietly weaken it."""

Expand Down
Loading