Skip to content

Replace deprecated url.parse in proxy resolution - #114

Open
Josh Mouch (joshmouch) wants to merge 1 commit into
microsoft:mainfrom
joshmouch:codex/remove-url-parse-deprecation
Open

Josh Mouch (joshmouch) wants to merge 1 commit into
microsoft:mainfrom
joshmouch:codex/remove-url-parse-deprecation

Conversation

@joshmouch

Copy link
Copy Markdown

Fixes the DEP0169 warnings emitted by VS Code agent-host and extension-host fetch paths.

The proxy cache already declares scheme://host:port as its key, so this replaces the legacy parser with WHATWG URL and constructs that same cache key from protocol and host.

The regression runs the resolver under --pending-deprecation in an isolated child and fails if DEP0169 is emitted. It fails against current main at src/index.ts:307 and passes with this change.

Verification:

  • Node 22.23.2
  • TypeScript compile with repository dependencies
  • unit tests: 35 passing
  • git diff --check

@trivikr

Copy link
Copy Markdown

cc Christof Marti (@chrmarti) Dmitriy Vasyura (@dmitrivMS) Martin Aeschlimann (@aeschli) could you take a look when you get a chance?

This fixes the DEP0169 warning (url.parse() deprecation) that shows up in extension test logs whenever an extension calls the global fetch() in the extension host.

The patched fetch goes through resolveProxyURL() → useProxySettings(), which calls nodeurl.parse(url). For example, we see it in smithy-lang/smithy-vscode CI while downloading Coursier.

(node:2741) [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.

One thing that may need a follow-up before merging: WHATWG URL keeps the brackets on IPv6 hostnames (new URL('http://[::1]/').hostname === '[::1]'), while url.parse returns ::1. The localhost check in useProxySettings() compares against '::1' and '::ffff:127.0.0.1', so IPv6 loopback requests would no longer resolve to DIRECT. The same applies to noProxy matching for IPv6 hosts. Stripping the brackets from hostname and adding a test for http://[::1]/ should cover it.

@trivikr

Copy link
Copy Markdown

Some extra context on why this matters for extension authors: the warning can't be suppressed on our side.

The usual workaround is NODE_OPTIONS=--disable-warning=DEP0169, but VS Code strips NODE_OPTIONS from the extension host environment. The VS Code bundle includes an env deny-list (DEBUG, NODE_OPTIONS, VSCODE_NODE_OPTIONS, LD_PRELOAD, DYLD_INSERT_LIBRARIES) and calls delete env.NODE_OPTIONS when it spawns child processes, so setting it on the CI job doesn't help.

The in-process alternatives don't work well:

  • Wrapping process.emitWarning from the test runner runs too late. Our extension activates and calls fetch() before the test entry point loads.
  • Doing it in the extension itself (or setting process.noDeprecation) would change a process-wide global shared by every extension in the host, so we don't want to ship that.

So for any extension that calls the global fetch(), this PR is the only practical way to get rid of the warning.

@trivikr

Copy link
Copy Markdown

Josh Mouch (@joshmouch) Can you rebase this branch and resolve conflicts, so that maintainers can look at your PR?

@trivikr

Copy link
Copy Markdown

This has had conflicts since October, so I opened #129. It rebases this change onto main, keeps Josh Mouch (@joshmouch) as co-author, and keeps IPv6 hostnames without brackets so [::1] still resolves to DIRECT. If you update this PR instead, I'll close mine.

@Jason3S

Copy link
Copy Markdown

Josh Mouch (@joshmouch)

Can you fix the merge conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants