node icon indicating copy to clipboard operation
node copied to clipboard

url: runtime deprecate url.parse

Open anonrig opened this issue 1 year ago β€’ 14 comments

We documentation-only deprecated URL.parse on v18, almost 2 years ago. Without a runtime deprecation people will continue to use it and be exposed to security flaws. This is a nudge on the direction for a possible EOL in 3-5 years?

cc @nodejs/tsc

anonrig avatar Sep 19 '24 19:09 anonrig

Review requested:

  • [ ] @nodejs/url

nodejs-github-bot avatar Sep 19 '24 19:09 nodejs-github-bot

I don't think this is used for new code and there are a lot of unmaintained but perfectly working and safe modules that will be affected by this for no good reason.

lpinca avatar Sep 19 '24 19:09 lpinca

safe modules that will be affected by this for no good reason.

Even in the deprecation note says that it's not recommended and safe to use it. How can it be safe? url.parse() can result in unwanted/unexpected outputs.

anonrig avatar Sep 19 '24 19:09 anonrig

It is perfectly safe when used on trusted and well defined inputs. For example, there is nothing wrong with url.parse() when used to parse URLs returned by a trusted server like the URLs in the Location and Link headers.

lpinca avatar Sep 19 '24 19:09 lpinca

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.41%. Comparing base (7ae193d) to head (76c9793). Report is 13 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #55017    +/-   ##
========================================
  Coverage   88.40%   88.41%            
========================================
  Files         653      653            
  Lines      187600   187484   -116     
  Branches    36117    36091    -26     
========================================
- Hits       165854   165755    -99     
+ Misses      14974    14967     -7     
+ Partials     6772     6762    -10     
Files with missing lines Coverage Ξ”
lib/url.js 100.00% <100.00%> (ΓΈ)

... and 42 files with indirect coverage changes

codecov[bot] avatar Sep 19 '24 21:09 codecov[bot]

perfectly working and safe modules that will be affected by this for no good reason.

I am neutral here, but can you elaborate what you mean by 'affected'?

lemire avatar Sep 19 '24 23:09 lemire

For example, the mongodb module uses url.parse. It means that potentially all Node.js applications using it will print a warning, annoying many users who are not the ones that should care about it.

targos avatar Sep 20 '24 05:09 targos

I think we should be doing what we have done for Buffer, emitting a warning only if the code is not inside node_modules.

mcollina avatar Sep 20 '24 13:09 mcollina

I agree with Matteo here. This will be super disruptive. Let's limit the warning only to modules not inside node_modules.

jasnell avatar Sep 21 '24 16:09 jasnell

I think we should be doing what we have done for Buffer, emitting a warning only if the code is not inside node_modules.

I updated the code as recommended. Thank you for the reviews!

anonrig avatar Sep 21 '24 19:09 anonrig

Looks like there are some tests that need updating

jasnell avatar Sep 21 '24 20:09 jasnell

gyp ERR! configure error 
gyp ERR! stack TypeError: isInsideNodeModules is not a function
gyp ERR! stack at urlParse (node:url:126:27)
gyp ERR! stack at Object.urlResolve [as resolve] (node:url:717:10)

targos avatar Oct 18 '24 07:10 targos

Related test failure:

=== release test-url-parse-invalid-input ===
Path: parallel/test-url-parse-invalid-input
Error: --- stderr ---
(node:174506) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
(Use `node --trace-deprecation ...` to show where the warning was created)
node:assert:90
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
+ actual - expected

+ '`url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.'
- 'The URL https://evil.com:.example.com/ is invalid. Future versions of Node.js will throw an error.'

    at Object.<anonymous> (/home/runner/work/node/node/test/common/index.js:684:14)
    at Object.DeprecationWarning (/home/runner/work/node/node/test/common/index.js:491:15)
    at process.<anonymous> (/home/runner/work/node/node/test/common/index.js:708:33)
    at process.emit (node:events:519:35)
    at doEmitWarning (node:internal/process/warning:85:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:89:21) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: '`url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.',
  expected: 'The URL https://evil.com:.example.com/ is invalid. Future versions of Node.js will throw an error.',
  operator: 'strictEqual'
}

Node.js v24.0.0-pre
Command: out/Release/node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./tools/github_reporter/index.js --test-reporter-destination=stdout /home/runner/work/node/node/test/parallel/test-url-parse-invalid-input.js

===
=== 1 tests failed
===

aduh95 avatar Oct 19 '24 11:10 aduh95

CI: https://ci.nodejs.org/job/node-test-pull-request/63202/

nodejs-github-bot avatar Oct 19 '24 16:10 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/63220/

nodejs-github-bot avatar Oct 20 '24 16:10 nodejs-github-bot

Commit Queue failed
- Loading data for nodejs/node/pull/55017
βœ”  Done loading data for nodejs/node/pull/55017
----------------------------------- PR info ------------------------------------
Title      url: runtime deprecate url.parse (#55017)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     anonrig:runtime-deprecate-url-parse -> nodejs:main
Labels     url, semver-major, deprecations, needs-ci
Commits    2
 - url: runtime deprecate url.parse
 - fix test
Committers 1
 - Yagiz Nizipli <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/55017
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: James M Snell <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/55017
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: James M Snell <[email protected]>
--------------------------------------------------------------------------------
   β„Ή  This PR was created on Thu, 19 Sep 2024 19:40:10 GMT
   βœ”  Approvals: 3
   βœ”  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/55017#pullrequestreview-2378667703
   βœ”  - Marco Ippolito (@marco-ippolito) (TSC): https://github.com/nodejs/node/pull/55017#pullrequestreview-2379246574
   βœ”  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/55017#pullrequestreview-2380649916
   βœ”  Last GitHub CI successful
   β„Ή  Last Full PR CI on 2024-10-20T16:41:32Z: https://ci.nodejs.org/job/node-test-pull-request/63220/
- Querying data for job/node-test-pull-request/63220/
   βœ”  Last Jenkins CI successful
--------------------------------------------------------------------------------
   βœ”  No git cherry-pick in progress
   βœ”  No git am in progress
   βœ”  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
βœ”  origin/main is now up-to-date
- Downloading patch for 55017
From https://github.com/nodejs/node
 * branch                  refs/pull/55017/merge -> FETCH_HEAD
βœ”  Fetched commits as c124cfb4facb..76c97932e55b
--------------------------------------------------------------------------------
[main dff1620ae5] url: runtime deprecate url.parse
 Author: Yagiz Nizipli <[email protected]>
 Date: Thu Sep 19 15:38:25 2024 -0400
 3 files changed, 8 insertions(+), 4 deletions(-)
[main fb8ddd6cdc] fix test
 Author: Yagiz Nizipli <[email protected]>
 Date: Sat Oct 19 12:54:22 2024 -0400
 1 file changed, 5 insertions(+), 5 deletions(-)
   βœ”  Patches applied
There are 2 commits in the PR. Attempting autorebase.
Rebasing (2/4)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
url: runtime deprecate url.parse

PR-URL: https://github.com/nodejs/node/pull/55017 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: James M Snell <[email protected]>

[detached HEAD dc82eebff2] url: runtime deprecate url.parse Author: Yagiz Nizipli <[email protected]> Date: Thu Sep 19 15:38:25 2024 -0400 3 files changed, 8 insertions(+), 4 deletions(-) Rebasing (3/4) Rebasing (4/4) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- fix test

PR-URL: https://github.com/nodejs/node/pull/55017 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: James M Snell <[email protected]>

[detached HEAD d8affe05b8] fix test Author: Yagiz Nizipli <[email protected]> Date: Sat Oct 19 12:54:22 2024 -0400 1 file changed, 5 insertions(+), 5 deletions(-) Successfully rebased and updated refs/heads/main.

β„Ή Add commit-queue-squash label to land the PR as one commit, or commit-queue-rebase to land as separate commits.

https://github.com/nodejs/node/actions/runs/11428689062

nodejs-github-bot avatar Oct 20 '24 18:10 nodejs-github-bot

Landed in 11fbdd8c9d7820f4812895bbaecad75bb80b2c55

nodejs-github-bot avatar Oct 20 '24 19:10 nodejs-github-bot

Nit: it's not immediately obvious what this API should be replaced with. Personally, the "WHATWG URL API" wasn't explicit enough, and I had to lookup this PR and search on google to understand that the recommendation is simple new URL() instead of url.parse().

Maybe it could be nice to mention URL.parse() or new URL() in the message, and/or link to this page? https://nodejs.org/dist/latest/docs/api/url.html#the-whatwg-url-api

I think it would also save time to the community if some common migration cases were addressed. For example url.parse("/xyz").pathname works, but we need URL.parse("/xyz","https://example.com").pathname with the WHATWG API

slorber avatar May 09 '25 15:05 slorber

@slorber Agreed, this has been really painful for years with no clear path forward.

Here was my workaround from 2020 and that still seems to be the best solution:

  • https://github.com/nodejs/web-server-frameworks/issues/71#issuecomment-702903372

Thoughts on documenting that?

styfle avatar May 13 '25 21:05 styfle