File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -1714,7 +1714,15 @@ A `URIError` is thrown if the `auth` property is present but cannot be decoded.
17141714strings . It is prone to security issues such as [host name spoofing][]
17151715and incorrect handling of usernames and passwords . Do not use with untrusted
17161716input . 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
17191727The example above assumes well-formed headers are forwarded from a reverse
17201728proxy to your Node.js server. If you are not using a reverse proxy, you should
You can’t perform that action at this time.
0 commit comments