Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b3eeb3b

Browse filesBrowse files
styfleaduh95
authored andcommitted
doc: provide alternative to url.parse() using WHATWG URL
PR-URL: #59736 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 1ddaab1 commit b3eeb3b
Copy full SHA for b3eeb3b

File tree

Expand file treeCollapse file tree

1 file changed

+9
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-1
lines changed
Open diff view settings
Collapse file

‎doc/api/url.md‎

Copy file name to clipboardExpand all lines: doc/api/url.md
+9-1Lines changed: 9 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,15 @@ A `URIError` is thrown if the `auth` property is present but cannot be decoded.
17141714
strings. It is prone to security issues such as [host name spoofing][]
17151715
and incorrect handling of usernames and passwords. Do not use with untrusted
17161716
input. CVEs are not issued for `url.parse()` vulnerabilities. Use the
1717-
[WHATWG URL][] API instead.
1717+
[WHATWG URL][] API instead, for example:
1718+
1719+
```js
1720+
function getURL(req) {
1721+
const proto = req.headers['x-forwarded-proto'] || 'https';
1722+
const host = req.headers['x-forwarded-host'] || req.headers.host || 'example.com';
1723+
return new URL(req.url || '/', `${proto}://${host}`);
1724+
}
1725+
```
17181726
17191727
The example above assumes well-formed headers are forwarded from a reverse
17201728
proxy to your Node.js server. If you are not using a reverse proxy, you should

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.