# CVE-2024-0685 Ninja Contact Forms Data Export SQLi

Ninja Forms WordPress plugin concatenated user email into raw SQL in get_subs_by_email during GDPR data export, allowing SQL injection via quote-containing email to dump all submissions.

- Payout: $165
- Severity: medium
- Program: Wordfence
- Found by: Matthew Rollings
- Disclosed: 2024-02-10
- Write-up quality: 6/10
- Original: https://sec.stealthcopter.com/ninja-contact-forms/
- Library page: https://bugbountylibrary.com/r/blog%3Asec-stealthcopter-com-ninja-contact-forms
- Tags: area:web domain:web impact:data-leak impact:pii-leak kind:bounty platform:blog sev:medium tech:php tech:wordpress technique:second-order vuln:sqli

**Target:** WordPress plugin Ninja Forms Contact Form, data export request handler (get_subs_by_email)
**Root cause:** User-supplied email address is concatenated directly into a raw SQL WHERE clause instead of using prepared statements, and sanitize_email/filter_var permit single quotes per RFC 5322.
**Steps:**
1. Identify that data export requests pass requester email into get_subs_by_email raw SQL query.
2. Craft email with single quote and SQL comment separators since spaces are invalid: `QuiRkyEmAil'/**/OR/**/1!='@stealthcopter.com`.
3. Submit a GDPR data export request using that email address.
4. Admin triggers export; query becomes `WHERE m.meta_value = 'QuiRkyEmAil'/**/OR/**/1!='@stealthcopter.com'` returning all rows.
5. Export file contains all user submissions.
**How found:** Code review of the export handler noticed email concatenated into raw SQL; then reasoned that RFC 5322 permits single quotes in the local part and that WordPress sanitize_email/filter_var allow them, enabling quote escape.
**Exploitation:** Attacker submits a data export request with a malicious email; when an admin processes the export, the injected SQL returns every submission row, and the resulting export file leaks all user data to the attacker.
**Escalation:** GDPR legal requirement to honor export requests raises likelihood an admin performs the export, turning an admin-only action into a realistic attack path.
**Insight:** Email addresses are a viable SQLi/XSS/path-traversal vector because RFC 5322 local parts allow quotes, slashes, asterisks; check which validator (is_email vs sanitize_email vs filter_var) gates the sink, and use /**/ comments when spaces are filtered.

## Proof of concept (copied exactly from the original report)

**Malicious email payload for SQL injection**

```
QuiRkyEmAil'/**/OR/**/1!='@stealthcopter.com
```

