Password & login security
Enforce password rules, prevent password reuse, lock accounts after failed logins and rate-limit sensitive user endpoints.
Password policy
Password rules for users and identities live in the configuration module, under the user and identity modules:
curl -X PUT https://api.example.com/api/config/user \
-H "Authorization: IDENTITY <token>" -H "Content-Type: application/json" \
-d '{"password": {"minLength": 10, "minLowercase": 1, "minUppercase": 1, "minNumber": 1, "minSpecialCharacter": 1}}'| Rule | Description |
|---|---|
minLength | Minimum number of characters. |
minLowercase | Minimum lowercase letters. |
minUppercase | Minimum uppercase letters. |
minNumber | Minimum digits. |
minSpecialCharacter | Minimum special characters. |
Passwords that break the rules are rejected when an account is created or its password changes:
{"message": ".password must NOT have fewer than 10 characters", "error": "validation failed", "statusCode": 400}Password history
Prevent people from reusing their recent passwords:
| Option | Default |
|---|---|
--passport-identity-password-history-limit | 0 (off) |
--passport-user-password-history-limit | 0 (off) |
With a limit of 5, a new password can't be any of the last five.
Lockout after failed logins
| Option | Default | Description |
|---|---|---|
--passport-identity-failed-login-attempt-limit | 0 (off) | Failed logins before identities are blocked. |
--passport-identity-block-duration-after-failed-login-attempts | 0 | Minutes the block lasts. |
--passport-user-failed-login-attempt-limit | 0 (off) | Failed logins before users are blocked. |
--passport-user-block-duration-after-failed-login-attempts | 0 | Minutes the block lasts. |
For example, --passport-user-failed-login-attempt-limit=5 --passport-user-block-duration-after-failed-login-attempts=15 blocks a user for 15 minutes after five wrong passwords.
Rate limits
User endpoints that attackers like to hammer have their own rate limits, set in the user configuration:
{
"rateLimits": {
"login": {"limit": 10, "ttl": 60},
"forgotPassword": {"limit": 5, "ttl": 300},
"providerVerification": {"limit": 5, "ttl": 300},
"refreshToken": {"limit": 30, "ttl": 60},
"createUser": {"limit": 20, "ttl": 60}
}
}limit is the number of requests allowed within ttl seconds.
| Key | Applies to |
|---|---|
login | User login (/passport/login) and passwordless login. |
forgotPassword | Password reset start and verify. |
providerVerification | Email and phone verification. |
refreshToken | User session refresh. |
createUser | POST /passport/user. |
For your own HTTP functions, use the trigger's rateLimit option.
Account and instance limits
| Option | Effect |
|---|---|
--passport-user-limit | Maximum number of users. |
--passport-identity-limit | Maximum number of identities. |
--passport-user-verification-code-expires-in | Lifetime of verification codes in seconds (default 300). |
Checklist
- Change the default identity's password, or remove the default identity.
- Turn on two-factor authentication for identities with full access.
- Set a password policy for users and identities.
- Enable lockout and rate limits before you open sign-up to the public.
- Keep access tokens short-lived and use refresh tokens.
- Serve the API over HTTPS only.
- Review identities, API keys and refresh tokens regularly, and remove what's unused.