Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Stored XSS via form submissions into admin: how to fix it

OPS-178High impactOther toolBy FunnelGuardPublished Updated
On this page

What this issue is

Cross-site scripting (XSS) means a page treats text as code. In the stored kind, an attacker types something like <script> or <img src=x onerror=...> into a public form field. Your site saves it. Later an employee opens the entries list, the lead in the CRM, or a notification email viewer, and the saved text is rendered as HTML instead of plain text. The script then runs with that employee's permissions.

How a stored XSS payload travels
  1. Attacker submits formMessage field contains script code
  2. Site saves entryStored in the database as submitted
  3. Admin opens entryValue printed as raw HTML
  4. Script runsActs as the logged-in user
  5. Account or data takenSession, leads or settings exposed

The break happens when the admin screen prints the saved value without escaping it.

Why it costs you leads or sales

The script runs as your staff member. It can read what they can read, change what they can change, or create a new admin user. That puts your lead database, customer details, form settings and integrations at risk.

The business cost is indirect but large. An attacker can redirect form notifications, insert malicious code on your public pages, or export contacts. Leads can be lost or leaked, ad accounts can be flagged if your pages start serving malware, and you may have to notify customers under data protection rules.

Example: how an attack unfolds
  1. Day 1

    A bot submits your contact form with a script in the message field.

  2. Day 1

    The entry looks like ordinary spam in the list.

  3. Day 2

    A team member opens it while logged in; the script runs silently.

  4. Day 2

    A hidden admin user is created or a session token is sent out.

  5. Day 3

    You escape output, update the plugin and rotate passwords.

How to check if your site has it

Only test sites you own or have written permission to test. Do it on a staging copy if you can, because a working payload will run in your own browser when you open the entry.

Test a form for stored XSS safely
  1. Use a harmless marker payload

    Submit a test entry with <b>xsstest</b> in each text field. Open the entry in the admin. If the text appears in bold instead of showing the tags, output is not escaped.

  2. Try an image payload

    Submit <img src=x onerror=alert(document.domain)>. If a popup appears when you open the entry, the flaw is confirmed.

  3. Check every place the data shows

    Look at the entries list, the single entry view, exports, dashboard widgets, email previews and any CRM or helpdesk that receives the lead.

  4. Run an automated scan

    Use a web application security scanner against staging. It will try many payloads and form fields that you would not think to test by hand.

  5. Delete your test entries

    Remove the test submissions from the database and from any connected tool afterwards.

How to fix it

The core rule: escape on output. Treat every submitted value as plain text when you display it, whatever was checked when it was saved. Validating input is a useful second layer, but output escaping is what stops the script running.

Fix by platform
  1. Update everything

    Update WordPress core, your form plugin and any entries or CRM add-ons. Stored XSS in form plugins is often fixed in a patch release. Check the plugin's changelog.

  2. Replace abandoned plugins

    If the form plugin no longer gets updates, move to a maintained one.

  3. Escape output in custom code

    In your own templates or admin screens, wrap values with esc_html(), esc_attr() or wp_kses_post() when printing. Sanitise input with sanitize_text_field() or sanitize_textarea_field().

  4. Limit who sees entries

    Give entry access only to roles that need it under Users and your form plugin's permissions settings.

WordPress: sanitise on save, escape on outputphp
<?php
// On save
$message = sanitize_textarea_field( wp_unslash( $_POST['message'] ?? '' ) );

// On output (admin screen or template)
echo '<p>' . esc_html( $message ) . '</p>';
Show submitted text without running itjavascript
const cell = document.querySelector('#entry-message');
// Unsafe: cell.innerHTML = entry.message;
cell.textContent = entry.message; // safe: shown as plain text
Add a second layer of defence
  1. Add a Content-Security-Policy to the admin area

    A policy that blocks inline scripts and unknown script sources stops many payloads even if one escape is missed. Test in report-only mode first.

  2. Set cookies as HttpOnly

    HttpOnly session cookies cannot be read by scripts, which limits what an injected script can steal.

  3. Clean existing entries

    Search the entries table for <script, onerror= and javascript:. Delete suspicious entries and check for admin users or settings you do not recognise.

  4. Rotate credentials if you opened a payload

    If a staff member opened a working payload while logged in, reset their password, end all sessions and review recent changes.

