[MM-54463] Enforce secure keyboard entry on macOS when a password box is focused (#2829)

* [MM-54463] Enforce secure keyboard entry on macOS when a password box is focused

* PR feedback
This commit is contained in:
Devin Binnie 2023-09-15 10:24:19 -04:00 committed by GitHub
parent 88e1fea4e7
commit d5f5c4849a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View file

@ -175,3 +175,5 @@ export const MAIN_WINDOW_FOCUSED = 'main-window-focused';
export const VALIDATE_SERVER_URL = 'validate-server-url';
export const GET_IS_DEV_MODE = 'get-is-dev-mode';
export const TOGGLE_SECURE_INPUT = 'toggle-secure-input';

View file

@ -29,6 +29,7 @@ import {
WINDOW_MINIMIZE,
WINDOW_RESTORE,
DOUBLE_CLICK_ON_WINDOW,
TOGGLE_SECURE_INPUT,
} from 'common/communication';
import Config from 'common/config';
import {isTrustedURL, parseURL} from 'common/utils/url';
@ -80,6 +81,7 @@ import {
handleOpenAppMenu,
handleQuit,
handlePingDomain,
handleToggleSecureInput,
} from './intercom';
import {
clearAppCache,
@ -272,6 +274,8 @@ function initializeInterCommunicationEventListeners() {
ipcMain.on(WINDOW_MINIMIZE, handleMinimize);
ipcMain.on(WINDOW_RESTORE, handleRestore);
ipcMain.on(DOUBLE_CLICK_ON_WINDOW, handleDoubleClick);
ipcMain.on(TOGGLE_SECURE_INPUT, handleToggleSecureInput);
}
async function initializeAfterAppReady() {

View file

@ -147,3 +147,9 @@ export function handlePingDomain(event: IpcMainInvokeEvent, url: string): Promis
throw new Error('Could not find server ' + url);
});
}
export function handleToggleSecureInput(event: IpcMainEvent, secureInput: boolean) {
// Enforce macOS to restrict processes from reading the keyboard input when in a password field
log.debug('handleToggleSecureInput', secureInput);
app.setSecureKeyboardEntryEnabled(secureInput);
}

View file

@ -38,6 +38,7 @@ import {
CALLS_ERROR,
CALLS_JOIN_REQUEST,
GET_IS_DEV_MODE,
TOGGLE_SECURE_INPUT,
} from 'common/communication';
const UNREAD_COUNT_INTERVAL = 1000;
@ -373,3 +374,16 @@ ipcRenderer.on(CALLS_JOIN_REQUEST, (event, message) => {
window.addEventListener('resize', () => {
ipcRenderer.send(VIEW_FINISHED_RESIZING);
});
let isPasswordBox = false;
window.addEventListener('focusin', (event) => {
const targetIsPasswordBox = event.target.tagName === 'INPUT' && event.target.type === 'password';
if (targetIsPasswordBox && !isPasswordBox) {
ipcRenderer.send(TOGGLE_SECURE_INPUT, true);
} else if (!targetIsPasswordBox && isPasswordBox) {
ipcRenderer.send(TOGGLE_SECURE_INPUT, false);
}
isPasswordBox = targetIsPasswordBox;
});