-
Couldn't load subscription status.
- Fork 3.8k
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
On Node v20, DEP0170 is active:
Type: Runtime
url.parse() accepts URLs with ports that are not numbers. This behavior might result in host name spoofing with unexpected input. These URLs will throw an error in future versions of Node.js, as the WHATWG URL API does already.
It looks like npm tries to parse dependencies like
{
"dependencies": {
"something-private": "git+ssh://[email protected]:group/project.git#commitish"
}
}with url.parse, which in turn interprets group as port number.
The NPM docs on Git URLs as Dependencies state:
Git urls are of the form:
<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
<protocol>is one ofgit,git+ssh,git+http,git+https, orgit+file.
Changing the dependency URL to
git+ssh://[email protected]:22:group/project.git#commitish
leads to Gitlab intepreting "22:group" as (non-existing) project namespace.
Expected Behavior
The warning should be addressed.
Since Node obviously seeks WHATWG URL API compatibility, there are a few options:
- Use a custom URL parser, which allows to parse all documented NPM dependency URL formats, without warnings.
- Deprecate dependency URL formats which don't follow the WHATWG API URL specification.
- Amend the WHATWG API URL with generic URL formats, such as
git+ssh, where host/port and path are separated by a colon.
Steps To Reproduce
See current behaviour above:
- reference a dependency via
git+ssh://URL - run
npm install - observe the warning
[DEP0170] DeprecationWarning: The URL git+ssh://... is invalid. Future versions of Node.js will throw an error.
Environment
- npm: 10.1.0
- Node.js: v20.8.0
- OS Name: Debian 11.7
- System Model Name: n/a
- npm config:
; "user" config from /home/dm/.npmrc
prefix = "/home/dm/.local"
python = "/usr/bin/python3"
; node bin location = /usr/bin/node
; node version = v20.8.0
; npm local prefix = [irrelevant]
; npm version = 10.1.0
; cwd = [irrelevant]
; HOME = [irrelevant]
; Run `npm config ls -l` to show all defaults.