Skip to content
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

preload.ts withPrototype only works on enumerable properties (possibly electron 29.0.0-alpha7 related) #30

Closed
sparecycles opened this issue Jan 7, 2024 · 1 comment · Fixed by #32

Comments

@sparecycles
Copy link

The example process for exposing the ipcRenderer does not handle non-enumerable properties, leading to window.ipcRenderer.invoke being undefined outside of preload.ts.

The problem is the use of Object.entries to determine properties to expose here

const protos = Object.getPrototypeOf(obj)
for (const [key, value] of Object.entries(protos)) {
if (Object.prototype.hasOwnProperty.call(obj, key)) continue

I suggest replacing Object.entries with Object.getOwnPropertyNames to address this.

  const protos = Object.getPrototypeOf(obj)

  for (const key of Object.getOwnPropertyNames(protos)) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) continue
    const value = protos[key];

Although, arguably, the base code shouldn't be exposing the ipcRenderer like this, as per the security considerations note in
https://www.electronjs.org/docs/latest/tutorial/ipc

@caoxiemeihao
Copy link
Member

Although, arguably, the base code shouldn't be exposing the ipcRenderer like this, as per the security considerations note in
https://www.electronjs.org/docs/latest/tutorial/ipc

Yeah. This code snippets seems a bit hack and not safe enough. 👍

@caoxiemeihao caoxiemeihao linked a pull request Mar 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants