Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Check password length earlier

Chocobozzzcd9a79584dd8
diff --git a/config/config-schema.json b/config/config-schema.json
index b125178040..f50b227a75 100644
--- a/config/config-schema.json
+++ b/config/config-schema.json
@@ -264,23 +264,22 @@
"additionalProperties": false
},
"login_lockout": {
- "description": "Lock an account (independently of the source IP) after too many password/OTP login failures. Each source IP's failures only count towards the lock up to max_per_ip, so a single attacker IP cannot lock an account by itself; reaching max requires failures from several distinct IPs",
+ "description": "Lock an account after too many password/OTP login failures",
"type": "object",
"properties": {
"window": {
- "description": "Lock duration once the threshold is reached, and the rolling window during which failures accumulate towards it",
"type": "string",
"default": "5 minutes"
},
"max": {
- "description": "Failed login/OTP attempts allowed (summed across contributing IPs, see max_per_ip) before the account is locked",
+ "description": "Requires at least 4 distinct IPs (`max / max_per_ip`) to lock an account",
"type": "integer",
- "default": 10
+ "default": 20
},
"max_per_ip": {
- "description": "Cap on how many of a single source IP's failed attempts count towards max",
+ "description": "A single IP's contribution to the account lock is capped at 5 failures",
"type": "integer",
- "default": 3
+ "default": 5
}
},
"additionalProperties": false
diff --git a/config/default.yaml b/config/default.yaml
index 737b656f0c..5987db7714 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -76,8 +76,8 @@ rates_limit:
max: 60
login_lockout: # Lock an account after too many password/OTP login failures
window: 5 minutes
- max: 20 # Requires at least 4 distinct IPs (`max / max_per_ip`) to lock an account
- max_per_ip: 5 # A single IP's contribution to the account lock is capped at 5 failures
+ max: 60 # Requires at least 10 distinct IPs (`max / max_per_ip`) to lock an account
+ max_per_ip: 6 # A single IP's contribution to the account lock is capped at 6 failures
oauth2:
token_lifetime:
diff --git a/config/production.yaml.example b/config/production.yaml.example
index 1b5cc87e6c..b8f8ac84a3 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -74,8 +74,8 @@ rates_limit:
max: 60
login_lockout: # Lock an account after too many password/OTP login failures
window: 5 minutes
- max: 20 # Requires at least 4 distinct IPs (`max / max_per_ip`) to lock an account
- max_per_ip: 5 # A single IP's contribution to the account lock is capped at 5 failures
+ max: 60 # Requires at least 10 distinct IPs (`max / max_per_ip`) to lock an account
+ max_per_ip: 6 # A single IP's contribution to the account lock is capped at 6 failures
oauth2:
token_lifetime:
diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.ts
index d2facdb157..558d649dcb 100644
--- a/server/core/initializers/constants.ts
+++ b/server/core/initializers/constants.ts
@@ -942,7 +942,6 @@ export const USER_PASSWORD_RESET_LIFETIME = 60000 * 60 // 60 minutes
export const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7 // 7 days
export const TWO_FACTOR_AUTH_REQUEST_TOKEN_LIFETIME = 60000 * 10 // 10 minutes
-
export let JWT_TOKEN_USER_EXPORT_FILE_LIFETIME: `${number} minutes` | `${number} seconds` = '15 minutes'
export const EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
diff --git a/server/core/lib/auth/oauth-handlers.ts b/server/core/lib/auth/oauth-handlers.ts
index 60f9faa548..eee8fd1a59 100644
--- a/server/core/lib/auth/oauth-handlers.ts
+++ b/server/core/lib/auth/oauth-handlers.ts
@@ -8,6 +8,7 @@ import OAuth2Server, {
UnsupportedGrantTypeError
} from '@node-oauth/oauth2-server'
import { maskSecret } from '@peertube/peertube-core-utils'
+import { isUserPasswordTooLong } from '@server/helpers/custom-validators/users.js'
import { MOAuthClient } from '@server/types/models/index.js'
import express from 'express'
import { logger } from '../../helpers/logger.js'
@@ -15,6 +16,7 @@ import { CONFIG } from '../../initializers/config.js'
import { OAuthClientModel } from '../../models/oauth/oauth-client.js'
import { Hooks } from '../plugins/hooks.js'
import { BypassLogin } from './bypass-login.model.js'
+import { TooLongPasswordError } from './oauth-errors.js'
import { buildToken, getAccessToken, getRefreshToken, revokeToken, saveToken } from './oauth-token.js'
import { getUserOrThrow } from './oauth-user.js'
@@ -120,14 +122,18 @@ async function handlePasswordGrant (options: {
password: oauthRequest.body.password
}, 'filter:oauth.password-grant.get-user.params')
- if (!options.oauthRequest.body.username) {
+ if (!usernameOrEmail) {
throw new InvalidRequestError(req.t('Missing parameter: `username`'))
}
- if (!bypassLogin && !options.oauthRequest.body.password) {
+ if (!bypassLogin && !password) {
throw new InvalidRequestError(req.t('Missing parameter: `password`'))
}
+ if (password && isUserPasswordTooLong(password)) {
+ throw new TooLongPasswordError(req.t('Password is too long. Please reset it using the password reset procedure.'))
+ }
+
const user = await getUserOrThrow({ usernameOrEmail, password, bypassLogin, req, oauthHeaders: options.oauthRequest.headers })
const now = new Date()
diff --git a/server/core/lib/auth/oauth-user.ts b/server/core/lib/auth/oauth-user.ts
index 50ade68c7c..9554f39b6c 100644
--- a/server/core/lib/auth/oauth-user.ts
+++ b/server/core/lib/auth/oauth-user.ts
@@ -2,7 +2,6 @@ import { AccessDeniedError, InvalidGrantError } from '@node-oauth/oauth2-server'
import { pick } from '@peertube/peertube-core-utils'
import { UserRegistrationState } from '@peertube/peertube-models'
import { AttributesOnly } from '@peertube/peertube-typescript-utils'
-import { isUserPasswordTooLong } from '@server/helpers/custom-validators/users.js'
import { isOTPValid } from '@server/helpers/otp.js'
import { AccountModel } from '@server/models/account/account.js'
import { UserRegistrationModel } from '@server/models/user/user-registration.js'
@@ -27,8 +26,7 @@ import {
InvalidTwoFactorError,
MissingTwoFactorError,
RegistrationApprovalRejected,
- RegistrationWaitingForApproval,
- TooLongPasswordError
+ RegistrationWaitingForApproval
} from './oauth-errors.js'
export async function getUserOrThrow (options: {
@@ -55,7 +53,7 @@ export async function getUserOrThrow (options: {
logger.debug('Getting User (username/email: ' + usernameOrEmail + ', password: ******).')
- const users = await UserModel.loadByUsernameOrEmailCaseInsensitive(usernameOrEmail)
+ const users = await UserModel.listByUsernameOrEmailCaseInsensitive(usernameOrEmail)
const user = usernameOrEmail.includes('@')
? getByEmailPermissive(users, usernameOrEmail)
: users[0]
@@ -86,10 +84,6 @@ export async function getUserOrThrow (options: {
throwInvalidGrantError()
}
- if (isUserPasswordTooLong(password)) {
- throw new TooLongPasswordError(req.t('Password is too long. Please reset it using the password reset procedure.'))
- }
-
const passwordMatch = await user.isPasswordMatch(password)
if (passwordMatch !== true) {
const failures = await Redis.Instance.addLoginFailure(user.id, req.ip)
diff --git a/server/core/middlewares/validators/shared/users.ts b/server/core/middlewares/validators/shared/users.ts
index 66827b51f7..cec2584d69 100644
--- a/server/core/middlewares/validators/shared/users.ts
+++ b/server/core/middlewares/validators/shared/users.ts
@@ -43,8 +43,8 @@ export async function checkUsernameOrEmailDoNotAlreadyExist (options: {
}) {
const { username, email, req, res } = options
- const existingUser = await UserModel.loadByUsernameOrEmailCaseInsensitive(username)
- const existingEmail = await UserModel.loadByUsernameOrEmailCaseInsensitive(email)
+ const existingUser = await UserModel.listByUsernameOrEmailCaseInsensitive(username)
+ const existingEmail = await UserModel.listByUsernameOrEmailCaseInsensitive(email)
if (existingUser.length > 0 || existingEmail.length > 0) {
res.fail({
diff --git a/server/core/models/user/user.ts b/server/core/models/user/user.ts
index de80d53499..71de459d1b 100644
--- a/server/core/models/user/user.ts
+++ b/server/core/models/user/user.ts
@@ -766,7 +766,7 @@ export class UserModel extends SequelizeModel<UserModel> {
return UserModel.findAll(query)
}
- static loadByUsernameOrEmailCaseInsensitive (usernameOrEmail: string): Promise<MUserDefault[]> {
+ static listByUsernameOrEmailCaseInsensitive (usernameOrEmail: string): Promise<MUserDefault[]> {
const query = {
where: {
[Op.or]: [