Skip to content

Commit 5091e2c

Browse files
committed
fix(ssr): address possible xss vector
1 parent 0dc27dc commit 5091e2c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/platforms/web/server/modules/attrs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function renderAttr (key: string, value: string): string {
5050
} else if (isEnumeratedAttr(key)) {
5151
return ` ${key}="${isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true'}"`
5252
} else if (!isFalsyAttrValue(value)) {
53-
return ` ${key}="${typeof value === 'string' ? cachedEscape(value) : value}"`
53+
return ` ${key}="${cachedEscape(String(value))}"`
5454
}
5555
return ''
5656
}

test/ssr/ssr-string.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,19 @@ describe('SSR: renderToString', () => {
821821
})
822822
})
823823

824+
it('should prevent script xss with v-bind object syntax + array value', done => {
825+
renderVmWithOptions({
826+
data: {
827+
test: ['"><script>alert(1)</script><!--"']
828+
},
829+
template: `<div v-bind="{ test }"></div>`
830+
}, res => {
831+
console.log(res)
832+
expect(res).not.toContain(`<script>alert(1)</script>`)
833+
done()
834+
})
835+
})
836+
824837
it('v-if', done => {
825838
renderVmWithOptions({
826839
template: `

0 commit comments

Comments
 (0)