8000 [trustedTypes]: Mark output from @html as untrusted · sveltejs/svelte@08c56ee · GitHub
[go: up one dir, main page]

Skip to content

Commit 08c56ee

Browse files
[trustedTypes]: Mark output from @html as untrusted
1 parent b3ba3c7 commit 08c56ee

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/svelte/src/internal/client/dom/blocks/html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function html(node, get_value, svg = false, mathml = false, skip_warning
9797
// Don't use create_fragment_with_script_from_html here because that would mean script tags are executed.
9898
// @html is basically `.innerHTML = ...` and that doesn't execute scripts either due to security reasons.
9999
/** @type {DocumentFragment | Element} */
100-
var node = create_fragment_from_html(html);
100+
var node = create_fragment_from_html(html, /*untrusted=*/true);
101101

102102
if (svg || mathml) {
103103
node = /** @type {Element} */ (get_first_child(node));

packages/svelte/src/internal/client/dom/reconciler.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ function create_trusted_html(html) {
1515
return /** @type {string} */ (policy?.createHTML(html) ?? html);
1616
}
1717

18-
/** @param {string} html */
19-
export function create_fragment_from_html(html) {
18+
/**
19+
* @param {string} html
20+
* @param {boolean} untrusted
21+
*/
22+
export function create_fragment_from_html(html, untrusted = false) {
2023
var elem = document.createElement('template');
21-
elem.innerHTML = create_trusted_html(html.replaceAll('<!>', '<!---->')); // XHTML compliance
24+
html = html.replaceAll('<!>', '<!---->'); // XHTML compliance
25+
elem.innerHTML = untrusted ? html : create_trusted_html(html);
2226
return elem.content;
2327
}

0 commit comments

Comments
 (0)
0