The vulnerability exists in the timestamp-based authentication caching mechanism of sudo-rs. When Defaults targetpw or Defaults rootpw is enabled in the sudoers configuration, sudo-rs should authenticate using the target user's password. However, the application was incorrectly creating and checking the authentication timestamp file (/var/run/sudo/ts/<username>) using the UID of the user invoking sudo, not the UID of the user being authenticated as.
The patch addresses this by introducing a new AuthUser struct that is passed through the authentication pipeline. This struct holds the context of the user to be authenticated. The key changes are in src/sudo/pipeline.rs and src/system/timestamp.rs.
In src/sudo/pipeline.rs, the auth_and_update_record_file and determine_auth_status functions were modified to use this new AuthUser object when creating or checking timestamp records.
In src/system/timestamp.rs, the functions responsible for interacting with the timestamp file (SessionRecordFile::create, SessionRecordFile::touch, and SessionRecord::matches) were updated to take the AuthUser object and use its UID for all operations.
This ensures that when targetpw is used, the timestamp record is correctly associated with the target user's UID, preventing an attacker who knows one user's password from bypassing authentication for other users they are permitted to impersonate via sudo. The identified functions are the ones directly involved in this flawed logic.