Skip to content

Commit cdd3575

Browse files
authored
[fix] attribute escaping during ssr (#7333)
Fixes #7327 and a related security issue
1 parent b26aa1c commit cdd3575

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/runtime/internal/ssr.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ export function create_ssr_component(fn) {
177177

178178
export function add_attribute(name, value, boolean) {
179179
if (value == null || (boolean && !value)) return '';
180-
return ` ${name}${value === true && boolean_attributes.has(name) ? '' : `=${typeof value === 'string' ? JSON.stringify(escape(value)) : `"${value}"`}`}`;
180+
const assignment = (boolean && value === true) ? '' : `="${escape_attribute_value(value.toString())}"`;
181+
return ` ${name}${assignment}`;
181182
}
182183

183184
export function add_classes(classes) {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<div
2-
foo="&#34;></div><script>alert(42)</script>"
3-
></div>
2+
foo="&#34;></div>\<script>alert(42)</script>"
3+
bar="&#34;></div>\<script>alert(42)</script>"
4+
></div>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
2-
export let foo = '"></div><script>alert(42)</' + 'script>';
2+
export let foo = '"></div>\\<script>alert(42)</' + 'script>';
3+
export let bar = { toString: () => '"></div>\\<script>alert(42)<\/script>' };
34
</script>
45

5-
<div foo={foo}></div>
6+
<div foo={foo} bar={bar}></div>

0 commit comments

Comments
 (0)