Cross-site scripting: how attackers turn your trusted browser against you

Cross-site scripting: how attackers turn your trusted browser against you
Image: Intellect (generated)

In short: Cross-site scripting (XSS) occurs when malicious scripts are injected into otherwise trusted web pages. By exploiting vulnerabilities in how sites handle user data, attackers can bypass security controls to steal session cookies, access sensitive information, or even turn a browser into a self-propagating worm without the user ever knowing.

First identified in the 1990s, cross-site scripting has evolved from a simple data-breach method into the most common publicly reported security vulnerability. The term, coined by Microsoft security engineers in January 2000, is considered a misnomer by the Open Web Application Security Project (OWASP) because it now encompasses a wide range of code injection techniques beyond its original scope. In 2007, researchers estimated that as many as 68% of websites were potentially open to these attacks.

The mechanism relies on the same-origin policy, a fundamental web security concept that grants permissions to content based on URI schemes, host names, and port numbers. When a site fails to properly sanitize or encode user-supplied data, an attacker can inject malicious scripts that the browser executes under the trusted site's permissions. These attacks generally fall into two primary categories: non-persistent (reflected) XSS, where the payload is delivered via a link, and persistent (stored) XSS, where the malicious code is saved on the server and served to every visitor.

Modern web development has introduced further complexity with DOM-based XSS, where the vulnerability exists entirely in client-side JavaScript rather than on the server. Mitigating these risks is notoriously difficult. While developers can use techniques like contextual output encoding, HTML sanitization, or the HttpOnly cookie flag, these are often imperfect. Even advanced defenses, such as blocking scripts by default or using Trusted Types to verify data, face trade-offs between security and site functionality, as many modern web applications rely heavily on client-side scripts to remain responsive and interactive.

Opens the Intellect+ feed with this card first. Swipe up for the next one.

Sources

To cite this card, link to https://intellectplus.co.uk/app/technology-cross-site-scripting.

How we source, check and correct cards: Editorial standards.

General information, not professional advice. Spotted an error? Flag the card or see corrections and complaints.

Intellect Plus is a visual educational discovery platform for exploring fascinating facts and ideas. Brain Food, Not Brain Rot. What is Intellect Plus?

Related

Finding something worth knowing…