-
Notifications
You must be signed in to change notification settings - Fork 109
Need an advice for building app with communication between renderer and main #393
Comments
This needs to be done very carefully. Annoyingly I am looking to make the sandboxing between the two components thicker not thinner. However, there's no reason why you can't share a socket |
I want it to also work on windows, and, my assumption is that there are no unix sockets there. Am I wrong? |
@posix4e wait a second, can I get socket on a renderer side in a preload script in muon, with full sandbox on? |
@posix4e you are talking about named pipes on Windows, aren't you? I can channel all communication through this. Can I get a socket on a renderer side in a preload? Muon docs say that node is eradicated from renderer. How can I get the socket? |
Ahh I was a bit confused. So you are trying to do this in javascript or change the c++? |
@posix4e yes, I prefer to do this in javascript land, without a need to custom compile muon. I'll introduce context. Its for 3NWeb platform effort. Client side core, currently an Electron, does crypto for messaging, storage, identity. We do want to provide explicitly defined capabilities to an app, but we want to contain an app. Firstly, to guard against our own bugs. Secondly, apps Capabilities object is sort of a proxy to core's functionality, that an app is allowed to use. All of communication to animate such proxy, can be passed via socket. In Electron, we had a version that used electron's ipc, but its JSON-ification is the only nuisance, when passing Muon's story sounds like we can get true sandboxing, by jumping from Electron to Muon. To make this jump, a communication channel is needed between main and renderer. But how can it be arranged on muon, so that it drives |
If you use |
@shadowcodex thank you for the tip |
Do you have more information about this please? Is chrome.ipcRenderer exposed to the whole renderer process or is it restricted to the preload environment? If it's exposed to the whole of the renderer than an attacker can still leverage it to do damage, a whitelist on the channels should be enforced. I was looking into muon to ditch electron, because I've been experiencing some odd behaviour: The repository that has all my research is: |
A quick thought I just had, maybe it is possible to have the preload environment copy/reference the chrome.ipcRenderer to a local object of the filter, and then override chrome.ipcRenderer. The filter then attaches to the window and if I'm lucky, everything works. |
@kewde your code is good, if javascript closure can't be busted in a meaning mentioned/discussed here. If it were 100% bullet proof, electron would've been fine, I guess. @kewde we must do this kind of "squeaking to get needed oil". Well deserved rantEvery single time @diracdeltas sends on twitter a reminder that electron's security story isn't good, we come here, to muon place. And again, we see no actionable docs and no examples, of how we can use muon with some communication between main and renderer (compartmentalization of an app's sections), i.e. not just for displaying web pages (brave's specific use case). |
It's restricted to extension contexts, such as If you're in a privileged non-webview renderer context like the Electron window context, use electron.ipcRenderer instead. Then to receive these messages these messages in the main process, use it's often easiest to just look at the source code in brave/browser-laptop |
@diracdeltas does it mean, that
|
@diracdeltas I know I'm probably asking for a lot, but would it be possible to extend this to the preload context? Ideally, it is possible to have a completely normal and sandboxed environment, with one addition: ipcRenderer exposed with a whitefilter forced by the browser/main process. @3n-mb |
Muon supports the majority of Chrome extension APIs and has added some extra ones like chrome.ipcRenderer. So instead of using preload scripts you can use content scripts, same as for Chrome extensions: https://developer.chrome.com/extensions/content_scripts. I don't know if Electron's preload scripts are still supported but I think most of the functionality should be doable via content scripts. extension contexts are privileged - they cannot be modified from the regular page context. chrome.ipcRenderer is the communication channel to other processes. |
@kewde I think that muon folks already have a know-how that is why I am bugging them. So, @diracdeltas and folks are the ones to ping with this offer. |
Ahh, this is interesting.
I will work on implementing this in electron-sandbox once I find enough time (and courage). |
1)
If I want security, should word can be must, in muon? 2)
Are you talking about muon? ... guys, do you have inner-team communication? 3)
This is talking business. And this must be in docs. And, ... can you kill electron's docs, as misleading docs are worse than no-docs. |
On a note, my offer for exposing an IPC to the renderer still stands by the way.
Note: I made up ipcRendererWhitelist (in before I confuse a stranger). and then an exposed electron.ipcRenderer in the renderer process. Also, interesting: |
@kewde As for Your extension organizes the whitelist by virtue of giving to renderer particular objects, via shared DOM. |
@3n-mb Extensions provide the ability of sandboxed files/frames which is what we'll want to use.
I'm not sure if the sandboxed file/frame can communicate with the extension directly, or if it's forced to go through content scripts. There's a lot of figuring out to do, but at least we have a direction. |
to communicate between extensions and background pages you should use the chrome api https://developer.chrome.com/extensions/runtime#method-sendMessage |
@3n-mb @kewde check out the documentation I wrote in #444. It goes over how to closely mimic preload scripts using content scripts. Communication channels could look something like this
If you don't need to mutate global |
First, after reading this doc, I have following questions:
In my particular use case, I want the following (using ASCII graphics):
The best IPC in a web world is that to web worker, because it allows to pass byte array without mangling it (why stick json-ification everywhere?). Can there be an example of how to pass byte arrays between main and extension with minimal interference? |
@3n-mb If you can't use IPCs for byte arrays, the next best idea I can think of is a local WebSocket server initialized from the main process. Then create a client in the extension script so you send binary data between the two. |
@samuelmaddock |
Also, if you load an extension using session.defaultSession.extensions.load(extPath, manifest, 'component'); There was some talk about documenting that in #417 on the Discord #developers-muon channel. |
@samuelmaddock |
@samuelmaddock |
@samuelmaddock |
Thanks for that descriptive guide, there were some things I didn't know before. Is it an active community on the #developers-muon? I don't really like Discord tbh. |
I want to put for the record, that question 2: "Is it possible to pass byte arrays via ipc without being JSON-ified?" isn't applicable for current code. It used to be the case at least for June 2016 (just date-checked my repos). Today Uint8Arrays are not JSON-ified in Electron, even if they sit inside of an object. And the same code is present in muon (e.g.). |
What is the best way for communication between renderer and main? Please advise.
contents.executeJavaScript(...)
is used. For actions, initiated on renderer side, custom protocol is used. Will these work in muon?Thank you, in advance.
The text was updated successfully, but these errors were encountered: