Add safeguards to secure input on macOS

* Fixes #11906
* Disable secure input when password widget is hidden as well as focused out
* Add safeguard to ensure the internal counter that macOS keeps is always set to 1 preventing the ability to disable secure input by focus/unfocus a password field
This commit is contained in:
Jonathan White 2025-03-21 07:30:09 -04:00
parent 37ddbb3cd2
commit 2a18b84b05
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
2 changed files with 8 additions and 1 deletions

View file

@ -231,7 +231,7 @@ bool PasswordWidget::eventFilter(QObject* watched, QEvent* event)
if (isVisible() && (type == QEvent::KeyPress || type == QEvent::KeyRelease || type == QEvent::FocusIn)) {
checkCapslockState();
}
if (type == QEvent::FocusIn || type == QEvent::FocusOut) {
if (type == QEvent::FocusIn || type == QEvent::FocusOut || type == QEvent::Hide) {
osUtils->setUserInputProtection(type == QEvent::FocusIn);
}
}

View file

@ -152,11 +152,18 @@ bool MacUtils::isCapslockEnabled()
void MacUtils::setUserInputProtection(bool enable)
{
static bool secureInputEnabled = false;
if (enable) {
// Always keep the internal counter set to 1
if (secureInputEnabled) {
DisableSecureEventInput();
}
EnableSecureEventInput();
} else {
DisableSecureEventInput();
}
// Store our last known state
secureInputEnabled = enable;
}
/**