Files
zoneminder/web/api/app/Model/User.php
T
Isaac ConnorandClaude Opus 4.8 05a610a2c6 fix: revoke API tokens when a user's password is changed
Changing a user's password rewrote only the password hash and left the
user's JWT API tokens valid: a pre-change access token kept working and a
pre-change refresh token kept minting new access tokens for up to its 24
hour lifetime, so a leaked token survived the password change meant to
cut it off.

Set TokenMinExpiry to the change time in the same step that rewrites the
hash, so validateToken() rejects every token issued before the change,
matching the options page's existing revoke action. Covered paths: the
REST API User model (beforeSave), with the self-edit controller whitelist
widened to persist the field, and the classic web UI user action for both
the administrator edit and the self edit. The login-time upgrade of a
legacy hash to bcrypt rewrites the same password and is left untouched so
it does not revoke tokens.

refs GHSA-5w6w-qp25-2qqh

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-04 08:26:38 -05:00

105 lines
2.5 KiB
PHP

<?php
App::uses('AppModel', 'Model');
/**
* User Model
*
*/
class User extends AppModel {
public $validate = array(
'Username' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required'
)
),
'Password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required'
),
'acceptable' => array(
'rule' => array('acceptablePassword')
)
)
);
# The same check as the web interface (passwordProblem() in includes/auth.php):
# true, or the reason as the validation message.
public function acceptablePassword($check) {
$problem = passwordProblem(reset($check));
return ($problem === null) ? true : passwordProblemText($problem);
}
function beforeFind($query) {
if ( empty($query['fields']) ) {
$schema = $this->schema();
unset($schema['Password']);
foreach (array_keys($schema) as $field) {
$query['fields'][] = $this->alias . '.' . $field;
}
return $query;
}
return parent::beforeFind($query);
}
public function beforeSave($options = array()) {
if (!empty($this->data['User']['Password'])) {
$this->data['User']['Password'] = password_hash($this->data['User']['Password'], PASSWORD_BCRYPT);
# A password change revokes the user's existing API tokens: any token
# issued before TokenMinExpiry is rejected by validateToken(), the same
# mechanism the options page's revoke action uses. Without this a pre-
# change access or refresh token keeps working after the password is
# changed (refs GHSA-5w6w-qp25-2qqh).
$this->data['User']['TokenMinExpiry'] = time();
}
return true;
} # end function beforeSave
/**
* Use table
*
* @var mixed False or table name
*/
public $useTable = 'Users';
/**
* Primary key field
*
* @var string
*/
public $primaryKey = 'Id';
/**
* Display field
*
* @var string
*/
public $displayField = 'Username';
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Role' => array(
'className' => 'Role',
'foreignKey' => 'RoleId',
),
);
/**
* hasMany associations
*
* @var array
*/
public $hasMany = array(
);
}