From c4ff538a8aaf68ba11aefd0f63f7fbc340cda423 Mon Sep 17 00:00:00 2001 From: ngqile Date: Mon, 30 Nov 2026 15:01:28 +0800 Subject: [PATCH] docs(openspec): archive add-admin-login-security Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../.openspec.yaml | 0 .../design.md | 0 .../proposal.md | 0 .../specs/admin-login-security/spec.md | 0 .../specs/admin-own-password/spec.md | 0 .../sql/01-login-audit.sql | 0 .../sql/02-lockout-settings.sql | 0 .../sql/03-login-security-module.sql | 0 .../sql/99-rollback.sql | 0 .../tasks.md | 0 openspec/specs/admin-login-security/spec.md | 133 ++++++++++++++++++ openspec/specs/admin-own-password/spec.md | 56 ++++++++ 12 files changed, 189 insertions(+) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/.openspec.yaml (100%) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/design.md (100%) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/proposal.md (100%) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/specs/admin-login-security/spec.md (100%) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/specs/admin-own-password/spec.md (100%) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/sql/01-login-audit.sql (100%) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/sql/02-lockout-settings.sql (100%) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/sql/03-login-security-module.sql (100%) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/sql/99-rollback.sql (100%) rename openspec/changes/{add-admin-login-security => archive/2026-11-30-add-admin-login-security}/tasks.md (100%) create mode 100644 openspec/specs/admin-login-security/spec.md create mode 100644 openspec/specs/admin-own-password/spec.md diff --git a/openspec/changes/add-admin-login-security/.openspec.yaml b/openspec/changes/archive/2026-11-30-add-admin-login-security/.openspec.yaml similarity index 100% rename from openspec/changes/add-admin-login-security/.openspec.yaml rename to openspec/changes/archive/2026-11-30-add-admin-login-security/.openspec.yaml diff --git a/openspec/changes/add-admin-login-security/design.md b/openspec/changes/archive/2026-11-30-add-admin-login-security/design.md similarity index 100% rename from openspec/changes/add-admin-login-security/design.md rename to openspec/changes/archive/2026-11-30-add-admin-login-security/design.md diff --git a/openspec/changes/add-admin-login-security/proposal.md b/openspec/changes/archive/2026-11-30-add-admin-login-security/proposal.md similarity index 100% rename from openspec/changes/add-admin-login-security/proposal.md rename to openspec/changes/archive/2026-11-30-add-admin-login-security/proposal.md diff --git a/openspec/changes/add-admin-login-security/specs/admin-login-security/spec.md b/openspec/changes/archive/2026-11-30-add-admin-login-security/specs/admin-login-security/spec.md similarity index 100% rename from openspec/changes/add-admin-login-security/specs/admin-login-security/spec.md rename to openspec/changes/archive/2026-11-30-add-admin-login-security/specs/admin-login-security/spec.md diff --git a/openspec/changes/add-admin-login-security/specs/admin-own-password/spec.md b/openspec/changes/archive/2026-11-30-add-admin-login-security/specs/admin-own-password/spec.md similarity index 100% rename from openspec/changes/add-admin-login-security/specs/admin-own-password/spec.md rename to openspec/changes/archive/2026-11-30-add-admin-login-security/specs/admin-own-password/spec.md diff --git a/openspec/changes/add-admin-login-security/sql/01-login-audit.sql b/openspec/changes/archive/2026-11-30-add-admin-login-security/sql/01-login-audit.sql similarity index 100% rename from openspec/changes/add-admin-login-security/sql/01-login-audit.sql rename to openspec/changes/archive/2026-11-30-add-admin-login-security/sql/01-login-audit.sql diff --git a/openspec/changes/add-admin-login-security/sql/02-lockout-settings.sql b/openspec/changes/archive/2026-11-30-add-admin-login-security/sql/02-lockout-settings.sql similarity index 100% rename from openspec/changes/add-admin-login-security/sql/02-lockout-settings.sql rename to openspec/changes/archive/2026-11-30-add-admin-login-security/sql/02-lockout-settings.sql diff --git a/openspec/changes/add-admin-login-security/sql/03-login-security-module.sql b/openspec/changes/archive/2026-11-30-add-admin-login-security/sql/03-login-security-module.sql similarity index 100% rename from openspec/changes/add-admin-login-security/sql/03-login-security-module.sql rename to openspec/changes/archive/2026-11-30-add-admin-login-security/sql/03-login-security-module.sql diff --git a/openspec/changes/add-admin-login-security/sql/99-rollback.sql b/openspec/changes/archive/2026-11-30-add-admin-login-security/sql/99-rollback.sql similarity index 100% rename from openspec/changes/add-admin-login-security/sql/99-rollback.sql rename to openspec/changes/archive/2026-11-30-add-admin-login-security/sql/99-rollback.sql diff --git a/openspec/changes/add-admin-login-security/tasks.md b/openspec/changes/archive/2026-11-30-add-admin-login-security/tasks.md similarity index 100% rename from openspec/changes/add-admin-login-security/tasks.md rename to openspec/changes/archive/2026-11-30-add-admin-login-security/tasks.md diff --git a/openspec/specs/admin-login-security/spec.md b/openspec/specs/admin-login-security/spec.md new file mode 100644 index 0000000..34b209a --- /dev/null +++ b/openspec/specs/admin-login-security/spec.md @@ -0,0 +1,133 @@ +# admin-login-security Specification + +## Purpose + +Protect admin sign-in against password guessing: record every admin sign-in, sign-out, unlock and own password change, lock a username after repeated failures, and let authorised admins read the history, unlock staff and edit the lockout and password-rule settings. + +## Requirements + +### Requirement: Login history + +The system SHALL record every admin sign-in attempt, sign-out, unlock and own password change, with the time, trimmed username, event, client IP, user agent and, for a known username, the user's company. Events: `LOGIN_SUCCESS`, `LOGIN_FAIL`, `LOGIN_LOCKED`, `LOGOUT`, `UNLOCK_RESET`, `PASSWORD_CHANGED`. Recording SHALL be best-effort and MUST NOT change the sign-in answer. A blank username or password SHALL NOT be recorded. + +#### Scenario: Successful sign-in is recorded + +- **WHEN** `sales1` signs in with the right password +- **THEN** a `LOGIN_SUCCESS` record for `sales1` is saved with the time, client IP and user agent + +#### Scenario: Failed sign-in is recorded + +- **WHEN** someone signs in as `sales1` with a wrong password +- **THEN** a `LOGIN_FAIL` record for `sales1` is saved + +#### Scenario: Unknown username is recorded + +- **WHEN** someone signs in as `nobody1`, which matches no user +- **THEN** a `LOGIN_FAIL` record for `nobody1` is saved with no company + +#### Scenario: Sign-out is recorded + +- **WHEN** `sales1` signs out +- **THEN** a `LOGOUT` record for `sales1` is saved + +#### Scenario: History write failure does not block sign-in + +- **GIVEN** the history cannot be written +- **WHEN** `sales1` signs in with the right password +- **THEN** the sign-in succeeds +- **AND** the write failure is logged + +### Requirement: Lockout after repeated failures + +The system SHALL lock a username when lockout is on and its `LOGIN_FAIL` records reach the configured maximum, counting only records inside the configured period and after its latest `LOGIN_SUCCESS`, `UNLOCK_RESET` or `PASSWORD_CHANGED`. The maximum, period, unit and on/off switch SHALL come from settings. Failures SHALL count for unknown usernames too, so a lock does not reveal whether an account exists. The lock SHALL end once the counted failures leave the period. + +#### Scenario: Maximum reached locks the username + +- **GIVEN** lockout is on with a maximum of 5 in 15 minutes +- **WHEN** `sales1` fails to sign in 5 times within 15 minutes +- **THEN** `sales1` is locked + +#### Scenario: Old failures do not count + +- **GIVEN** lockout is on with a maximum of 5 in 15 minutes +- **WHEN** `sales1` has 4 failures within the last 15 minutes and 3 older ones +- **THEN** `sales1` is not locked + +#### Scenario: A success resets the count + +- **WHEN** `sales1` fails 4 times, signs in successfully, then fails 4 more times within 15 minutes +- **THEN** `sales1` is not locked + +#### Scenario: Lockout switched off + +- **GIVEN** lockout is off +- **WHEN** `sales1` fails 10 times within 15 minutes +- **THEN** `sales1` is not locked + +### Requirement: Locked username is refused + +The system SHALL refuse sign-in for a locked username before checking the password, with the code `ACCOUNT_LOCKED` and a message telling the user to try later or ask an administrator, and SHALL record `LOGIN_LOCKED`. When the lock state cannot be read because of an infrastructure error, sign-in SHALL proceed to the normal password check. + +#### Scenario: Right password while locked + +- **GIVEN** `sales1` is locked +- **WHEN** `sales1` signs in with the right password +- **THEN** sign-in is refused with `ACCOUNT_LOCKED` +- **AND** no session is issued +- **AND** a `LOGIN_LOCKED` record is saved + +#### Scenario: Lock check unavailable + +- **GIVEN** the lock state cannot be read +- **WHEN** `sales1` signs in with the right password +- **THEN** the sign-in succeeds + +#### Scenario: Portal shows the locked message + +- **WHEN** sign-in is refused with `ACCOUNT_LOCKED` +- **THEN** the login page shows the locked message instead of "Invalid username or password" + +### Requirement: Unlock + +The system SHALL let an admin with `BO_LOGIN_SECURITY` list the usernames that are locked now, with their failure count, last failure time and when the lock ends, and SHALL let that admin unlock one. Unlocking SHALL save an `UNLOCK_RESET` record naming the admin who unlocked. + +#### Scenario: Unlock a locked username + +- **GIVEN** `sales1` is locked +- **WHEN** an admin with `BO_LOGIN_SECURITY` unlocks `sales1` +- **THEN** `sales1` no longer appears in the locked list +- **AND** `sales1` can sign in with the right password +- **AND** an `UNLOCK_RESET` record for `sales1` names the admin + +### Requirement: Login history screen + +The system SHALL let an admin with `BO_LOGIN_SECURITY` read the login history, newest first and paged, filtered by username, event and date range. + +#### Scenario: Filter by event + +- **WHEN** an admin filters the history by event `LOGIN_FAIL` +- **THEN** only `LOGIN_FAIL` records are listed, newest first + +#### Scenario: Without the module + +- **WHEN** an admin without `BO_LOGIN_SECURITY` calls the login-security API +- **THEN** the request is refused with 403 + +### Requirement: Lockout and password-rule settings + +The system SHALL let an admin with `BO_LOGIN_SECURITY` read and change the lockout settings (on/off, maximum attempts, period, time unit) and the admin password rules (each rule's on/off status and value). The system SHALL reject a maximum below 1 or above 1000, a period below 1 or above 10000, and a time unit other than S, M, H or D. Password rules SHALL only be edited, never added or removed. Every change SHALL write a log line naming the admin. + +#### Scenario: Change the lockout settings + +- **WHEN** an admin sets the maximum to 3 and the period to 30 minutes +- **THEN** the next lock decision uses 3 attempts in 30 minutes + +#### Scenario: Invalid setting + +- **WHEN** an admin sets the maximum to 0 +- **THEN** the change is refused with a validation error and the settings stay as they were + +#### Scenario: Change a password rule + +- **WHEN** an admin sets the minimum length rule to 10 +- **THEN** a new password of 9 characters is refused by every admin password check diff --git a/openspec/specs/admin-own-password/spec.md b/openspec/specs/admin-own-password/spec.md new file mode 100644 index 0000000..b2df473 --- /dev/null +++ b/openspec/specs/admin-own-password/spec.md @@ -0,0 +1,56 @@ +# admin-own-password Specification + +## Purpose + +Let a signed-in admin change their own password, checked against the current password and the admin password rules, without an administrator. + +## Requirements + +### Requirement: Change own password + +The system SHALL let a signed-in admin change their own password by giving the current password, a new password and its confirmation. The new password SHALL pass the admin password rules and SHALL differ from the current one. On success the system SHALL keep the admin signed in, keep their first-login state complete, and record `PASSWORD_CHANGED`. An admin whose first-login password change is still pending SHALL use the first-login flow instead. + +#### Scenario: Successful change + +- **WHEN** `sales1` gives the right current password and a new password that passes the rules, twice +- **THEN** the new password works at the next sign-in and the old one does not +- **AND** `sales1` stays signed in +- **AND** a `PASSWORD_CHANGED` record is saved + +#### Scenario: Confirmation differs + +- **WHEN** the new password and its confirmation differ +- **THEN** the change is refused with `PASSWORD_MISMATCH` + +#### Scenario: Same as current + +- **WHEN** the new password equals the current password +- **THEN** the change is refused with `PASSWORD_SAME` + +#### Scenario: Fails the rules + +- **WHEN** the new password breaks an admin password rule +- **THEN** the change is refused with `PASSWORD_POLICY` + +#### Scenario: Pending first login + +- **GIVEN** `sales1` must still complete the first-login password change +- **WHEN** `sales1` calls change password +- **THEN** the request is refused and `sales1` is sent to the first-login flow + +### Requirement: Wrong current password counts as a failed sign-in + +The system SHALL refuse a change whose current password is wrong with `CURRENT_PASSWORD_WRONG`, and SHALL record it as `LOGIN_FAIL` so that repeated wrong guesses lock the username. A locked username SHALL be refused with `ACCOUNT_LOCKED` before the current password is checked. + +#### Scenario: Wrong current password + +- **WHEN** `sales1` gives a wrong current password +- **THEN** the change is refused with `CURRENT_PASSWORD_WRONG` +- **AND** a `LOGIN_FAIL` record for `sales1` is saved + +#### Scenario: Locked while changing + +- **GIVEN** `sales1` is locked +- **WHEN** `sales1` calls change password with the right current password +- **THEN** the change is refused with `ACCOUNT_LOCKED` +- **AND** the password is unchanged