-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
doc: deprecate url.parse() #44919
doc: deprecate url.parse() #44919
Changes from all commits
b555ee1
8c3fd95
8975b00
8829ec5
5005966
e14b5a5
0ce81e0
620a31d
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 |
---|---|---|
|
@@ -27,7 +27,7 @@ The `node:url` module provides two APIs for working with URLs: a legacy API that | |
is Node.js specific, and a newer API that implements the same | ||
[WHATWG URL Standard][] used by web browsers. | ||
|
||
A comparison between the WHATWG and Legacy APIs is provided below. Above the URL | ||
A comparison between the WHATWG and legacy APIs is provided below. Above the URL | ||
`'https://user:[email protected]:8080/p/a/t/h?query=string#hash'`, properties | ||
of an object returned by the legacy `url.parse()` are shown. Below it are | ||
properties of a WHATWG `URL` object. | ||
|
@@ -63,7 +63,7 @@ const myURL = | |
new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash'); | ||
``` | ||
|
||
Parsing the URL string using the Legacy API: | ||
Parsing the URL string using the legacy API: | ||
|
||
```mjs | ||
import url from 'node:url'; | ||
|
@@ -1521,6 +1521,9 @@ The formatting process operates as follows: | |
<!-- YAML | ||
added: v0.1.25 | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/44919 | ||
description: Documentation-only deprecation. | ||
- version: | ||
- v15.13.0 | ||
- v14.17.0 | ||
|
@@ -1540,7 +1543,7 @@ changes: | |
when no query string is present. | ||
--> | ||
|
||
> Stability: 3 - Legacy: Use the WHATWG URL API instead. | ||
> Stability: 0 - Deprecated: Use the WHATWG URL API instead. | ||
|
||
* `urlString` {string} The URL string to parse. | ||
* `parseQueryString` {boolean} If `true`, the `query` property will always | ||
|
@@ -1562,16 +1565,9 @@ A `URIError` is thrown if the `auth` property is present but cannot be decoded. | |
|
||
`url.parse()` uses a lenient, non-standard algorithm for parsing URL | ||
strings. It is prone to security issues such as [host name spoofing][] | ||
and incorrect handling of usernames and passwords. | ||
|
||
`url.parse()` is an exception to most of the legacy APIs. Despite its security | ||
concerns, it is legacy and not deprecated because it is: | ||
|
||
* Faster than the alternative WHATWG `URL` parser. | ||
* Easier to use with regards to relative URLs than the alternative WHATWG `URL` API. | ||
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. Do we have a solution for relative URLs using WHATWG? 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. If you know the base URL, then yes. If not, you have to fake it, perhaps with an identifiably bogus base URL. In that second case, it's a solution, but perhaps not a particularly elegant one. My opinion only, but a lot of the current problems with Ref: #12682 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. Thanks @Trott My worry is that marking I remember when this was "deprecated" the first time, it confused a lot of people and then it was reverted to say "legacy" which I think was the right decision. Or maybe the solution here is to document how to parse relative urls, such as 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. There's whatwg/url#421 that would fit the use-case, unfortunately the proposal look rather stalled. 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’ve seen that one too. It has a label “needs implementer interest”. Does that need to be a browser or can we say Node.js is interested in implementing? 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. The proposal comes from Node.js, I think it's implied that Node.js is interested, I think we need other implementers as well. 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. @aduh95 The discussion around whatwg/url#421 more or less has been continued in whatwg/url#531. 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. @styfle I have spent a lot of effort to find a solution for relative URLs that agrees with the WHATWG Standard, see e.g. this comment and also this URL Specification and this library. This was indeed far from trivial due to design decisions made in the WHATWG standard. I have an idea for a simple API ready, but I stopped working on it for a while. In part because it is unlikely that the WHATWG standard can incrementally add support for relative URLs. This leads to an understandable resistance, which nonetheless is frustrating to me and something that I don’t yet know how to solve. The other reason is simply being preoccupied with other work at the moment. Suggestions and ideas are appreciated! 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. Looks interesting. I think WHATWG is probably the wrong place to standardize this since browsers aren't interested. I think WinterCG is a better choice for standardization of relative url parsing since it is focused on server-side JS. 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. Personally I think that marking this API as deprecated should've been gated on a suitable replacement being made available, and perhaps that would've introduced some incentive to come to a consensus on what that replacement should look like. Relative URLs are a thing, and we need a suitable API to replace this one. |
||
* Widely relied upon within the npm ecosystem. | ||
|
||
Use with caution. | ||
and incorrect handling of usernames and passwords. Do not use with untrusted | ||
input. CVEs are not issued for `url.parse()` vulnerabilities. Use the | ||
[WHATWG URL][] API instead. | ||
|
||
### `url.resolve(from, to)` | ||
|
||
|
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.
Do we know which one is faster?
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.
I suspect @anonrig might be able to answer that. Generally, I'd say
url.parse()
is usually faster, but not necessarily by a whole lot in the typical use cases. And it is more susceptible to things like host spoofing than WHATWGURL
. But anything @anonrig says to the contrary should be treated as the more informed opinion that it is.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.
Url.parse is faster but not spec compliant.
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.
When parsing a relative URL, then there is no possibility of host spoofing or username/password issues, right?
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.
I can’t answer that question with 100% uncertainity, and I think nobody can.
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.
Let me rephrase the question:
Has anyone reported bugs or vulnerabilities for relative urls as inputs to url.parse()?
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.
url.parse()
used to treat the\bhttp://example.com/\b
as a hostless URL. WHATWG URL strips leading and trailing backspaces and treats it as a fully-qualified URL. So that's an example whereurl.parse()
mishandling a URL and treating it like a hostless URL could lead to problems. (This issue has been fixed.)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.
I see. I'm thinking more along the lines of URLs that start with
/
, like req.urlThis is the case for which
url.parse()
andurl.format()
is useful, and theres not a good solution today usingnew URL()
.