Skip to content

Commit f32ed71

Browse files
authored
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
1 parent 8a32b3b commit f32ed71

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/gui/PasswordWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ bool PasswordWidget::eventFilter(QObject* watched, QEvent* event)
231231
if (isVisible() && (type == QEvent::KeyPress || type == QEvent::KeyRelease || type == QEvent::FocusIn)) {
232232
checkCapslockState();
233233
}
234-
if (type == QEvent::FocusIn || type == QEvent::FocusOut) {
234+
if (type == QEvent::FocusIn || type == QEvent::FocusOut || type == QEvent::Hide) {
235235
osUtils->setUserInputProtection(type == QEvent::FocusIn);
236236
}
237237
}

src/gui/osutils/macutils/MacUtils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,22 @@ bool MacUtils::isCapslockEnabled()
152152

153153
void MacUtils::setUserInputProtection(bool enable)
154154
{
155+
static bool secureInputEnabled = false;
155156
if (enable) {
157+
/*
158+
* MacOS keeps a single counter over all apps that needs to be zero to disable secure input. By never going
159+
* higher than 1 internally this makes sure secure input doesn't stay active after calling this function
160+
* multiple times.
161+
*/
162+
if (secureInputEnabled) {
163+
DisableSecureEventInput();
164+
}
156165
EnableSecureEventInput();
157166
} else {
158167
DisableSecureEventInput();
159168
}
169+
// Store our last known state
170+
secureInputEnabled = enable;
160171
}
161172

162173
/**

0 commit comments

Comments
 (0)