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:
RafaelGSS committed 2026-03-24 19:46:50 -03:00
1 parent 3a04e0ff25
commit dabb2f5f0c
2 files changed
+15 -1

No files matched your search

+7 -1
View File
@@ -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;
+8
View File
@@ -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 });
});