Alta

phpMyFAQ has SQL Injection in CurrentUser::setTokenData through unescaped OAuth token fields

  • Publicada: 06.05.2026
  • Actualizado: 11.10.2026 10:22

Summary

CurrentUser::setTokenData() in phpmyfaq/src/phpMyFAQ/User/CurrentUser.php at lines 515-534 builds a SQL UPDATE statement with sprintf and interpolates OAuth token fields (refresh_token, access_token, code_verifier, and json_encode($token['jwt'])) without calling $db->escape(). Sibling methods setAuthSource() and setRememberMe() in the same file do call $db->escape() on user-controlled values, so the omission is local to this method. An attacker (Bob) whose Azure AD display name contains a single quote (for example O'Brien, or a deliberate SQL payload) breaks out of the string literal and injects arbitrary SQL against the phpMyFAQ database.

Details

Vulnerable code (phpmyfaq/src/phpMyFAQ/User/CurrentUser.php, lines 513-534):

php
public function setTokenData(#[\SensitiveParameter] array $token): bool
{
    $update = sprintf(
        "
        UPDATE
            %sfaquser
        SET
            refresh_token = '%s',
            access_token = '%s',
            code_verifier = '%s',
            jwt = '%s'
        WHERE
            user_id = %d",
        Database::getTablePrefix(),
        $token['refresh_token'],
        $token['access_token'],
        $token['code_verifier'],
        json_encode($token['jwt'], JSON_THROW_ON_ERROR),
        $this->getUserId(),
    );

    return (bool) $this->configuration->getDb()->query($update);
}

json_encode() does NOT escape single quotes. A JWT claim such as {"preferred_username": "O'Malley"} produces {"preferred_username":"O'Malley"} after json_encode, which terminates the SQL string literal at the apostrophe.

Correct pattern in the same file (setAuthSource, line 458-461):

php
$update = sprintf(
    "UPDATE %sfaquser SET auth_source = '%s' WHERE user_id = %d",
    Database::getTablePrefix(),
    $this->configuration->getDb()->escape($authSource),
    $this->getUserId(),
);

setRememberMe() (line 471-478) follows the same safe pattern with $db->escape().

Reachability: The phpMyFAQ Azure AD (Entra ID) OAuth flow calls setTokenData() after token exchange. The token response includes an id_token whose payload originates from the identity provider. An attacker registers a Microsoft account with a display name or custom claim containing SQL metacharacters. When that user logs into a phpMyFAQ instance with Azure AD auth enabled, the malicious claim flows into the UPDATE without sanitization.

Proof of Concept

Prerequisites: phpMyFAQ instance with Azure AD / Entra ID authentication enabled.

  1. Bob registers an Azure AD account with display name x]","email":"x',(SELECT SLEEP(5)))-- -.

  2. Bob initiates the OAuth login flow on the target phpMyFAQ.

  3. After authorization, the token endpoint returns a JWT with the crafted claim.

  4. phpMyFAQ calls setTokenData() with the unsanitized token array. The resulting SQL becomes:

sql
UPDATE faquser
SET
    refresh_token = '<valid>',
    access_token = '<valid>',
    code_verifier = '<valid>',
    jwt = '{"preferred_username":"x',(SELECT SLEEP(5)))-- -"}'
WHERE
    user_id = 42

The single quote after x closes the jwt string literal. Everything after it executes as attacker-controlled SQL.

  1. To confirm time-based blind injection locally (requires modifying the OAuth token response in a proxy):
python
import requests

# Simulates what happens when the crafted JWT claim reaches the DB
# In production, this happens automatically through the OAuth flow
payload = "x'||(SELECT SLEEP(5))||'"

# The interpolated query will pause for 5 seconds, confirming injection
print(f"Injected jwt value: {payload}")
print("If the login takes 5+ seconds longer than normal, injection succeeded.")

Impact

An attacker who can authenticate via Azure AD with a crafted claim achieves arbitrary SQL execution on the phpMyFAQ database. This permits reading all FAQ data (including restricted entries), modifying or deleting content, and extracting password hashes and session tokens of all users including administrators.

CWE: CWE-89 (SQL Injection)

Recommended Fix

