Cross-site scripting (XSS) meaning, in plain words

XSS lets an attacker run a script in a visitor's browser through your own page. How the flaw works, what Cookie theft looks like, and the role of escaping.

Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated

Cross-site scripting (XSS) is an attack that runs a malicious script in a visitor's browser through a page on your site. IPA describes it as a vulnerability where a problem in how a web page handles content to output allows a malicious script to be embedded in the page. The people affected are not the site itself but the visitors who load the compromised page.

How does XSS work?

Imagine a town noticeboard where a manager pastes up every note that arrives without reading the content. A notice that looked like a genuine announcement could be a forgery, and passers-by would have no way to tell the difference. On a website, displaying another person's input on a page without checking it creates the same opening.

A browser runs any script it finds on a page as though it belongs to that site. A script that has been embedded in the page can therefore do anything the legitimate site can do in that user's context — including reading session data or submitting forms.

The primary fix is escaping: converting special characters into their plain text equivalents before they are written to the page. IPA shows that this must be applied to every element that is output. When HTML input is permitted, the content must be parsed and only approved elements retained. What to check and how to address it is covered on the cross-site scripting vulnerability page.

Why does XSS matter?

IPA describes two main categories of harm. The first is displaying a fraudulent page inside the genuine site, which can be used to lead visitors into a phishing flow. The second is stealing Cookies — the small data items that hold login state — to impersonate the user. The user is the direct victim, but the site operator bears the reputational damage.

Defenses are layered. Adding the HttpOnly attribute to a Cookie prevents scripts on the page from reading it. CSP is an additional layer that stops scripts from unauthorized sources from running. IPA places both in a supporting role rather than as a primary fix.

OWASP warns that if XSS is present, the protections against CSRF can also be undermined. Closing XSS flaws therefore helps preserve the effectiveness of other defenses as well.

Whether input from visitors reaches your site's pages without being escaped is not visible from outside. The free URL check shows which security headers are present. For a review of how your pages handle output, contact us.

Related terms

  • CSP: a response header that blocks scripts from unauthorized sources — a supplementary defense alongside output escaping.
  • CSRF: an attack that exploits a logged-in user's session; XSS can break CSRF defenses if not addressed.
  • SQL injection: another attack that stems from improper input handling, targeting the database rather than the browser.

Frequently asked questions

Does XSS affect a simple company site that only publishes articles?

It can. Any feature that takes input from someone else and displays it on a page — a comment section, a search results page, an inquiry management screen — creates a potential path. Plugins that handle user input also warrant attention.

Does adding a CSP header prevent XSS?

CSP is a supplementary defense. The primary fix is escaping output correctly, so both should be used together. IPA also positions response header controls as a supplementary measure, not a replacement for output escaping.

Next step

The first step for assessing your exposure is to list every feature that takes someone else's input and displays it. The cross-site scripting vulnerability page covers how to check and what to fix. For the site-defacement aspect, the tampering countermeasures page is also relevant. The free URL check shows what is visible from outside, and specific questions can be addressed by contacting us.

Frequently asked questions

Does XSS affect a simple company site that only publishes articles?

It can. Any feature that takes input from someone else and displays it on a page — a comment section, a search results page, an inquiry management screen — creates a potential path. Plugins that handle user input also warrant attention.

Does adding a CSP header prevent XSS?

CSP is a supplementary defense. The primary fix is escaping output correctly, so both should be used together. IPA also positions response header controls as a supplementary measure, not a replacement for output escaping.

See what an attacker can see, today

The free URL check returns a grade in under a minute. For costs and next steps, book a free consultation.