Skip to content

Commit cba66c4

Browse files
RafaelGSSjuanarbol
authored andcommitted
src: handle url crash on different url formats
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: nodejs-private/node-private#816 CVE-ID: CVE-2026-21712
1 parent 6fae244 commit cba66c4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/node_url.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,13 @@ void BindingData::Format(const FunctionCallbackInfo<Value>& args) {
344344
// directly want to manipulate the url components without using the respective
345345
// setters. therefore we are using ada::url here.
346346
auto out = ada::parse<ada::url>(href.ToStringView());
347-
CHECK(out);
347+
if (!out) {
348+
// If the href cannot be re-parsed (e.g. due to ada parser inconsistencies
349+
// with certain IDN hostnames), return the original href unmodified rather
350+
// than crashing.
351+
args.GetReturnValue().Set(args[0]);
352+
return;
353+
}
348354

349355
if (!hash) {
350356
out->hash = std::nullopt;

test/parallel/test-url-format-whatwg.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,11 @@ test('should format tel: prefix', { skip: !hasIntl }, () => {
147147
url.format(new URL('tel:123'), { unicode: true })
148148
);
149149
});
150+
151+
// Regression test: url.format should not crash on URLs that ada::url_aggregator
152+
// can parse but ada::url cannot (e.g. special scheme URLs with opaque paths).
153+
test('should not crash on URLs with invalid IDN hostnames', () => {
154+
const u = new URL('ws:xn-\u022B');
155+
// doesNotThrow
156+
url.format(u, { fragment: false, unicode: false, auth: false, search: false });
157+
});

0 commit comments

Comments
 (0)