Escape all interpolated values using $this->configuration->getDb()->escape(), matching the pattern used by setAuthSource() and setRememberMe() in the same file:

php
public function setTokenData(#[\SensitiveParameter] array $token): bool
{
    $db = $this->configuration->getDb();
    $update = sprintf(
        "
        UPDATE
            %sfaquser
        SET
            refresh_token = '%s',
            access_token = '%s',
            code_verifier = '%s',
            jwt = '%s'
        WHERE
            user_id = %d",
        Database::getTablePrefix(),
        $db->escape($token['refresh_token']),
        $db->escape($token['access_token']),
        $db->escape($token['code_verifier']),
        $db->escape(json_encode($token['jwt'], JSON_THROW_ON_ERROR)),
        $this->getUserId(),
    );

    return (bool) $db->query($update);
}

Found by aisafe.io

Software afectado

Haz clic en una tecnología para ver todas sus vulnerabilidades.

PlataformaPaqueteVersiones vulnerablesCorregida en
Paquete de Composer phpmyfaq/phpmyfaq < 4.1.2 4.1.2
Paquete de Composer thorsten/phpmyfaq < 4.1.2 4.1.2

Referencias

Puntuación CVSS 7.5/10
Vector CVSS
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H
Debilidad (CWE)
CWE-89
Plataforma
Composer
Paquete
phpmyfaq/phpmyfaq, thorsten/phpmyfaq
Publicada
06.05.2026
Actualizado
11.10.2026 10:22

Fuentes y licencias

OSV / GitHub Advisory Database - GHSA-pm8c-3qq3-72w7 - CC BY 4.0

Historial de vulnerabilidades: phpmyfaq/phpmyfaq

Todas las vulnerabilidades publicadas de este paquete (Paquete de Composer), de la más reciente a la más antigua. Muestra si es un fallo aislado o un paquete que hay que vigilar.

Todas (47) en el archivo
Entradas en total
47
Primera → última
10.2022 09.2026
Sin corrección
2
Explotada en ataques
0

Distribución por gravedad

  • Crítica 2
  • Alta 18
  • Media 25
  • Baja 2

Divulgaciones por año

  1. 2022: 1
  2. 2023: 0
  3. 2024: 11
  4. 2025: 3
  5. 2026: 32
Gravedad:
  1. Alta · 8.1 CVE-2026-56737 >= 3.2.0, < 4.1.6 4.1.6
  2. Alta · 7.5 CVE-2026-35672 < 4.1.3 4.1.3
  3. Alta · 8.8 CVE-2026-35671 < 4.1.3 4.1.3
  4. phpMyFAQ has SQL Injection in CurrentUser::setTokenData through unescaped OAuth token fields esta entrada
    Alta · 7.5 CVE-2026-46359 < 4.1.2 4.1.2
  5. Alta · 7.6 CVE-2026-46367 >= 4.1.1, < 4.1.2 4.1.2
  6. Alta · 7.2 CVE-2024-28105 >= 3.2.5, < 3.2.6 3.2.6
  7. Alta · 8.8 CVE-2024-28107 >= 3.2.5, < 3.2.6 3.2.6
  8. Alta · 8.8 CVE-2024-27299 >= 3.2.5, < 3.2.6 3.2.6
  9. Alta · 8.4 CVE-2022-3608 < 3.2.0-alpha 3.2.0-alpha

Identifica las vulnerabilidades de tu aplicación

Con la integración de DockRay y el inventario de software activado, DockRay compara las versiones notificadas de los componentes con las vulnerabilidades conocidas y avisa de las coincidencias confirmadas. La cobertura depende de la tecnología compatible y de los avisos disponibles.

Conectar tu aplicación
Newsletter DockRay

La seguridad de tus aplicaciones en tu correo

Vulnerabilidades importantes, recomendaciones concretas y consejos prácticos para tus aplicaciones. Elige tus tecnologías y sigue lo que importa para tu proyecto.

  • Un resumen diario de nuevas vulnerabilidades, también las críticas.
  • Avisos sobre actualizaciones importantes.
  • Consejos prácticos sobre seguridad y monitorización de aplicaciones.

Déjalo vacío para recibir avisos de todas las tecnologías.

Suscripción gratuita. Date de baja con un clic en cualquier correo.