Challenge - 5 Problems
Vue Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding Cross-Site Scripting (XSS) in Vue
What is the main reason Vue automatically escapes HTML in template bindings?
Attempts:
2 left
💡 Hint
Think about what happens if user input contains script tags.
✗ Incorrect
Vue escapes HTML in template bindings to stop attackers from running harmful scripts inside your app, which is called Cross-Site Scripting (XSS).
❓ component_behavior
intermediate2:00remaining
Safe Rendering with v-html Directive
What happens if you use
v-html with untrusted user input in Vue?Vue
<template> <div v-html="userContent"></div> </template> <script setup> const userContent = '<img src=x onerror=alert(1)>' </script>
Attempts:
2 left
💡 Hint
Consider what
v-html does with raw HTML strings.✗ Incorrect
The v-html directive renders raw HTML, so if the content includes malicious scripts, they will run unless you sanitize the input yourself.
🔧 Debug
advanced2:00remaining
Identifying a Security Flaw in Vue Code
Which option shows a Vue snippet that can cause a security vulnerability?
Attempts:
2 left
💡 Hint
Look for where raw HTML is rendered without escaping.
✗ Incorrect
Option B uses v-html with raw script tags, which will execute the script and cause an XSS vulnerability.
❓ state_output
advanced2:00remaining
Effect of Sanitizing User Input Before Rendering
If you sanitize user input to remove scripts before assigning it to a Vue reactive variable used with
v-html, what will be the output?Vue
<template> <div v-html="safeContent"></div> </template> <script setup> import DOMPurify from 'dompurify' const rawContent = '<img src=x onerror=alert(1)><p>Hello</p>' const safeContent = DOMPurify.sanitize(rawContent) </script>
Attempts:
2 left
💡 Hint
Think about what sanitizing does to dangerous HTML.
✗ Incorrect
Sanitizing removes harmful parts like scripts but keeps safe HTML tags, so only safe content is rendered.
📝 Syntax
expert2:00remaining
Correct Syntax to Bind Attributes Safely in Vue
Which option correctly binds a user-provided URL to an
img tag's src attribute to avoid security issues?Attempts:
2 left
💡 Hint
Remember how Vue binds dynamic attributes safely.
✗ Incorrect
Using :src or v-bind:src safely binds the URL as an attribute, preventing injection. Using mustache inside src or plain strings does not work correctly.