You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The previous documentation example for converting `request.url` to an
`URL` object was unsafe, as it could allow a server crash through
malformed URL inputs and potentially enable host header attacks.
This commit revises the example to use string concatenation over the
usage of the `baseUrl` and removes the usage of the `req.headers.host`
as the authority part of the url, mitigating both the crash and security
risks by ensuring the host part of the URL remains controlled and
predictable.
Fixes#52494
Co-authored-by: @astlouisf
Co-authored-by: @samhh
When `request.url` is `'/status?name=ryan'` and `request.headers.host` is
2893
-
`'localhost:3000'`:
2892
+
When `request.url` is `'/status?name=ryan'` and `process.env.HOST` is undefined:
2894
2893
2895
2894
```console
2896
2895
$ node
2897
-
> new URL(request.url, `http://${request.headers.host}`)
2896
+
> new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);
0 commit comments