Enforce the type of login parameters

As they are received from a non authenticated entrypoint, we must ensure their
types.
This commit is contained in:
Cédric Krier
2026-09-02 12:19:42 +02:00
parent 53a97c277d
commit bc8def47b0
3 changed files with 19 additions and 18 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ class User(metaclass=PoolMeta):
if user_id:
SMSCode.send(user_id)
if 'sms_code' in parameters:
code = parameters['sms_code']
code = str(parameters['sms_code'])
if not code:
return
if SMSCode.check(user_id, code):
+1 -1
View File
@@ -135,7 +135,7 @@ class User(metaclass=PoolMeta):
if 'password' not in parameters:
msg = gettext('res.msg_user_password', login=login)
raise LoginException('password', msg, type='password')
password = parameters['password']
password = str(parameters['password'])
try:
server = ldap_server()
if server:
+17 -16
View File
@@ -775,21 +775,22 @@ class User(avatar_mixin(100, 'login'), DeactivableMixin, ModelSQL, ModelView):
msg = gettext('res.msg_user_password', login=login)
raise LoginException('password', msg, type='password')
user_id, password_hash, password_reset = cls._get_login(login)
if user_id and password_hash:
password = parameters['password']
valid, new_hash = cls.check_password(password, password_hash)
if valid:
if new_hash:
logger.info("Update password hash for %s", user_id)
with Transaction().new_transaction():
with without_check_access():
cls.write([cls(user_id)], {
'password_hash': new_hash,
})
return user_id
if user_id and password_reset:
if compare_digest(password_reset, parameters['password']):
return user_id
if user_id:
password = str(parameters['password'])
if password_hash:
valid, new_hash = cls.check_password(password, password_hash)
if valid:
if new_hash:
logger.info("Update password hash for %s", user_id)
with Transaction().new_transaction():
with without_check_access():
cls.write([cls(user_id)], {
'password_hash': new_hash,
})
return user_id
if password_reset:
if compare_digest(password_reset, password):
return user_id
@classmethod
def hash_password(cls, password):
@@ -894,7 +895,7 @@ class UserDevice(ModelSQL):
try:
device, = cls.search([
('login', '=', login),
('cookie', '=', cookie),
('cookie', '=', str(cookie)),
], limit=1)
except ValueError:
return None