Next.js
/Intermediate
XSS Prevention
Definition
Cross-Site Scripting (XSS): A vulnerability where an attacker injects malicious JavaScript into a website, which then executes in the browser of other users.
Explain Like I'm New
An attacker writes `<script>stealPasswords()</script>` in a blog comment. If your website blindly renders that comment, the browser will execute the script. React and Next.js automatically prevent this by 'escaping' all text.
Real World Example
A forum website. You must ensure that if someone pastes JavaScript into a forum post, it displays as raw text on the screen, rather than actually running the code.
Common Use Cases
- •Application security
- •Sanitizing user inputs
Interactive Example
Loading Code Playground...
Interview Questions
basic
- Does React automatically protect you from XSS attacks when rendering variables like `<div>{userData}</div>`?
intermediate
- What specific React property explicitly bypasses this protection and leaves you vulnerable to XSS?