Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
163 lines
7.6 KiB
Markdown
163 lines
7.6 KiB
Markdown
# 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 of their own company that are locked now, with their failure count, last failure time and when the lock ends, and SHALL let that admin unlock one of them. A super admin SHALL see and unlock locked usernames of every company, including attempts that match no company. Unlocking SHALL save an `UNLOCK_RESET` record naming the admin who unlocked.
|
|
|
|
#### Scenario: Unlock a locked username
|
|
|
|
- **GIVEN** INS user `sales1` is locked
|
|
- **WHEN** an INS 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
|
|
|
|
#### Scenario: Another company's locked user
|
|
|
|
- **GIVEN** CV user `sales2` is locked
|
|
- **WHEN** an INS admin with `BO_LOGIN_SECURITY` lists locked users or unlocks `sales2` of CV
|
|
- **THEN** `sales2` is not listed and the unlock answers 404
|
|
|
|
### 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 the lockout settings and the admin password rules, and SHALL let only a super admin change them, because they apply to every company. 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** a super admin sets the maximum to 3 and the period to 30 minutes
|
|
- **THEN** the next lock decision in every company uses 3 attempts in 30 minutes
|
|
|
|
#### Scenario: Invalid setting
|
|
|
|
- **WHEN** a super 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** a super admin sets the minimum length rule to 10
|
|
- **THEN** a new password of 9 characters is refused by every admin password check
|
|
|
|
#### Scenario: Company user changes settings
|
|
|
|
- **WHEN** an INS user with `BO_LOGIN_SECURITY` changes a lockout setting or a password rule
|
|
- **THEN** the change is refused with 403 and the settings stay as they were
|
|
|
|
### Requirement: Password hint from the rules
|
|
|
|
Every screen that sets an admin password (first-login change, change own password, set a temporary password, reset password by email link) SHALL show a hint listing the admin password rules that are switched on, with their values, read from the same rules the server checks. A refused password SHALL name the rule it failed.
|
|
|
|
#### Scenario: Hint follows the switched-on rules
|
|
|
|
- **GIVEN** the switched-on admin rules are minimum length 8, at least 1 capital and at least 1 small letter, and the symbol rule is off
|
|
- **WHEN** a user opens the change password dialog
|
|
- **THEN** the hint lists at least 8 characters, 1 capital letter and 1 small letter
|
|
- **AND** it says nothing about symbols
|
|
|
|
#### Scenario: Rule switched on
|
|
|
|
- **GIVEN** a super admin switches on the symbol rule with value 2 under Login security
|
|
- **WHEN** a user opens the reset password page from an email link
|
|
- **THEN** the hint also lists at least 2 symbols
|
|
- **AND** a new password with one symbol is refused with a message naming the symbol rule
|