Skip to content

Commit 50b8968

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 d82d107 commit 50b8968

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/node_url.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,13 @@ void BindingData::Format(const FunctionCallbackInfo<Value>& args) {
319319
// directly want to manipulate the url components without using the respective
320320
// setters. therefore we are using ada::url here.
321321
auto out = ada::parse<ada::url>(href.ToStringView());
322-
CHECK(out);
322+
if (!out) {
323+
// If the href cannot be re-parsed (e.g. due to ada parser inconsistencies
324+
// with certain IDN hostnames), return the original href unmodified rather
325+
// than crashing.
326+
args.GetReturnValue().Set(args[0]);
327+
return;
328+
}
323329

324330
if (!hash) {
325331
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)