-
Notifications
You must be signed in to change notification settings - Fork 16.9k
feat: add app.setNodePreload API #41165
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
Conversation
623e671 to
2abd893
Compare
|
/cc @bpasero |
2abd893 to
43283f9
Compare
|
Note that this PR includes an update to the |
e200621 to
19b618f
Compare
deepak1556
left a comment
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 on the implementation. Thank you!
Still needs API review.
|
The failing WoA test is from newly added one |
19b618f to
a300730
Compare
a300730 to
2495207
Compare
|
API LGTM |
nornagon
left a comment
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.
It's not clear to me how this approach protects against e.g. prototype pollution. What is this trying to prevent?
| const Module = require('node:module') | ||
| const originalMethod = Module._nodeModulePaths | ||
| exports.onBuiltinModulesPatched = () => { | ||
| Module._nodeModulePaths = (...args) => { | ||
| originalMethod(...args) | ||
| } | ||
| } |
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.
Can this be ESM?
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.
No, the lib/node/init.ts is loaded by Electron synchronously, supporting ESM implies supporting async/await in exports, which is not how Electron's initialization works.
4c43d9b to
b9377a4
Compare
In VS Code this will be used for 2 things:
Without this feature they have to patch Electron to implement the behaviors, because there is no way to inject scripts to workers or child processes. I don't think they mean to prevent malicious extensions code, this is more about setting up an environment for extensions. @deepak1556 should know more about the security part. |
|
Yes both the mentioned features are not protection against untrusted code executed in the process but rather against external actors, both the described features in VS Code are specific to Windows
Both the changes are additional checks on top of what Electron/Node.js provides, so the preload API seems a better alternative to maintain the changes at the application layer rather than maintaining them as patch in the custom fork of the runtime. |
jkleinsc
left a comment
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.
API LGTM
Description of Change
For certain apps they want stricter security checks than the default settings provided by Electron. For example in VS Code, they restrict module search paths in certain locations, and forbids file operations into UNC locations.
The
app.setNodePreloadAPI provides them a way to apply the restrictions reliably without patching Electron.Checklist
npm testpassesRelease Notes
Notes: Add
app.setNodePreloadAPI.