/

CVE-2026-46364

Severity:

CRITICAL RISK

(9.8)

SQL Injection in phpMyFAQ Captcha API

CVE-2026-46364

Deferred

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Database Compromise and Sensitive Data Exposure

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

phpMyFAQ contains an unauthenticated SQL injection flaw where the BuiltinCaptcha::garbageCollector() and BuiltinCaptcha::saveCaptcha() methods interpolate unsanitized User-Agent headers directly into DELETE and INSERT queries.

By sending crafted requests to the public /api/captcha endpoint, an attacker can perform time-based blind SQL injection and potentially extract sensitive data such as user credentials, admin tokens, and SMTP configuration secrets from the database.

Affected context

This vulnerability occurs in phpMyFAQ deployments that expose the /api/captcha endpoint without additional access control or filtering.

The issue arises when the application's built-in CAPTCHA implementation logs or stores User-Agent strings and passes them into SQL statements without proper escaping, binding, or validation.

Environments with reachable database backends and valuable secrets stored in the phpMyFAQ database—such as user accounts, administrative session data, or outbound email credentials—are particularly at risk.

Exploit preconditions

  • Attack surface: Public HTTP interface via GET /api/captcha
  • Required access: No authentication; attacker only needs network access to the phpMyFAQ instance
  • Trigger point: BuiltinCaptcha::garbageCollector() and BuiltinCaptcha::saveCaptcha() when they construct SQL DELETE and INSERT statements using the incoming User-Agent header
  • Why exploitation is possible: The User-Agent header is treated as trusted data and is interpolated directly into SQL queries (string concatenation) instead of being handled with parameterized statements or sanitized, enabling time-based blind SQL injection

Why this happens

The root cause aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

The BuiltinCaptcha methods use dynamically constructed SQL statements that embed the raw User-Agent header without neutralizing control characters (such as quotes, delimiters, and operators). This pattern treats attacker-controlled input as part of the SQL command structure rather than as data.

Because the endpoint is unauthenticated and uses a common header field as input, the SQL injection becomes reachable by default, turning a routine logging or persistence feature into a high-impact injection point.

Potential impact

  • Unauthorized extraction of sensitive data such as:
  • Usernames, email addresses, and hashed passwords
  • Admin session tokens or API tokens
  • SMTP and other integration credentials stored in the database
  • Enumeration of database schema and internal configuration tables
  • Tampering with application data, including inserting or deleting records
  • Creation of backdoor administrative accounts or elevation of existing user privileges
  • Potential pivoting to other systems that rely on credentials stored in the phpMyFAQ database

General mitigation guidance

Effective mitigation focuses on breaking the direct trust relationship between incoming HTTP headers and SQL statements.

Recommended defensive patterns include:

  • Using parameterized queries (prepared statements) for all database access, ensuring user-controlled values are always bound as data, not concatenated into SQL strings.
  • Applying strict input handling for header-derived values, including length limits, character whitelists, and canonicalization; treat HTTP headers as untrusted input on par with query parameters.
  • Centralizing database access patterns behind a data access layer that enforces safe query construction by default.
  • Minimizing storage of unnecessary header information and avoiding storing raw headers in relational schemas unless absolutely required.
  • Reducing the privilege of the database account used by the application (e.g., least-privilege accounts that cannot access unrelated tables or perform dangerous operations).

How teams detect issues like this

Detection strategies can combine code-level analysis with behavioral monitoring:

  • Static analysis and code review:
  • Search for SQL query construction that concatenates request-derived data, particularly HTTP headers such as User-Agent, into query strings.
  • Flag any direct use of user input in WHERE, VALUES, or ORDER BY clauses without binding or escaping.
  • Enforce coding standards that mandate parameterized queries and disallow ad-hoc string-based SQL assembly.
  • Automated tooling:
  • Use static application security testing (SAST) tools configured with rules for CWE-89 to detect unsafe SQL construction patterns.
  • Incorporate pull-request checks that inspect changes to database access code for adherence to safe query patterns.
  • Runtime monitoring:
  • Enable database logging for anomalous queries (e.g., queries containing suspicious timing constructs or unusual User-Agent strings).
  • Use web application firewalls (WAF) or reverse proxies to flag or block requests with typical SQL injection signatures in headers, including User-Agent.

Sources

SourceLink
github.comgithub.com/thorsten/phpMyFAQ/commit/b9f25109fddb38eee19987183798638d07943f92
github.comgithub.com/thorsten/phpMyFAQ/security/advisories/GHSA-289f-fq7w-6q2w
vulncheck.comvulncheck.com/advisories/phpmyfaq-sql-injection-via-user-agent-header-in-builtincaptcha

Frequently asked

questions

The vulnerability is widely exploitable wherever the /api/captcha endpoint is exposed over the network, because it does not require authentication and relies only on the attacker's ability to set a crafted User-Agent header in HTTP requests.

An attacker needs basic network access to the phpMyFAQ instance over HTTP or HTTPS. No valid user account or administrative privileges are required; any client capable of sending HTTP requests with custom headers can attempt exploitation.

The safest pattern is to refactor all affected database operations to use parameterized queries, ensuring that header values and other user-controlled fields are bound as parameters rather than concatenated into SQL strings. This should be accompanied by stricter validation of header inputs and a review of any other code paths that build dynamic SQL.

Prevention relies on adopting secure-by-default data access patterns: standardize on prepared statements, centralize database interactions in a well-reviewed abstraction layer, and enforce linting or static analysis rules that disallow direct string-based SQL construction using request data. Complement this with secure coding guidelines, regular security-focused code reviews, and automated security testing integrated into the development lifecycle.

Find out what's already
exploitable in your codebase.