Skip to content
Free website migration on every plan, done by our team.Learn more ›
Security

Cross-site scripting (XSS) explained for website owners

How cross-site scripting injects malicious scripts into web pages, what it can steal, the common sources in plugins and forms, and the defences that stop it.

Short answer: Cross-site scripting (XSS) lets an attacker run their own JavaScript in your visitors' browsers through your site, usually via comments, forms or vulnerable plugins. It can steal sessions or show fake content. Defences include escaping output, updates, a Content Security Policy and a WAF.

How it happens

A site displays something a user entered, such as a comment, without making it safe first. If that input contains script code, browsers run it as if it came from your site.

What attackers can do

  • Steal logged-in session cookies.
  • Show fake login forms.
  • Redirect visitors to scam sites.

Defences

  1. Escape output in code so input is displayed as text (developers' job).
  2. Update plugins and themes promptly.
  3. Content Security Policy headers that restrict which scripts can run. See security headers.
  4. HttpOnly cookies so scripts can't read session cookies.
  5. A web application firewall. See WAF.

Frequently asked questions

Does HTTPS prevent XSS?

No. HTTPS encrypts the connection; XSS comes from the content of the page.

Can comment sections cause XSS?

Only if the site doesn't sanitise comments. Keep WordPress and comment plugins updated.

Ready when you are

Host it where it performs

NVMe speed, offshore privacy and a written SLA — live in minutes on AuroxHost.