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.
<?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
- Crafted linkAttacker sends a URL with a script in the search parameter
- Visitor clicksThe link is on your real domain, so it looks safe
- Page echoes inputSearch or form page prints the value without escaping
- Script runsRuns in the visitor's browser with your site's access
- 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
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.
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.
Check special characters
Submit fgtest<b>"'& and look at the source. If you see the raw < and " characters instead of < and ", that output is not escaped.
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.
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
Update core, theme and plugins
Most WordPress reflected XSS comes from plugins or themes. Update everything, and remove anything abandoned.
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'].
Sanitise input
Use sanitize_text_field() on incoming values and wp_unslash() where needed.
Escape Liquid output
In your theme, use the escape filter on any value taken from the request, for example {{ search.terms | escape }}.
Audit custom theme code and apps
Search theme files for raw uses of request data in script tags and attributes. Remove apps you no longer use.
Review Custom HTML tags
Check Custom HTML tags and Custom JavaScript variables that read URL parameters and write them into the page with innerHTML or document.write. Switch to textContent.
Limit who can publish
Restrict publish access in the container so unreviewed code cannot go live.
Check custom code embeds
Webflow escapes its native content, so look at custom code and embeds that read the URL and write it into the page. Use textContent instead of innerHTML.
Review third-party scripts
Remove search or form widgets you do not need.
Review Velo and embedded code
Wix escapes its standard elements. Check Velo code and HTML embeds that insert query values into the page, and set element text with the .text property rather than HTML.
Check code injection and code blocks
Under Settings > Advanced > Code Injection and in Code Blocks, look for scripts that read location.search and write to the page as HTML. Use textContent.
Use auto-escaping templates
Use a template engine that escapes by default (for example Twig, Jinja2, Razor or React) and avoid the raw or unescaped options.
Escape by context
HTML body: encode < > & " '. Attributes: always quote them and encode. JavaScript: pass data as JSON, not by string concatenation. URLs: validate the scheme and encode.
Avoid dangerous DOM sinks
Do not assign untrusted data to innerHTML, outerHTML, document.write or eval. Use textContent.
const q = new URLSearchParams(location.search).get('q') || '';
// Unsafe
// document.getElementById('term').innerHTML = q;
// Safe
document.getElementById('term').textContent = q;Start in report-only mode
Send a Content-Security-Policy-Report-Only header first so you can see what would break without blocking anything.
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.
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.
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' https://www.googletagmanager.com; object-src 'none'; base-uri 'self'" always;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 < and " in the source
- CSP limits which scripts can run
How to confirm it's fixed
- 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
- 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
Day 0
A plugin update adds a search widget that prints the query unescaped
Day 12
A crafted link is shared and clicked by visitors
Day 14
A scanner finds the reflection
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 < and ". 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.
Related issues
- OPS-178Stored XSS via form submissions into adminFix guide
- OPS-170Missing Content-Security-PolicyFix guide
- OPS-156Outdated plugins/themes with known CVEsFix guide
- OPS-179SQL injection in formsFix guide
- OPS-176Open redirect on site (abused for phishing, ad disapproval)Fix guide
- OPS-175Cookies without Secure/HttpOnly/SameSiteFix guide