Skip to content

Commit

Permalink
fix(ssr): address possible xss vector
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 29, 2017
1 parent 0dc27dc commit 5091e2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/platforms/web/server/modules/attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function renderAttr (key: string, value: string): string {
} else if (isEnumeratedAttr(key)) {
return ` ${key}="${isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true'}"`
} else if (!isFalsyAttrValue(value)) {
return ` ${key}="${typeof value === 'string' ? cachedEscape(value) : value}"`
return ` ${key}="${cachedEscape(String(value))}"`
}
return ''
}
13 changes: 13 additions & 0 deletions test/ssr/ssr-string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,19 @@ describe('SSR: renderToString', () => {
})
})

it('should prevent script xss with v-bind object syntax + array value', done => {
renderVmWithOptions({
data: {
test: ['"><script>alert(1)</script><!--"']
},
template: `<div v-bind="{ test }"></div>`
}, res => {
console.log(res)
expect(res).not.toContain(`<script>alert(1)</script>`)
done()
})
})

it('v-if', done => {
renderVmWithOptions({
template: `
Expand Down

0 comments on commit 5091e2c

Please sign in to comment.