Skip to content

Commit f4bdf9b

Browse files
Dansatchaduh95
authored andcommitted
url: validate href setter receiver first
Validate the URL receiver before converting the assigned href value. Fixes: #67344 Signed-off-by: dansatch <dansatch98@gmail.com> PR-URL: #67350 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent 399228b commit f4bdf9b

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎lib/internal/url.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,9 @@ class URL {
10221022
}
10231023

10241024
set href(value) {
1025+
const context = this.#context;
10251026
value = `${value}`;
1026-
const href = bindingUrl.update(this.#context.href, updateActions.kHref, value);
1027+
const href = bindingUrl.update(context.href, updateActions.kHref, value);
10271028
if (!href) { throw new ERR_INVALID_URL(value); }
10281029
this.#updateContext(href, true);
10291030
}

‎test/parallel/test-whatwg-url-custom-href-side-effect.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@ assert.throws(() => {
1313
});
1414

1515
assert.deepStrictEqual(url, ref);
16+
17+
const setHref = Object.getOwnPropertyDescriptor(URL.prototype, 'href').set;
18+
let calls = 0;
19+
20+
assert.throws(() => {
21+
setHref.call({}, {
22+
toString() {
23+
calls++;
24+
return 'https://example.com/';
25+
},
26+
});
27+
}, {
28+
name: 'TypeError',
29+
});
30+
31+
assert.strictEqual(calls, 0);

0 commit comments

Comments
 (0)