-
Notifications
You must be signed in to change notification settings - Fork 30k
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
module: check env NODE_PRELOAD for preload modules #11888
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,8 +411,38 @@ | |
|
||
// Load preload modules | ||
function preloadModules() { | ||
if (process._preload_modules) { | ||
NativeModule.require('module')._preloadModules(process._preload_modules); | ||
var allPreloads = process._preload_modules; | ||
var isSetUidRoot = false; | ||
|
||
if (process.platform !== 'win32') { | ||
isSetUidRoot = process.getuid() !== process.geteuid() || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why aren't you using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure how. Can you tell me please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look for how OPENSSL_CONF is loaded from env, in such a way that its ignored if the IDs aren't safe, much as you are manually trying to check here. |
||
process.getgid() !== process.getegid(); | ||
} | ||
|
||
if (!isSetUidRoot && process.env.NODE_PRELOAD) { | ||
const path = NativeModule.require('path'); | ||
|
||
const addPreload = (nmDir, preloads) => { | ||
const addNmDir = (m) => { | ||
return path.isAbsolute(m) ? m : path.join(nmDir, m); | ||
}; | ||
|
||
if (preloads && preloads.length > 0) { | ||
preloads = preloads.map((m) => addNmDir(m.trim())) | ||
.filter((m) => (m.length > nmDir.length && m.startsWith(nmDir))); | ||
|
||
if (preloads.length > 0) { | ||
allPreloads = (allPreloads || []).concat(preloads); | ||
} | ||
} | ||
}; | ||
|
||
const globalNm = path.join(process.argv[0], '../../lib/node_modules/'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't make any sense to disallow requiring a packages own dependencies, please remove this. Resolution should be identical to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment I am waiting for an approach that everyone can at least not put a -1 on first. If @nodejs/ctc have an approach that's acceptable, I'd implement that. |
||
addPreload(globalNm, process.env.NODE_PRELOAD.split(path.delimiter)); | ||
} | ||
|
||
if (allPreloads) { | ||
NativeModule.require('module')._preloadModules(allPreloads); | ||
} | ||
} | ||
|
||
|
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.
If this is going to happen, this var should be called
isSetUid