Skip to content

Header-injection abuse on cPanel-hosted contact forms

How attackers exploit unsanitized contact forms on cPanel sites to inject SMTP headers and send mail via your domain, and how to detect and stop it before reputation goes south.

A WordPress site on a cPanel server suddenly appears in spam reports. Logs show outbound mail from a noreply@ address with subjects in languages nobody on the team speaks. The compromise isn’t on the cPanel side — it’s a contact form on the site whose code passes user input straight to mail headers without sanitizing newlines. Each form submission injects new To:, Cc:, and Bcc: lines and sends a campaign through your domain. This pattern dates from 2005 and still shows up in 2026 because plenty of legacy PHP forms never had the bug fixed.

What’s happening

A naive contact form takes form input and passes it to PHP’s mail() function. If the form accepts a “name” or “email” field without filtering newlines, an attacker submits a string like attacker@evil.com\r\nBcc: target1@example.com,target2@example.com,... and the resulting mail headers include a Bcc to thousands of recipients. The cPanel server delivers as instructed — it sees a legitimate authenticated send from PHP — and the abuse continues until the form is fixed or the attacker moves on.

How to verify

Find recent unusual outbound from PHP scripts:

grep "U=<user> .*<= " /var/log/exim_mainlog | grep -E "(cwd=.*public_html)" | head
exim -bp | awk '{print $4}' | grep -v "^$" | sort | uniq -c | sort -rn | head

Look for cwd values pointing at contact-form pages and senders that don’t look like the legitimate site mailbox. For specific evidence of injection, look for messages with unusual numbers of recipients per send.

The fix

  1. Identify the vulnerable form. Search the user’s site for mail() and wp_mail() calls and follow the input chain to the form fields. The vulnerable pattern is concatenating user input into the From, Reply-To, Subject, or To headers without str_replace("\r\n", "", $input) or equivalent.
  2. Patch the form. Strip newlines from every header input field. Use a library function — WordPress’s wp_mail() with proper headers array, or PHP’s filter_var($email, FILTER_VALIDATE_EMAIL) — rather than rolling your own validator.
  3. For WordPress sites, the issue is often in a plugin. Audit recent plugin updates and disable the suspect plugin while testing. The Contact Form 7, WPForms, and Gravity Forms families have all had injection issues historically; keep them current.
  4. Block the attack at the cPanel level temporarily. WHM > Security Advisor and the ConfigServer Firewall (CSF) can detect and block IPs sending bursts of form submissions. ModSecurity rules covering Bcc: and Cc: headers in POST bodies catch many variants.
  5. Reset reputation if the abuse ran for hours. See the reputation-rebuild KB. Throttle outbound, audit DMARC reports, and watch Postmaster Tools.
  6. Audit every form on every site at takeover. A new cPanel customer’s contact-form code is usually older than their last website redesign. The bugs are easy to find when you go looking.

For environments where customer sites have a long tail of forms that need ongoing audit, Stack Harbor folds form security into managed cPanel operations.