Loading Depth Study
Preparing your workspace
Cross-site scripting occurs when attacker-controlled content is interpreted as executable browser code instead of harmless data.
XSS can happen when applications insert untrusted content into HTML, attributes, scripts, URLs, or other executable contexts without appropriate protection. Modern frameworks often escape normal text output automatically, which is safer than inserting raw HTML. Features that intentionally render HTML require extra care. Content Security Policy can provide an additional defense layer, but it does not replace safe coding practices.
A course discussion system should render a student's comment as text unless the application has a carefully controlled and sanitized rich-text feature.
const comment = userComment;
// Safe text rendering in a framework:
return <p>{comment}</p>;
// Avoid rendering untrusted HTML directly unless it has been safely handled.The framework renders the comment as text rather than treating it as executable HTML.