Deluze / electron-vue-template

Simple Vue3 + Electron starter template in TypeScript, including ViteJS and Electron Builder
MIT License
534 stars 104 forks source link

Changed renderer -> main communication example #38

Closed BmElectro closed 1 year ago

BmElectro commented 1 year ago

Changed the basic included example to satisfy security recommedations by Electron Team in:

  1. https://www.electronjs.org/docs/latest/tutorial/context-isolation
  2. https://www.electronjs.org/docs/latest/tutorial/ipc

Mainly not exposing ipcRenderer.send as it is a security risk.

Deluze commented 1 year ago

Thanks for taking your time for this PR @BmElectro! I agree, we should ship it with a secure example.

Though exposing ipcRenderer.send is not safe, with the current setup we can still pass in an arbitrary channel (1st argument), something the docs advise against. So to adhere to the docs, the channel argument should be hardcoded in the preload. The message argument can stay.

Besides that, looks good and I'd be happy to merge this PR.

BmElectro commented 1 year ago

Agreed @Deluze, the open channel argument can be exploited, hardcoding it is better and simpler since this is just an example anyway. I commited the hardcoded version. Also, you are welcome! Felt I gotta contribute something here since this template is a massive timesaver.

Deluze commented 1 year ago

Awesome! Thanks for your contribution. Glad this template is of any use :)