mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
src: handle url crash on different url formats
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: https://github.com/nodejs-private/node-private/pull/816 Refs: https://hackerone.com/reports/3546390 CVE-ID: CVE-2026-21712
This commit is contained in:
2 files changed
+15
-1
No files matched your search
+7
-1
@@ -344,7 +344,13 @@ void BindingData::Format(const FunctionCallbackInfo<Value>& args) {
|
||||
// directly want to manipulate the url components without using the respective
|
||||
// setters. therefore we are using ada::url here.
|
||||
auto out = ada::parse<ada::url>(href.ToStringView());
|
||||
CHECK(out);
|
||||
if (!out) {
|
||||
// If the href cannot be re-parsed (e.g. due to ada parser inconsistencies
|
||||
// with certain IDN hostnames), return the original href unmodified rather
|
||||
// than crashing.
|
||||
args.GetReturnValue().Set(args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hash) {
|
||||
out->hash = std::nullopt;
|
||||
|
||||
@@ -147,3 +147,11 @@ test('should format tel: prefix', { skip: !hasIntl }, () => {
|
||||
url.format(new URL('tel:123'), { unicode: true })
|
||||
);
|
||||
});
|
||||
|
||||
// Regression test: url.format should not crash on URLs that ada::url_aggregator
|
||||
// can parse but ada::url cannot (e.g. special scheme URLs with opaque paths).
|
||||
test('should not crash on URLs with invalid IDN hostnames', () => {
|
||||
const u = new URL('ws:xn-\u022B');
|
||||
// doesNotThrow
|
||||
url.format(u, { fragment: false, unicode: false, auth: false, search: false });
|
||||
});
|
||||
Reference in new issue
Block a user