Skip to content

NODE_PATH not recognized when cap_net_bind_service is set #22648

@Musinux

Description

@Musinux
  • Version: v10.9.0
  • Platform: Linux NZXT 4.9.0-5-rt-amd64 deps: update openssl to 1.0.1j #1 SMP PREEMPT RT Debian 4.9.65-3+deb9u2 (2018-01-04) x86_64 GNU/Linux
  • Subsystem: module require

I recently upgraded my Node.js version from v9.6.1 to v10.9.0, and the behavior related to the capability cap_net_bind_service has changed.

Up until the v9.6.1 version, i have always set the net_bind_service capability to be able to load my service on ports 80 and 443 on my development machine. It has always worked as expected.

With v10.9.0, it prevents the NODE_PATH env variable to be used to set a different require path.

Full commands to replicate the behavior (v9.6.1):

 $ cd ~/tmp/node/node-v9.6.1-linux-x64
 $ sudo cp -r bin include lib share /usr/local/
 $ sudo setcap cap_net_bind_service=+ep /usr/local/bin/node
 $ node -v
v9.6.1
 $ NODE_PATH=$PWD"/lib" node                               
> console.log(process.env.NODE_PATH)
/home/louis/tmp/node/node-v9.6.1-linux-x64/lib
undefined
> require.resolve.paths("custom")
[ '/home/louis/tmp/node/node-v9.6.1-linux-x64/repl/node_modules',
  '/home/louis/tmp/node/node-v9.6.1-linux-x64/node_modules',
  '/home/louis/tmp/node/node_modules',
  '/home/louis/tmp/node_modules',
  '/home/louis/node_modules',
  '/home/node_modules',
  '/node_modules',
  '/home/louis/tmp/node/node-v9.6.1-linux-x64/lib',
  '/home/louis/.node_modules',
  '/home/louis/.node_libraries',
  '/usr/local/lib/node',
  '/home/louis/tmp/node/node-v9.6.1-linux-x64/lib',
  '/home/louis/.node_modules',
  '/home/louis/.node_libraries',
  '/usr/local/lib/node' ]

Here, with the version v9.6.1, /home/louis/tmp/node/node-v9.6.1-linux-x64/lib is correctly set in the require paths

Now the same steps with the v10.9.0:

 $ cd ~/tmp/node/node-v10.9.0-linux-x64                    
 $ sudo cp -r bin include lib share /usr/local/            
 $ sudo setcap cap_net_bind_service=+ep /usr/local/bin/node
 $ node -v
v10.9.0
 $ NODE_PATH=$PWD"/lib" node                               
> console.log(process.env.NODE_PATH)
/home/louis/tmp/node/node-v10.9.0-linux-x64/lib
undefined
> require.resolve.paths("custom")
[ '/home/louis/tmp/node/node-v10.9.0-linux-x64/repl/node_modules',
  '/home/louis/tmp/node/node-v10.9.0-linux-x64/node_modules',
  '/home/louis/tmp/node/node_modules',
  '/home/louis/tmp/node_modules',
  '/home/louis/node_modules',
  '/home/node_modules',
  '/node_modules',
  '/usr/local/lib/node',
  '/usr/local/lib/node' ]

In this last example, you can see that /home/louis/tmp/node/node-v9.6.1-linux-x64/lib has disapeared.
However, without the setcap command, NODE_PATH works as expected with v10.9.0.

 $ sudo setcap -r /usr/local/bin/node #removes capabilities
 $ node -v                           
v10.9.0
 $ NODE_PATH=$PWD"/lib" node         
> process.env.NODE_PATH
'/home/louis/tmp/node/node-v10.9.0-linux-x64/lib'
> require.resolve.paths("custom")
[ ... (skipped)
  '/home/louis/tmp/node/node-v10.9.0-linux-x64/lib',
  ... (skipped ]

I will now use Node.js without the bind capability (port >1024), but I think this is a regression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions