This project demonstrates an XSS vulnerability in vue-i18n (include 9.0.0 ⟶ < 9.14.5, and earlier 10/11 minors) when using v-html to render translations containing untrusted HTML.
- The app sets a cookie named
secure_tokento simulate a sensitive value (e.g., an auth token). - The translation for
welcomecontains a{name}parameter, which is set to a value that could come from an external API. - In the demo,
nameis set to a malicious payload:const name = `<img src=x onerror=alert(document.cookie)>`;
- The
XssDemo.vuecomponent renders this translation usingv-html:<div v-html="$t('welcome', { name })"></div>
- When the page loads, the malicious code executes, reading
document.cookieand displaying the stolen token in an alert. In a real attack, this could be exfiltrated to a remote server.
- Install dependencies:
npm install
- Start the dev server:
npm run dev
- Open the app in your browser. You should see an alert triggered by the XSS payload.
Never use v-html with untrusted translations or user input.
This demo is for educational purposes only.
VSCode + Volar (and disable Vetur).
See Vite Configuration Reference.
npm installnpm run devnpm run build