Repository navigation
security: IPC channel whitelisting and structured argument sanitization (#3377) #3568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jhaabhijeet864
wants to merge
3
commits into
RocketChat:dev
from
jhaabhijeet864:security/ipc-whitelisting-sanitization-3377
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
4f786fb
security: IPC channel whitelisting and structured argument sanitizati…
jhaabhijeet864 be1f477
feat: add IPC message sanitization and channel whitelist for webview …
jhaabhijeet864 10e8236
feat: implement video call window renderer logic and event handlers
jhaabhijeet864 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { ipcRenderer } from 'electron'; | ||
|
|
||
| const sanitize = (args: unknown[]): unknown[] => structuredClone(args); | ||
|
|
||
| // Define allowed channels for the webview preload environment. | ||
| // This prevents the untrusted server view from exploiting the contextBridge | ||
| // to send unauthorized IPC messages to the main process or other windows. | ||
| const ALLOWED_CHANNELS = new Set([ | ||
| 'redux/get-initial-state', | ||
| 'redux/action-dispatched', | ||
| 'servers/fetch-info', | ||
| 'notifications/fetch-icon', | ||
| 'power-monitor/get-system-idle-state', | ||
| 'certificatesManager/remove', | ||
| 'server-view/get-url', | ||
| 'ui-preview/apply', | ||
| 'ui-preview/restore', | ||
| 'ui-preview/add', | ||
| 'ui-preview/refresh', | ||
| 'server-view/ready', | ||
| 'server-view/open-url-on-browser', | ||
| 'server-view/take-pending-conference', | ||
| 'server-view/conference-requested', | ||
| 'video-call-window/open-window', | ||
| 'video-call-window/open-url', | ||
| 'video-call-window/open-in-main-window', | ||
| 'video-call-window/open-screen-picker', | ||
| 'video-call-window/screen-sharing-source-responded', | ||
| 'video-call-window/screen-recording-is-permission-granted', | ||
| 'video-call-window/close-requested', | ||
| 'video-call-window/open-webview-dev-tools', | ||
| 'video-call-window/handshake', | ||
| 'video-call-window/renderer-ready', | ||
| 'video-call-window/request-url', | ||
| 'video-call-window/url-received', | ||
| 'video-call-window/webview-created', | ||
| 'video-call-window/webview-loading', | ||
| 'video-call-window/webview-ready', | ||
| 'video-call-window/webview-failed', | ||
| 'video-call-window/get-language', | ||
| 'video-call-window/prewarm-capturer-cache', | ||
| 'video-call-window/media-capture-changed', | ||
| 'jitsi-desktop-capturer-get-sources', | ||
| 'desktop-capturer-get-sources', | ||
| 'outlook-calendar/get-events', | ||
| 'outlook-calendar/set-exchange-url', | ||
| 'outlook-calendar/has-credentials', | ||
| 'outlook-calendar/clear-credentials', | ||
| 'outlook-calendar/set-user-token', | ||
| 'browser/open-url', | ||
| 'document-viewer/open-window', | ||
| 'document-viewer/fetch-content', | ||
| 'secondary-window/minimize', | ||
| 'secondary-window/toggle-maximize', | ||
| 'secondary-window/close', | ||
| 'secondary-window/is-maximized', | ||
| 'screen-picker/open', | ||
| 'screen-picker/source-responded', | ||
| 'screen-picker/screen-recording-is-permission-granted', | ||
| 'screen-picker/open-url', | ||
| 'telephony/get-diagnostics', | ||
| 'telephony/call-requested', | ||
| 'presence/change-requested', | ||
| 'navigate-to-route', | ||
| 'log-viewer-window/get-server-tag', | ||
| ]); | ||
|
|
||
| const originalSend = ipcRenderer.send.bind(ipcRenderer); | ||
| const originalInvoke = ipcRenderer.invoke.bind(ipcRenderer); | ||
| const originalOn = ipcRenderer.on.bind(ipcRenderer); | ||
| const originalSendSync = ipcRenderer.sendSync.bind(ipcRenderer); | ||
|
|
||
| const isAllowedChannel = (channel: string): boolean => { | ||
| if (ALLOWED_CHANNELS.has(channel)) { | ||
| return true; | ||
| } | ||
| const match = channel.match(/^([^@]+)@[\w-]+$/); | ||
| return Boolean(match && ALLOWED_CHANNELS.has(match[1])); | ||
| }; | ||
|
|
||
| ipcRenderer.send = (channel: string, ...args: unknown[]) => { | ||
| if (!isAllowedChannel(channel)) { | ||
| console.warn(`Blocked unauthorized IPC send channel: ${channel}`); | ||
| return; | ||
| } | ||
| originalSend(channel, ...sanitize(args)); | ||
| }; | ||
|
|
||
| ipcRenderer.invoke = async (channel: string, ...args: unknown[]) => { | ||
| if (!ALLOWED_CHANNELS.has(channel)) { | ||
| console.warn(`Blocked unauthorized IPC invoke channel: ${channel}`); | ||
| throw new Error('Unauthorized IPC'); | ||
| } | ||
| return originalInvoke(channel, ...sanitize(args)); | ||
| }; | ||
|
|
||
| ipcRenderer.sendSync = (channel: string, ...args: unknown[]) => { | ||
| if (!ALLOWED_CHANNELS.has(channel)) { | ||
| console.warn(`Blocked unauthorized IPC sendSync channel: ${channel}`); | ||
| return undefined; | ||
| } | ||
| return originalSendSync(channel, ...sanitize(args)); | ||
| }; | ||
|
|
||
| ipcRenderer.on = ( | ||
| channel: string, | ||
| listener: (event: Electron.IpcRendererEvent, ...args: any[]) => void | ||
| ) => { | ||
| if (!isAllowedChannel(channel)) { | ||
| console.warn(`Blocked unauthorized IPC on channel: ${channel}`); | ||
| return ipcRenderer; | ||
| } | ||
| return originalOn(channel, listener); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.