-
Notifications
You must be signed in to change notification settings - Fork 25
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
fix: Enable context isolation #815
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to takle the context isolation! Looks good to me and works.
I added an idea on how to refactor the enums for the IpcChannels.
src/shared/ipc-channels.ts
Outdated
@@ -21,3 +22,30 @@ export enum IpcChannel { | |||
ShowProjectStatisticsPopup = 'show-project-statistics-pop-up', | |||
SetBaseURLForRoot = 'set-base-url-for-root', | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the channels I'd suggest to split the enum containing all channels into two
- frontend channels
- other channels
This could look like (maybe naming might be improved):
export enum IpcChannel {
ExportFile = 'export-file',
OpenFile = 'open-file',
OpenLink = 'open-link',
SaveFile = 'save-file',
SendErrorInformation = 'send-error-information',
}
export enum AllowedFrontendChannels {
ExportFileRequest = 'export-file-request',
FileLoaded = 'file-loaded',
Logging = 'logging',
ResetLoadedFile = 'reset-loaded-file',
RestoreFrontend = 'restore-frontend',
SaveFileRequest = 'save-file-request',
ToggleHighlightForCriticalSignals = 'toggle-highlight-for-critical-signals',
ShowSearchPopup = 'show-search-pop-up',
ShowProjectMetadataPopup = 'show-project-metadata-pop-up',
ShowProjectStatisticsPopup = 'show-project-statistics-pop-up',
SetBaseURLForRoot = 'set-base-url-for-root',
}
Then the checks in the backend
if (allowedFrontendChannels.includes(channel)) {
could read
if (Object.values(AllowedFrontendChannels).includes(channel)) {
and the constant
export const allowedFrontendChannels
would not be required.
This would avoid to add new channels to two enums in case of "allowed for frontend" and to the constant as well. Further, it would make the distinction between the two enums more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea I changed it according to your suggestion.
319c82c
to
6df7e70
Compare
It is discouraged to disable context isolation and expose ipcRendeder to the main window as it allows access from the frontend to an extremly powerful API. Instead it is recommended to use a contextBridge and expose only subset of APIs to the frontend. Signed-off-by: Nico Carl <nicocarl@protonmail.com>
6df7e70
to
b40521d
Compare
Summary of changes
ipcRenderer
ipcRenderer
API a subset of functions is exposed.invoke
is called an API is defined, which describes the actual action, e.g.openLink
.on
and.removeListener
) the respective part of the API is exposed but an allow list of channels is applied in the backend before passing anything throughContext and reason for change
Deactivating context isolation and exposing
ipcRenderer
globally is discouraged. An attacker could access it from the frontend withwindow.ipcRenderer
and would have a rather powerful API. Instead it is recommended to use a preload script where a subset of APIs is exposed.Details can be found here.
How can the changes be tested
ipcRenderer
are working (saving files, opening links, ...)