Recall & Review
beginner
What is XSS and why is it a security risk in web applications?
XSS (Cross-Site Scripting) is when attackers inject harmful scripts into web pages viewed by others. It can steal data, hijack user sessions, or change page content, making it a serious security risk.
Click to reveal answer
beginner
How does Vue.js prevent XSS attacks by default in templates?
Vue automatically escapes HTML special characters in template expressions, so user input is shown as text, not code. This stops scripts from running inside the page.
Click to reveal answer
intermediate
What is the risk of using the v-html directive in Vue templates?
v-html inserts raw HTML into the page without escaping. If the HTML comes from untrusted sources, it can run malicious scripts and cause XSS attacks.
Click to reveal answer
intermediate
Name two best practices to avoid XSS when using Vue templates.
1. Avoid using v-html with untrusted content. 2. Always sanitize any HTML before inserting it. 3. Use Vue's default template syntax for binding text.
Click to reveal answer
advanced
How can you sanitize HTML content before using it with v-html in Vue?
Use a trusted library like DOMPurify to clean the HTML string by removing unsafe tags and attributes before binding it with v-html.
Click to reveal answer
What does Vue do by default to prevent XSS in templates?
✗ Incorrect
Vue escapes HTML special characters in template expressions to show user input as text, preventing scripts from running.
Which Vue directive can cause XSS if used with untrusted content?
✗ Incorrect
v-html inserts raw HTML without escaping, so untrusted content can run scripts and cause XSS.
What is a safe way to display user input in Vue templates?
✗ Incorrect
Using {{ }} escapes HTML characters, showing input as text safely.
Which tool can help sanitize HTML before using it with v-html?
✗ Incorrect
DOMPurify cleans HTML strings by removing unsafe code, preventing XSS.
Why should you avoid using v-html with user-generated content?
✗ Incorrect
Untrusted HTML can contain scripts that run when inserted with v-html, causing XSS.
Explain how Vue's template syntax helps prevent XSS attacks.
Think about how Vue treats {{ userInput }} in templates.
You got /3 concepts.
Describe the risks of using v-html and how to safely use it in Vue applications.
Consider what happens if untrusted HTML is inserted directly.
You got /4 concepts.