How to fix: Vue v-html Directive with Dynamic Content
The Vue v-html directive was found in the page with a dynamic binding. v-html renders raw HTML without Vue's template escaping, creating XSS risk if the bound value includes any user-controlled content.
Why it matters
v-html bypasses Vue's HTML escaping. If the bound variable contains user-generated content, the browser will render it as HTML, executing any injected script tags, event handlers, or javascript: URLs.
Vue's template system escapes HTML by default: {{ userContent }} is always rendered as text. v-html explicitly renders HTML, which is safe only for fully trusted content (e.g., pre-sanitized CMS content).
How to fix it
- 1Avoid v-html with user-generated content.
- 2If HTML rendering is needed, sanitize with DOMPurify before binding: :v-html='sanitize(content)'.
- 3Prefer {{ content }} (text interpolation) which always escapes HTML.
- 4Consider a component-based rich text renderer instead of raw HTML.
Code examples
Safe v-html with DOMPurify
<!-- Bad -->
<div v-html="userContent"></div>
<!-- Good -->
<div v-html="sanitized(userContent)"></div>
<!-- In script -->
import DOMPurify from 'dompurify';
const sanitized = (html) => DOMPurify.sanitize(html);References
Detected automatically by VulnRadar. The check id is vue-v-html-directive, stable across every scan so you can filter or diff on it.
More client-side checks
- HighCSP Allows 'unsafe-inline' Scripts
- MediumCSP Allows 'unsafe-eval'
- HighpostMessage Without Origin Validation
- HighSensitive Data Stored in localStorage
- HighDOM XSS via location.hash Assignment
- Highdocument.write() in Page Scripts
- Higheval() in Client-Side JavaScript
- MediumExternal Script Without Subresource Integrity
Questions
- How severe is Vue v-html Directive with Dynamic Content?
- VulnRadar rates this high severity in the client-side category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id vue-v-html-directive, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Vue v-html Directive with Dynamic Content map to?
- It maps to CWE-79. In the OWASP Top 10 it falls under A03:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.