fix: a Kanban user's own password change signs out their other sessions and counts wrong current passwords (security area 3)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m47s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m2s

/api/operator/me/password left every other session of the account valid for
up to 8 h, and a wrong current password was never counted, so a session left
open could guess it. Now, as a customer's change already does: the throttle
and login_failed of the sign-in, and the other sessions of the account end.
users_test proves both; the Usuários admin edit already ended sessions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-12-01 14:20:23 -03:00
parent 52fc90cbcd
commit 0f833fa1fa
2 changed files with 30 additions and 4 deletions

View File

@@ -16,8 +16,8 @@ from pydantic import Field, field_validator
from .. import machines, mail, observability
from ..core import db
from ..core.auth import (CAPABILITIES, audit, can, has, machine_bound, machine_question, may_move, may_reorder,
password_hash, password_matches, roles_of, signed_in)
from ..core.auth import (CAPABILITIES, audit, can, client_ip, has, login_failed, machine_bound, machine_question,
may_move, may_reorder, password_hash, password_matches, roles_of, signed_in, throttle)
from ..core.models import StrictModel
from ..runtime import BACK, ENVIRONMENT, STATES, TRANSITIONS
@@ -149,12 +149,21 @@ def choose_session_machine(body: MachineAnswer, request: Request):
@router.post('/api/operator/me/password')
def change_password(body: PasswordChange, request: Request):
"""As a customer's (app/api/customer.py): a wrong current password counts
against the sign-in, so a session left open cannot guess it, and the new one
signs out every other session of this account (security area 3, 01/12)."""
account = signed_in(request)
throttle('operator:' + account['email'], request)
with db.connect() as c:
row = c.execute('SELECT password_hash FROM dtf_local.operators WHERE id=%s', (account['id'],)).fetchone()
if not password_matches(body.current, row['password_hash']):
raise HTTPException(403, 'A senha atual não confere.')
if not password_matches(body.current, row['password_hash']):
login_failed('operator:' + account['email'])
audit('operator_password_change_failed', operator=account['email'], ip=client_ip(request))
raise HTTPException(403, 'A senha atual não confere.')
with db.connect() as c:
c.execute('UPDATE dtf_local.operators SET password_hash=%s WHERE id=%s', (password_hash(body.new), account['id']))
c.execute('DELETE FROM dtf_local.operator_sessions WHERE username=%s AND token_hash<>%s',
(account['email'], account['session']))
audit('operator_password_changed', operator=account['email'])
return {'ok': True}