Skip to content

Commit 5a8234f

Browse files
authored
security: sanitize Vue directive attributes (#285)
1 parent 5940e4b commit 5a8234f

4 files changed

Lines changed: 860 additions & 582 deletions

File tree

packages/comark/src/internal/props-validation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,16 @@ function validateUrl(value: string, mode: 'link' | 'image', options: PropsValida
9292
}
9393

9494
export function validateProp(attribute: string, value: string, options: PropsValidationOptions = {}): string | false {
95-
attribute = attribute.toLowerCase()
95+
attribute = attribute
96+
.toLowerCase()
97+
.replace(/^(:|v-bind:)/, '')
98+
.replace(/^(@|v-on:)/, 'on')
99+
.replace(/:/g, '')
96100
if (attribute.startsWith('on') || unsafeAttributes.includes(attribute)) {
97101
return false
98102
}
99103

100-
if (attribute === 'href') {
104+
if (attribute === 'href' || attribute === 'xlinkhref') {
101105
return validateUrl(value, 'link', options)
102106
}
103107

0 commit comments

Comments
 (0)