{
    "title": "XSS (cross-site scripting)",
    "seo_title": "XSS (cross-site scripting): definition and prevention",
    "h1": "XSS (cross-site scripting)",
    "description": "XSS explained: how an injected script runs in your visitors' browsers, the stored, reflected and DOM types, and the protections to apply on WordPress.",
    "lead": "XSS (cross-site scripting) is a vulnerability that lets an attacker run their own JavaScript in the page another visitor is viewing. The script then acts in the victim's browser with the site's privileges: performing actions on their behalf, reading the data on screen or redirecting them.",
    "language": "en",
    "locale": "en-US",
    "type": "definition",
    "url": "https://www.wp-feint.com/glossary/xss/",
    "canonical": "https://www.wp-feint.com/glossary/xss/",
    "markdown": "https://www.wp-feint.com/glossary/xss/index.md",
    "json": "https://www.wp-feint.com/glossary/xss/index.json",
    "published": "2026-10-28T08:00:00+00:00",
    "modified": "2026-11-22T12:07:20+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "XSS (cross-site scripting)",
            "url": "https://www.wp-feint.com/glossary/xss/",
            "markdown": "https://www.wp-feint.com/glossary/xss/index.md",
            "json": "https://www.wp-feint.com/glossary/xss/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "Faille XSS",
            "url": "https://www.wp-feint.com/fr/definitions/faille-xss/",
            "markdown": "https://www.wp-feint.com/fr/definitions/faille-xss/index.md",
            "json": "https://www.wp-feint.com/fr/definitions/faille-xss/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "Vulnerabilidad XSS",
            "url": "https://www.wp-feint.com/es/glosario/vulnerabilidad-xss/",
            "markdown": "https://www.wp-feint.com/es/glosario/vulnerabilidad-xss/index.md",
            "json": "https://www.wp-feint.com/es/glosario/vulnerabilidad-xss/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "Cross-Site-Scripting (XSS)",
            "url": "https://www.wp-feint.com/de/glossar/cross-site-scripting/",
            "markdown": "https://www.wp-feint.com/de/glossar/cross-site-scripting/index.md",
            "json": "https://www.wp-feint.com/de/glossar/cross-site-scripting/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "Vulnerabilità XSS",
            "url": "https://www.wp-feint.com/it/glossario/vulnerabilita-xss/",
            "markdown": "https://www.wp-feint.com/it/glossario/vulnerabilita-xss/index.md",
            "json": "https://www.wp-feint.com/it/glossario/vulnerabilita-xss/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "Vulnerabilidade XSS",
            "url": "https://www.wp-feint.com/pt/glossario/vulnerabilidade-xss/",
            "markdown": "https://www.wp-feint.com/pt/glossario/vulnerabilidade-xss/index.md",
            "json": "https://www.wp-feint.com/pt/glossario/vulnerabilidade-xss/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "Cross-site scripting (XSS)",
            "url": "https://www.wp-feint.com/nl/woordenlijst/cross-site-scripting/",
            "markdown": "https://www.wp-feint.com/nl/woordenlijst/cross-site-scripting/index.md",
            "json": "https://www.wp-feint.com/nl/woordenlijst/cross-site-scripting/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "XSS (cross-site scripting)"
        },
        {
            "level": 2,
            "text": "How an XSS attack works"
        },
        {
            "level": 2,
            "text": "The different types of XSS"
        },
        {
            "level": 2,
            "text": "For WordPress: escape late"
        },
        {
            "level": 2,
            "text": "How to protect your site without touching code"
        },
        {
            "level": 2,
            "text": "Common mistakes"
        }
    ],
    "body": "XSS stands for cross-site scripting; the X is used instead of a C to avoid confusion with CSS style sheets. It is an injection flaw: the site inserts data from the outside into its page without neutralizing it, and the browser interprets that data as code. MITRE catalogs it as CWE-79. Because the script appears to come from the site itself, the browser gives it the same trust as the rest of the page.\n\n## How an XSS attack works\n\nIt all starts with a value the attacker controls: a URL parameter, a form field, a comment, an HTTP header saved in visitor statistics. If the code outputs that value raw, a string like `<script>…</script>` or an `onerror=\"…\"` attribute becomes executable. The script can then read the page content, send requests on behalf of the logged-in user, change what they see or redirect them to another site.\n\n![Five-step diagram of a stored XSS: the attacker injects a script tag into a field, the site saves it, an administrator opens the screen that displays it, the page returns the script without escaping and the script runs in the administrator's session](https://www.wp-feint.com/media/2026/10/xss-stockee-en.webp)\n\nOn a WordPress site, the prime target is the administrator. A script running in their session can create an account, install a plugin or change a setting without ever knowing their password: the browser itself sends the login cookies with every request.\n\n## The different types of XSS\n\n- **Stored (persistent) XSS**: the script is saved on the server, in the database for example, then served again every time the data is displayed. The victim doesn't have to do anything special, just open the page.\n- **Reflected XSS**: the script travels in the request, often a booby-trapped link, and the server immediately copies it into its response. The victim has to click.\n- **DOM-based XSS**: the page's own JavaScript inserts untrusted data, such as the fragment of a URL. The server may never see it go by.\n\nOWASP also describes “blind” XSS: a stored variant that fires later, in an interface the attacker cannot see. That is exactly the case for the logs, statistics and form submissions you review from the Dashboard. The real-world XSS cases in popular plugins show this scenario is anything but theoretical.\n\n*Video: “Cross-Site Scripting (XSS) Explained” (PwnFunction)*\n\n## For WordPress: escape late\n\nThe WordPress developer documentation sets a simple rule: escape as late as possible, at the moment the data is output, with the function that matches the context.\n\n| Output context | Function |\n| --- | --- |\n| Text inside an HTML element | `esc_html()` |\n| Attribute value | `esc_attr()` |\n| URL in href or src | `esc_url()` |\n| Inline JavaScript | `esc_js()` |\n| Textarea content | `esc_textarea()` |\n| HTML where some tags are allowed | `wp_kses()`, `wp_kses_post()` |\n\n```\n<h2><?php echo esc_html( $title ); ?></h2>\n<a href=\"<?php echo esc_url( $link ); ?>\" title=\"<?php echo esc_attr( $info ); ?>\">View</a>\n```\n\nValidating and sanitizing input is still useful, but it does not replace output escaping: the same value can be displayed in several contexts.\n\n## How to protect your site without touching code\n\n- Update plugins and themes quickly: XSS flaws exploited at scale usually target versions that have already been patched.\n- Keep few privileged accounts and delete the ones nobody uses anymore.\n- Watch for new administrator accounts, a common sign of an exploited XSS.\n- Add a [Content Security Policy](https://www.wp-feint.com/glossary/content-security-policy/), keeping in mind that a strict version, which bans inline scripts, is hard to maintain with WordPress. Our guide to [HTTP security headers for WordPress](https://www.wp-feint.com/http-security-headers-wordpress/) covers the options.\n- A [web application firewall](https://www.wp-feint.com/glossary/waf/) can stop known payloads, with no guarantee against a new variant.\n\nWP Feint Pro sends [security headers](https://www.wp-feint.com/features/security-headers/), including an optional basic CSP. That CSP does not restrict scripts, so it does not block an XSS. WP Feint is neither a web application firewall nor a code fixer: only updating the faulty component closes the hole.\n\n## Common mistakes\n\n- Confusing XSS with [CSRF](https://www.wp-feint.com/glossary/csrf/): the latter makes the browser send a forged request without running any script in the page. An XSS, on the other hand, can bypass anti-CSRF protections, since the script reads the tokens in the page.\n- Assuming data is “internal” because it shows up in the admin area: an HTTP header or a visited URL comes from the outside.\n- Using `esc_html()` in an attribute or `esc_attr()` for a URL: each context has its own function.\n- Thinking that protection against [SQL injection](https://www.wp-feint.com/glossary/sql-injection/) is enough: data stored safely in the database can still be dangerous when displayed.\n\n## Related terms\n\n- [Content Security Policy (CSP)](https://www.wp-feint.com/glossary/content-security-policy/)\n- [SQL injection](https://www.wp-feint.com/glossary/sql-injection/)\n- [CSRF (cross-site request forgery)](https://www.wp-feint.com/glossary/csrf/)\n- [HTTP security headers](https://www.wp-feint.com/glossary/http-security-headers/)\n- [Nonce](https://www.wp-feint.com/glossary/nonce/)\n\n\n## Sources\n\n- [OWASP : Cross Site Scripting (XSS)](https://owasp.org/www-community/attacks/xss/)\n- [MITRE CWE-79 : Improper Neutralization of Input During Web Page Generation (Cross-site Scripting)](https://cwe.mitre.org/data/definitions/79.html)\n- [WordPress Developer Resources : Escaping Data](https://developer.wordpress.org/apis/security/escaping/)",
    "definition": "XSS (cross-site scripting) is a vulnerability that lets an attacker run their own JavaScript in the page another visitor is viewing. The script then acts in the victim's browser with the site's privileges: performing actions on their behalf, reading the data on screen or redirecting them.",
    "group": "Web security",
    "aka": [
        "cross-site scripting",
        "XSS vulnerability",
        "XSS attack"
    ],
    "related": [
        {
            "title": "Content Security Policy (CSP)",
            "url": "https://www.wp-feint.com/glossary/content-security-policy/",
            "markdown": "https://www.wp-feint.com/glossary/content-security-policy/index.md"
        },
        {
            "title": "SQL injection",
            "url": "https://www.wp-feint.com/glossary/sql-injection/",
            "markdown": "https://www.wp-feint.com/glossary/sql-injection/index.md"
        },
        {
            "title": "CSRF (cross-site request forgery)",
            "url": "https://www.wp-feint.com/glossary/csrf/",
            "markdown": "https://www.wp-feint.com/glossary/csrf/index.md"
        },
        {
            "title": "HTTP security headers",
            "url": "https://www.wp-feint.com/glossary/http-security-headers/",
            "markdown": "https://www.wp-feint.com/glossary/http-security-headers/index.md"
        },
        {
            "title": "Nonce",
            "url": "https://www.wp-feint.com/glossary/nonce/",
            "markdown": "https://www.wp-feint.com/glossary/nonce/index.md"
        }
    ],
    "sources": [
        {
            "title": "OWASP : Cross Site Scripting (XSS)",
            "url": "https://owasp.org/www-community/attacks/xss/"
        },
        {
            "title": "MITRE CWE-79 : Improper Neutralization of Input During Web Page Generation (Cross-site Scripting)",
            "url": "https://cwe.mitre.org/data/definitions/79.html"
        },
        {
            "title": "WordPress Developer Resources : Escaping Data",
            "url": "https://developer.wordpress.org/apis/security/escaping/"
        }
    ],
    "format": "application/json"
}