Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/util/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ const cp = require('child_process');

// try to build up the complete path to node-gyp
/* priority:
- node-gyp on ENV:NODEJS_MOBILE_GYP
- node-gyp on ENV:npm_config_node_gyp (https://github.com/npm/npm/pull/4887)
- node-gyp on NODE_PATH
- node-gyp inside npm on NODE_PATH (ignore on iojs)
- node-gyp inside npm beside node exe
*/
function which_node_gyp() {
let node_gyp_bin;
if (process.env.NODEJS_MOBILE_GYP) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to understand... Does this enable me to set an environment variable that switches node-gyp to be any executable I choose? Would that be a vast attack vector?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question 🤔
I suppose in theory yes, but if you check the code for the whole function, you get this code right after my addition:

  if (process.env.npm_config_node_gyp) {
    try {
      node_gyp_bin = process.env.npm_config_node_gyp;
      if (existsSync(node_gyp_bin)) {
        return node_gyp_bin;
      }
    } catch (err) {
      // do nothing
    }
  }

This addition follows the pattern that exists already in the code, just with a different environment variable, which is what is used in Node.js mobile.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// nodejs-mobile was using npm_config_node_gyp, but that's currently being overwritten by npm 7+
try {
node_gyp_bin = process.env.NODEJS_MOBILE_GYP;
if (existsSync(node_gyp_bin)) {
return node_gyp_bin;
}
} catch (err) {
// do nothing
}
}
if (process.env.npm_config_node_gyp) {
try {
node_gyp_bin = process.env.npm_config_node_gyp;
Expand Down