A5: sign up, sign in, sign out, profile and the base layout (WEB-02, WEB-06, WEB-11, WEB-50..54)

Registration (case-insensitive unique names, 8-256 char passwords, no email),
sign-in with a generic error and a fresh session, internal-only ?next=,
POST-only sign-out, password change that closes the other sessions. The
failed-login backoff, the registration quota and the password-change guard
live in the database so every web process shares them; the client IP is the
last X-Forwarded-For hop. One responsive stylesheet with light/dark theme,
labelled fields, alerts and no inline scripts or styles; Italian error pages
and a readable CSRF failure. Mutation checks: open redirects, uncounted
failures and a missing CSRF middleware are all caught.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-11-16 14:07:45 +01:00
1 parent 1d4b53d778
commit efb3e2e702
28 files changed
+1232 -22

No files matched your search

+9 -4
View File
@@ -53,8 +53,9 @@ MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
@@ -102,14 +103,16 @@ PASSWORD_HASHERS = [
"django.contrib.auth.hashers.Argon2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2PasswordHasher",
]
# SEC-17: 8 to 256 characters, nothing more — the same thresholds as the old server.
AUTH_PASSWORD_VALIDATORS = [
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", "OPTIONS": {"min_length": 8}},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
{"NAME": "apps.accounts.validators.MinimumLengthValidator"},
{"NAME": "apps.accounts.validators.MaximumLengthValidator"},
]
AUTHENTICATION_BACKENDS = ["apps.accounts.backends.CaseInsensitiveBackend"]
# ADR-60: Italian only for the pilot; gettext is on so other languages can be added later.
LANGUAGE_CODE = "it"
LANGUAGES = [("it", "Italiano")] # one language: the middleware activates it, so Django's own messages are Italian too
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
@@ -126,6 +129,7 @@ STORAGES = {
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SESSION_COOKIE_SECURE = not DEBUG
CSRF_COOKIE_SECURE = not DEBUG
SESSION_COOKIE_AGE = 24 * 3600 # a session lasts a day, like the old token (ADR-36)
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = "Lax"
CSRF_COOKIE_SAMESITE = "Lax"
@@ -136,6 +140,7 @@ SECURE_REFERRER_POLICY = "strict-origin-when-cross-origin"
LOGIN_URL = "/accedi/"
LOGIN_REDIRECT_URL = "/app/"
LOGOUT_REDIRECT_URL = "/"
CSRF_FAILURE_VIEW = "apps.web.views.csrf_failure"
LOGGING = {
"version": 1,