Add safeguards to secure input on macOS (#11928)

* 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-05-23 09:25:25 -04:00
parent 969b56d3ff
commit 877f4399e9
2 changed files with 12 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,22 @@ bool MacUtils::isCapslockEnabled()
void MacUtils::setUserInputProtection(bool enable)
{
static bool secureInputEnabled = false;
if (enable) {
/*
* MacOS keeps a single counter over all apps that needs to be zero to disable secure input. By never going
* higher than 1 internally this makes sure secure input doesn't stay active after calling this function
* multiple times.
*/
if (secureInputEnabled) {
DisableSecureEventInput();
}
EnableSecureEventInput();
} else {
DisableSecureEventInput();
}
// Store our last known state
secureInputEnabled = enable;
}
/**