Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Reflected XSS in form fields or search: how to find and fix it

OPS-177High impactOther toolBy FunnelGuardPublished Updated
On this page

What this issue is

Reflected XSS is a flaw where data from the request (a URL parameter, a search query, a form field) is placed into the HTML response without being made safe. The browser then treats that data as code instead of text. It is called "reflected" because the payload is not stored. It bounces straight back from the request to the response.

Vulnerable vs safe output (PHP)php
<?php
// Vulnerable: prints raw user input
echo 'You searched for: ' . $_GET['q'];

// Safe: escapes for HTML body context
echo 'You searched for: ' . htmlspecialchars($_GET['q'] ?? '', ENT_QUOTES, 'UTF-8');

Why it costs you leads or sales

How a reflected XSS attack reaches your customer
  1. Crafted linkAttacker sends a URL with a script in the search parameter
  2. Visitor clicksThe link is on your real domain, so it looks safe
  3. Page echoes inputSearch or form page prints the value without escaping
  4. Script runsRuns in the visitor's browser with your site's access
  5. Trust and data lostForm data, sessions or the checkout can be hijacked

The attacker never touches your server. They only need a visitor to click a crafted link.

How to check if your site has it

Manual reflection test
  1. Find where input is echoed

    List search boxes, form error pages, thank-you pages, 404 pages and any URL with parameters such as q, s, name, email, utm or redirect.

  2. Submit a unique marker

    Enter a string like fgtest12345 and view the page source (Ctrl+U or Cmd+Option+U). Search for the marker to see where it lands: in body text, an attribute or a script block.

  3. Check special characters

    Submit fgtest<b>"'& and look at the source. If you see the raw < and " characters instead of &lt; and &quot;, that output is not escaped.

  4. Run a scanner

    Use a web application vulnerability scanner such as OWASP ZAP against a staging copy. It tests parameters systematically and reports reflected XSS.

  5. Review plugins and themes

    Check whether your CMS plugins or themes have published reflected XSS advisories. See the related issue on outdated plugins.

How to fix it

Fix by platform
  1. Update core, theme and plugins

    Most WordPress reflected XSS comes from plugins or themes. Update everything, and remove anything abandoned.

  2. Escape in your own theme code

    Use esc_html() for body text, esc_attr() for attributes and esc_url() for links. For the search page use get_search_query(), which is escaped, instead of echoing $_GET['s'].

  3. Sanitise input

    Use sanitize_text_field() on incoming values and wp_unslash() where needed.

Client side: show a URL parameter safelyjavascript
const q = new URLSearchParams(location.search).get('q') || '';

// Unsafe
// document.getElementById('term').innerHTML = q;

// Safe
document.getElementById('term').textContent = q;
Add a second layer: Content-Security-Policy
  1. Start in report-only mode

    Send a Content-Security-Policy-Report-Only header first so you can see what would break without blocking anything.

  2. Restrict script sources

    Allow scripts only from your own domain and the tools you use, and avoid unsafe-inline where you can by using nonces.

  3. Enforce

    Once reports are clean, switch to the Content-Security-Policy header. A CSP reduces the damage of an XSS bug but does not replace escaping.

Example CSP header in nginx (adjust sources to your site)nginx
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' https://www.googletagmanager.com; object-src 'none'; base-uri 'self'" always;
Search results page

Vulnerable

  • Search term printed as raw HTML
  • Special characters appear unchanged in page source
  • A crafted link can run script on your domain

Fixed

  • Search term escaped for HTML context
  • < and " appear as &lt; and &quot; in the source
  • CSP limits which scripts can run

How to confirm it's fixed

Verification checklist
  • Repeat the marker test and confirm special characters are encoded in the page source
  • Test each context: body text, attributes, script blocks and URLs
  • Check error pages, thank-you pages and 404 pages, not just search
  • Re-run your vulnerability scanner on staging and production (with permission)
  • Confirm the CSP header is present using your browser's Network tab
  • Check the CSP report-only log shows no unexpected blocked scripts before enforcing

How to prevent it happening again

Prevention habits
  • Use frameworks and templates that escape output by default
  • Add XSS checks to code review: any place request data is printed
  • Keep CMS core, themes and plugins updated and remove abandoned ones
  • Run a scheduled vulnerability scan after each release
  • Keep a Content-Security-Policy and review its reports
  • Mark session cookies HttpOnly, Secure and SameSite to limit what script can steal
Example: from flaw to cleanup
  1. Day 0

    A plugin update adds a search widget that prints the query unescaped

  2. Day 12

    A crafted link is shared and clicked by visitors

  3. Day 14

    A scanner finds the reflection

  4. Day 15

    Output escaped, plugin updated, CSP added

How FunnelGuard handles this

Questions people ask

What is reflected XSS in simple terms?

Reflected XSS is when a website prints something a visitor sent, such as a search term, back into the page without making it safe. An attacker can build a link that makes the browser run their script on your site. Nothing is stored, so each victim has to click the crafted link.

How do I test my search box for XSS?

On a site you own, search for a unique marker such as fgtest12345 and view the page source to see where it appears. Then try special characters like < and " and check they come back encoded as &lt; and &quot;. A scanner such as OWASP ZAP on a staging copy covers more cases.

How do I fix reflected XSS?

Escape every value from the request for the context where you print it, such as HTML body, attribute, JavaScript or URL. Use templates that auto-escape and avoid innerHTML. Update vulnerable plugins and add a Content-Security-Policy as a second layer.

Is reflected XSS the same as stored XSS?

No. Reflected XSS bounces from the request straight into the response and needs the victim to click a crafted link. Stored XSS is saved on your server, for example in a form submission, and runs for anyone who views it.

Does a Content-Security-Policy stop XSS?

A strict CSP can block injected inline scripts and unknown script sources, which limits the damage. It is a second layer and does not replace escaping output. Start with report-only mode so you do not break legitimate scripts.

Can a WordPress plugin cause reflected XSS?

Yes. Many reported WordPress XSS issues come from plugins and themes that print request data without escaping. Update them, remove abandoned ones, and use esc_html(), esc_attr() and esc_url() in your own code.

Can FunnelGuard detect XSS on my site?

No. XSS testing needs a vulnerability scanner or penetration test. FunnelGuard monitors your funnels, such as forms and checkouts, so it can help confirm they still work after a security fix.

Does FunnelGuard catch this?

Other tool

Needs a different kind of tool.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.