-
-
Notifications
You must be signed in to change notification settings - Fork 480
[Tech] Enable sandboxing for ipcRenderer Processes #1783
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
[Tech] Enable sandboxing for ipcRenderer Processes #1783
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.
Thanks for this, was looking into doing something similar for a while now.
Looking into this a bit, it seems like it's also quite easy to add return type definitions to IPC functions now, which is (IMO) also something we need. But that can come gradually as people work on the system, no need to include everything here.
One very small thing, I'm not sure if just api
is the best name for the folder & property on the window
object. But then again, I can't really think of a better name right now either :^)
You've described a method of converting the Nevermind, should've taken care to read everything first before asking questionselectron-store
calls so nodeIntegration
can be turned off. I assume you've refrained from actually implementing that here since the PR's only about contextIsolation
?
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.
Those are pretty interesting changes and codewise it looks pretty good.
Although we need to change the whole app now on all platforms since these changes touch all functionalities.
can you point out the features and platforms you have already tested?
It is also important to test on both a current Heroic installation and a new one, by removing/renaming the config folders for both legendary and heroic.
I can help test but as more people test the better. :)
Testing here on Linux with my current install and what is not working so far:
|
On a clean install the app doesn't open. Somehow it is trying to find Legendary folder but since it doesn't exist it fails:
|
This is my fault and not related to this PR:
This assumes |
Awesome! And noted about the legendary/heroic config folders. I've just been testing on Windows. I've only run the unit tests and the app in dev mode. I am planning to test the builds and features more comprehensively today on Windows, mac, linux. Appreciate the help testing too! |
Yes I agree. It'd be nice to have the return types too. Agreed that they can be added gradually moving forward. I'm open to naming the folder something different. I named it that because I saw some other projects using a similar name, I'm pretty sure it doesn't conflict with window's existing properties, and it's quite simple to remember. |
Imo |
Login with Epic is not working but that is because the beta branch is not updated with the main branch so we need to updated it to get the fixes from it. |
ok, just updated the beta branch, now just update this branch against beta to get the fixes. |
Shouldn't it be |
This folder is created after login with epic, so legendary creates it. |
…, uncomment react devtools, exe optional parameter on Tools
Looks like the windows build check is throwing the same error as the last two commits to the beta branch.
Maybe the remote server was down during these tests. Doesn't seem to be related to the changes we've made unless I'm missing something. Can we re run the checks? Or should we just ignore for now |
Just ignore the builds. Some days github is more unstable than others. |
I've been testing today on Windows and Mac. I'm having a hard time in some cases trying to determine what the expected behavior should be though. I'm also still familiarizing myself with the frontend/repo in general so it's taking me a lot of time to go through every error message as well. On Windows I received the following error messages: Can't download from epic cdn (I think this is being discussed in the discord and is unrelated to the current PR)
HGL showed a "Can't get game info" error when trying to expand the game in the library while downloading it through Epic Games Launcher. React devtools is also throwing the following error when checking/unchecking some of the settings components for the first time.
The following error is sometimes thrown as well
But I'm able to navigate the Epic games store, install through EGL, and then refresh the library to see my game. The game launches fine through HGL. When I download a game from the GOG store. I don't see it show up in HGL. I'm not sure how to troubleshoot this as it seems there is only a sync option for the EGL. I've tested on Mac too and I've gotten the following error
I'm not sure when legendary is supposed to be installed on MacOS, so I'm having trouble troubleshooting this too. On Mac I'm able to see games from Epic Games Launcher, but the game that I've downloaded through EGL still shows up as "Not Installed". Clicking into the game gives
and I get a "Cannot get game info" message on the screen |
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.
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.
Gets pretty close to perfect.
I found something i don't know if you introduced it, but i could not reproduce it on beta.
If i uninstall a game it is still shown as installed on the library page till i refresh via the refresh button.
…alled games on sync regardless if online or not, additional check for is installed when rendering game cards
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.
We getting close :)
Left some comments
@BrettCleary the wine downloader still have issues but I found a solution.
Also change the api call to remove the event:
And finally on wine manager ipc_handlers use the window to send the command:
I think the only mandatory change is the first one but the others are for consistency and best practices. |
Why |
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.
Beside the one thing that flavio suggested, i would love to get rid of all
// eslint-disable-next-line @typescript-eslint/no-explicit-any
. I added some lines where i know the type.
In practice, it doesn't change anything. Was just about consistency because for the game progress we are using one way and for wine progress another way. Thats confusing because they are doing the same thing. |
The difference would be that |
Noted. latest commit addresses this. Also the useEffect will have to return the callback to remove the listener on each render and since TS throws error because not all code paths return a value, I added the ()=>void callback at the end.
|
Agreed. I would prefer to do this incrementally though especially since before this PR, there were no types in ipcRenderer/main calls |
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.
Looks good now, all bugs I could found were fixed, left a small comment but you should be able to merge whenever you like now :D
Thanks for that by the way, was a pretty good refactor ⚔️
@Nocccer approve it when you find some time since you asked for changes. ;) |
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.
LGTM. I left some comment we need to discuss and maybe fix after the merge.
This PR refactors all ipcRenderer calls into preload.ts as mentioned and begins to resolve #1772.
This allows contextIsolation to be set as true, which limits some of the api's that the renderer process can call and is an important security measure (https://www.electronjs.org/docs/latest/tutorial/context-isolation).
This refactor should also improve frontend developer productivity by clearly documenting the types and arguments when calling ipcRenderer.send, ipcRenderer.invoke, and ipcRenderer.on (now called via window.api.METHOD and defined in preload.ts). It will also clearly define the ipcRenderer calls/handlers in one place (preload.ts) whereas before these were duplicated across several frontend files in some instances and were pretty difficult to determine the types that could/should be passed.
There is also now the option to share types between frontend and backend ipc calls/handlers. Here is how it could work (documented in src/common/types.ts):
Here are the functions that type the callback from the preload.ts method
I decided to not include this in the current PR as it is quite complex and may only have marginal benefits since the types are already documented in preload.ts.
Also, the preload.ts file is built separately with es-build now (same build tool used by vite) and not bundled. This is necessary as the preload option for BrowserWindow requires an absolute path to the preload.js file.
This is an important first step towards enabling sandboxing in the renderer processes. Since it's a pretty big refactor already, allows contextIsolation to be enabled, and has other productivity benefits, I figured it would be better to go ahead and PR now.
FURTHER WORK
The next step towards enabling sandboxing will be to set nodeIntegration: false. The first issue encountered with this was that electron-store methods inside of preload.ts are synchronous but ipcRenderer calls are all async. As it is necessary to refactor these methods into the main process after setting nodeIntegration: false, this will propagate changes to a lot of frontend react components that are expecting these store method calls to be synchronous. This will be another large change, so I think it's best to PR now before beginning experimentation with that.
Use the following Checklist if you have changed something on the Backend or Frontend: