diff --git a/src/common/communication.ts b/src/common/communication.ts index 781806e0..c5133734 100644 --- a/src/common/communication.ts +++ b/src/common/communication.ts @@ -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'; diff --git a/src/main/app/initialize.ts b/src/main/app/initialize.ts index 1f8415c5..0f4bf414 100644 --- a/src/main/app/initialize.ts +++ b/src/main/app/initialize.ts @@ -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() { diff --git a/src/main/app/intercom.ts b/src/main/app/intercom.ts index 6625764f..27bda6af 100644 --- a/src/main/app/intercom.ts +++ b/src/main/app/intercom.ts @@ -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); +} diff --git a/src/main/preload/mattermost.js b/src/main/preload/mattermost.js index ac3665ad..f927d701 100644 --- a/src/main/preload/mattermost.js +++ b/src/main/preload/mattermost.js @@ -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; +});