GRC Careers

HomeResourcesCross-Site Scripting (XSS)

CS-059 · Application Security

Cross-Site Scripting (XSS)

An attack that injects malicious script into pages viewed by other users.

Executive Summary

Cross-site scripting, or XSS, is a class of web attack in which an attacker gets malicious script to run in another user's browser through a vulnerable application. Because the script runs in the victim's session, it can steal data, hijack accounts, or manipulate the page. The core defense is treating all untrusted data as data, using proper output encoding and a strong content security policy.

What It Is

XSS happens when an application includes untrusted data in a web page without safely neutralizing it, so a browser interprets that data as executable script. There are three common forms. Stored XSS saves the malicious content on the server, for example in a comment, so it runs for everyone who views it. Reflected XSS bounces attacker-supplied input straight back in a response, typically through a crafted link. DOM-based XSS occurs entirely in the browser when client-side code writes untrusted data into the page unsafely. In all forms the underlying problem is the same: data that should be displayed is instead executed.

Why It Matters

Because XSS runs in the victim's browser with the victim's privileges, it can do whatever the user can do on that site. That includes stealing session tokens, reading and changing displayed data, submitting actions as the user, and capturing keystrokes such as credentials. Stored XSS is especially dangerous because a single injected payload can affect many users automatically. XSS is a persistent, high-frequency finding in web assessments, so understanding and preventing it is a baseline skill for anyone building or testing web applications.

How It Works

At a conceptual level, XSS is an output problem. The application receives untrusted data and later places it into a page in a context where the browser can run it as script. The primary defense is contextual output encoding: when data is inserted into HTML, an attribute, or a script context, it is encoded so the browser treats it strictly as text to display. Modern frameworks that encode by default remove much of the risk when used correctly. A content security policy adds a strong second layer by restricting where scripts may load from and blocking inline script, which limits what an injected payload can do. For DOM-based XSS, the fix is to use safe browser APIs that set text rather than raw HTML, and to avoid passing untrusted data into functions that execute or render markup.

Architecture Diagram

Attacker supplies malicious inputApplication stores or reflects it into a pageUnsafe: browser runs it as scriptSafe: output encoding keeps it as displayed textContent security policy blocks unauthorized script
XSS turns untrusted data into running script; output encoding and a content security policy keep it as harmless text.

Visual Workflow

Identify every place untrusted data is written into a page, server-side and client-side.Apply contextual output encoding for HTML, attribute, and script contexts.Rely on a framework that encodes by default and use it as intended.Deploy a content security policy that restricts script sources and blocks inline script.For client-side code, use safe DOM APIs that set text rather than raw HTML.Test all three XSS types with automated tools and manual review, then re-test.

Common Attacks

Common Mistakes

Best Practices

Quick Checklist

Recommended Tools

Static application security testing (SAST)
Flags unsafe rendering of untrusted data in source code
Dynamic application security testing (DAST)
Probes a running application for reflected and stored XSS
Content security policy
Restricts script sources and inline script to limit injected payloads
Trusted templating framework
Encodes output by default to prevent injection when used correctly

Industry Standards

OWASP Top 10
XSS falls within the injection class of critical web application risk
OWASP Application Security Verification Standard (ASVS)
Testable requirements for safe output handling and encoding
CWE-79
The Common Weakness Enumeration entry for cross-site scripting

Career Relevance

XSS is essential knowledge for application security engineers, penetration testers, and secure code reviewers, who find it routinely in web assessments. Front-end and full-stack developers are expected to prevent it through safe rendering and a content security policy, and GRC and audit teams treat it as a common risk indicator. For the AI-Governance-Jobs.com audience, distinguishing the three XSS types and naming the correct defense is a frequent interview test.

Interview Questions

Related Certifications

GIAC Web Application Penetration Tester (GWAPT) Offensive Security Web Assessor (OSWA) CompTIA Security+

Further Reading

Key Takeaways

Download PDFDownload PNG

FAQ

What is the difference between stored and reflected XSS?

Stored XSS is saved on the server and runs for everyone who views the affected content, while reflected XSS is echoed back in a single response, usually through a crafted link that the victim must open.

Does a content security policy alone stop XSS?

No. A content security policy is a powerful second layer that limits what an injected script can do, but the primary fix is proper contextual output encoding so untrusted data is never treated as script in the first place.

Is DOM-based XSS different to fix?

Yes. Because it happens in the browser, the fix focuses on client-side code: use safe DOM APIs that set text rather than raw HTML, and avoid passing untrusted data into functions that render or execute markup.

Get all 116 reference sheets
The complete AGJ Cybersecurity Professional Reference Library, print-ready PDFs and PNGs.
Browse the library

Related Careers

Related certifications

GIAC Web Application Penetration Tester (GWAPT)Offensive Security Web Assessor (OSWA)CompTIA Security+

Current openings

Live openings appear on the web version. Browse the job board for current GRC and security roles.
Browse all jobs

Suggested learning path

  1. Ground the basics with CS-001 Cybersecurity
  2. Study this sheet: Cross-Site Scripting (XSS)
  3. Go deeper: OWASP Top 10
  4. Go deeper: SQL Injection
  5. Validate it: work toward GIAC Web Application Penetration Tester (GWAPT)
  6. Find the role: browse current openings

Related sheets

More in Application Security

Share this LinkedIn Facebook X Email