PHP2ShellAttacks began 17 Oct. Fixed builds shipped 21–22 Oct. Check your exposure
Common · OWASP Top 10

Cross-site scripting (XSS)

Cross-site scripting lets an attacker run their own script in your visitors’ browsers, to steal logins or change what they see on your pages.

CWE-79

The weakness ID for cross-site scripting

MITRE

Cheat sheet

OWASP’s guide to preventing it

OWASP

Why it matters to you

Comment boxes, profile fields, search results and contact forms all repeat what a visitor typed. If that text isn’t escaped, it can run as code in the next visitor’s browser, including yours.

Check it yourself

  1. 01Search your templates for output that isn’t escaped.
  2. 02On a copy of your own site, enter a harmless test script in a form and see whether it appears as text or runs.
  3. 03Watch the browser console for content security policy errors after you add one.

Fix it

  1. 01Escape output for where it appears: htmlspecialchars with ENT_QUOTES in PHP. In Laravel, Blade’s double braces escape by default and the {!! !!} form does not.
  2. 02Add a Content Security Policy to limit which scripts can run.
  3. 03Sanitise rich text with an allow-list library.
  4. 04Set session cookies HttpOnly and Secure.

How PatchRig helps

PatchRig finds the unescaped outputs, fixes them on a copy, and adds a content security policy that fits your site.

Sources

Related guides