Example CSP header for an admin area (test in report-only first)nginx
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'self'" always;
What changes after the fix

Before

  • Entry text printed as raw HTML
  • A payload runs when staff open the entry
  • No policy limiting scripts in the admin

After

  • Entry text escaped and shown as plain text
  • Payload appears as harmless visible characters
  • CSP blocks inline scripts as a backup

How to confirm it's fixed

Confirmation checks
  • Submit <b>xsstest</b> again and see the literal tags in every place the entry appears
  • The image payload no longer shows a popup in the list, detail view, export and CRM
  • Browser console shows no CSP violations from normal admin use
  • No unknown admin users, API keys or form notification addresses exist
  • A repeat automated scan reports no XSS findings

How to prevent it happening again

Prevention habits
  • Turn on automatic updates for form plugins and CMS core where you can
  • Remove plugins and apps you do not use
  • Escape on output in all custom code and review it in code reviews
  • Give staff the lowest role they need, and use 2FA on admin accounts
  • Open suspicious entries in a plain-text view or export, not the live admin
  • Run a security scan after each major change to forms or the admin
  • Add a Content-Security-Policy and keep it in your release checklist

How FunnelGuard handles this

This issue is outside what FunnelGuard checks. FunnelGuard runs your customer journeys with a robot visitor and checks that forms submit, tracking fires and test leads arrive. It does not test whether submitted text is escaped in your admin, and it does not hunt for injection flaws.

The kind of tool that fits is a web application security scanner (dynamic application security testing) run against a staging copy, or a penetration test by a qualified tester. For WordPress, a vulnerability scanner that tracks known plugin flaws also helps. FunnelGuard can still help you confirm that your form keeps working after you change it, since it submits a marked test lead and checks it reaches the inbox and CRM.

Questions people ask

What is stored XSS in a contact form?

Stored XSS is when a form saves script code that an attacker typed in, and your site later shows it as live HTML. The script runs in the browser of whoever opens it, often a logged-in admin. The attacker never needs an account.

Why does a script in my form entry run when I open it in the admin?

The admin screen is printing the saved value as raw HTML instead of plain text. The browser cannot tell your content from the attacker's code. Escaping the value on output, for example with esc_html() in WordPress, fixes it.

How do I test my form for stored XSS safely?

On a site you own, preferably staging, submit <b>xsstest</b> and open the entry. If it shows in bold instead of as visible tags, output is not escaped. Then try an image onerror payload to confirm, and delete your test entries afterwards.

Is sanitising input enough to stop stored XSS?

No. Sanitising on input helps, but the reliable defence is escaping on output for the right context (HTML, attribute, JavaScript or URL). Data can reach the page from imports, APIs and old records that skipped input checks.

Can a CAPTCHA or spam filter prevent stored XSS?

Not reliably. They reduce bot volume, but a human or a bypassing tool can still submit a payload. The fix has to be in how your admin or CRM displays the data.

What should I do if a staff member opened a malicious form entry?

Delete the entry, reset that person's password, end all active sessions and check for new admin users, changed notification emails and unknown plugins or API keys. Then fix the output escaping and update the form tool.

Does a Content-Security-Policy stop stored XSS?

A strict policy that blocks inline scripts can stop many payloads from running, so it is a strong backup. It does not replace escaping output. Use both.

Does FunnelGuard detect XSS in form submissions?

No. FunnelGuard checks that your journeys, tracking and lead delivery work. For XSS, use a web application security scanner or a penetration test.

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.