vue-html-injection
User data rendered as HTML by v-html, v-safe-html, or innerHTML.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule vue-html-injection - Level
- warning
- Reads
- Every file
- Fix
- None: the text must be rendered another way, which a rewrite of the attribute cannot choose
Why
A Vue template renders the value of v-html as HTML, and GitLab's v-safe-html renders it sanitized, which removes scripts but keeps the links, images, forms, and styles a user writes. Plain text a user wrote, such as an issue's title or a report's solution, what the page's address holds, markup written around values that are not escaped, and Markdown rendered in the browser with the default sanitizer, rendered this way let a user put their own markup on the page. Render text with {{ }}, which escapes it, render only HTML the server sanitized, such as GitLab's descriptionHtml fields, and escape each value written into markup.
The fix, as Ur suggests it: render the text with {{ }}, or escape what is written into the markup.
For agents
Render text a user wrote with {{ }}; give v-html and v-safe-html only HTML the server sanitized, and escape every value written into markup.
Example
app/solution.vue<script>
export default {
props: { vulnerability: { type: Object, required: true } },
computed: {
solutionText() {
const { solutionHtml, solution } = this.vulnerability;
return solutionHtml || solution;
},
},
};
</script>
<template>
<p v-safe-html="solutionText"></p>
</template>
$ ur scan --rule vue-html-injection
warning[vue-html-injection]: `v-safe-html` renders plain text a user wrote as HTML
--> ./app/solution.vue:14:6 `v-safe-html="solutionText"`
= hint: render the text with `{{ }}`, or escape what is written into the markup
= see: CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), MITRE (2024-11-19), https://cwe.mitre.org/data/definitions/79.html
scanned 1 file (no framework recognized)
vue-html-injection: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), MITRE (2024-11-19).