fix PW-001: Incorrect Hostname Parsing in pw::URLInfo::parse Leads to Denial of Service
#2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
pw::URLInfo::parsefunction incorrectly parses URLs that contain a query string or fragment but lack a path component (e.g.,https://example.com?q=1). The logic first searches for a path separator (/) to delimit the host from the path. If no/is found, it incorrectly assumes the entire remainder of the URL string is the host. This results in the query string and/or fragment being included as part of the host member of theURLInfoobject.When this malformed
URLInfoobject is used by client functions likepw::fetch, thehostname()method returns an invalid hostname (e.g.,"example.com?q=1"). This value is then passed topn::getaddrinfofor DNS resolution, which will almost certainly fail. This can be exploited by a malicious server that issues a redirect (3xx) to a specially crafted URL, causing the Polyweb client to fail its next request and effectively creating a denial of service for the client application.The fix involves rewriting the parsing logic to correctly identify the end of the URL's authority section (which contains the host) by looking for the first occurrence of a path (
/), query (?), or fragment (#) delimiter. This ensures the host is extracted correctly, and the subsequent parsing of the path and query parameters proceeds from the correct position in the URL string.