zappz

All topics

cross-site scripting

1 article

Cross-site scripting is a web security flaw that lets an attacker run their own script in other people's browsers as if it came from a trusted site.

It happens when a site takes text from an untrusted source and places it into a page without making sure the browser will treat it as plain text. If that text contains script, the browser runs it. There are three recognised kinds. In stored cross-site scripting, the malicious text is saved on the server, for example in a comment, and delivered to everyone who views it. In the reflected kind, the text travels in a link and is echoed straight back in the response to whoever clicks. In the DOM-based kind, the fault lies in the page's own script, which writes untrusted data into the page inside the browser.

The central defence is output encoding: converting special characters so they display as text and cannot act as code, with the method matched to the place in the page where the data lands. Where users must be allowed some formatting, a sanitiser strips out anything dangerous. Modern frameworks encode by default, and a Content Security Policy adds a backstop by limiting which scripts may run.

The flaw matters because injected script has the full authority of the site in the victim's browser. It can read what is on the page, take session cookies that are not protected, perform actions as the user, or show a false sign-in form. A single vulnerable comment box can compromise every visitor.

  1. cross-site scriptingWhat Is Cross-Site Scripting? Three Kinds, How to Stop ThemCross-site scripting lets an attacker's script run inside a site you trust. The three kinds, a worked comment box example, and the defenses that hold. · 7 min read

Related topics

All topics