-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle invalid chars in host header #3923
Conversation
CHANGELOG.asciidoc
Outdated
@@ -46,6 +46,8 @@ See the <<upgrade-to-v4>> guide. | |||
[float] | |||
===== Bug fixes | |||
|
|||
* Fix path resolution for requests that contain invalid characters in its |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added to a new ==== Unreleased
section. See template for the new section at the top of the CHANGELOG file.
const req = createRequest( | ||
'https://test.com/foo/bar?query=value#hash', | ||
// eslint-disable-next-line prettier/prettier, no-useless-escape | ||
'invalid\host\name', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that actually throw in the try/catch?
> new URL('http://invalid\\host\\name')
URL {
href: 'http://invalid/host/name',
origin: 'http://invalid',
protocol: 'http:',
username: '',
password: '',
host: 'invalid',
hostname: 'invalid',
port: '',
pathname: '/host/name',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
> new URL('http://invalid\host\name')
URL {
href: 'http://invalidhostame/',
origin: 'http://invalidhostame',
protocol: 'http:',
username: '',
password: '',
host: 'invalidhostame',
hostname: 'invalidhostame',
port: '',
pathname: '/',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
This works, er fails :)
> new URL('http://bad[hostname')
Uncaught TypeError [ERR_INVALID_URL]: Invalid URL
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:637:13) {
input: 'http://bad[hostname',
code: 'ERR_INVALID_URL'
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that actually throw in the try/catch?
I think the URL contained the char [
when I tried in the REPL. My bad
Host header may contain invalid characters making the agent throw an exception and stoping the app. Agent should not throw and let the app deal with the wrong requerst.
Closes: #3874
Checklist