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.
Vulnerable code (phpmyfaq/src/phpMyFAQ/User/CurrentUser.php, lines 513-534):
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):
$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.
Prerequisites: phpMyFAQ instance with Azure AD / Entra ID authentication enabled.
Bob registers an Azure AD account with display name x]","email":"x',(SELECT SLEEP(5)))-- -.
Bob initiates the OAuth login flow on the target phpMyFAQ.
After authorization, the token endpoint returns a JWT with the crafted claim.
phpMyFAQ calls setTokenData() with the unsanitized token array. The resulting SQL becomes:
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.
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.")
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)
Escape all interpolated values using $this->configuration->getDb()->escape(), matching the pattern used by setAuthSource() and setRememberMe() in the same file:
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 | Affected versions |
|---|---|
thorsten / phpmyfaq
|
< 4.1.2 |
phpmyfaq / phpmyfaq
|
< 4.1.2 |
A security vulnerability is a weakness in software, hardware, or configuration that can be exploited to compromise confidentiality, integrity, or availability. Many vulnerabilities are tracked as CVEs (Common Vulnerabilities and Exposures), which provide a standardized identifier so teams can coordinate patching, mitigation, and risk assessment across tools and vendors.
CVSS (Common Vulnerability Scoring System) estimates technical severity, but it doesn't automatically equal business risk. Prioritize using context like internet exposure, affected asset criticality, known exploitation (proof-of-concept or in-the-wild), and whether compensating controls exist. A "Medium" CVSS on an exposed, production system can be more urgent than a "Critical" on an isolated, non-production host.
A vulnerability is the underlying weakness. An exploit is the method or code used to take advantage of it. A zero-day is a vulnerability that is unknown to the vendor or has no publicly available fix when attackers begin using it. In practice, risk increases sharply when exploitation becomes reliable or widespread.
Recurring findings usually come from incomplete Asset Discovery, inconsistent patch management, inherited images, and configuration drift. In modern environments, you also need to watch the software supply chain: dependencies, containers, build pipelines, and third-party services can reintroduce the same weakness even after you patch a single host. Unknown or unmanaged assets (often called Shadow IT) are a common reason the same issues resurface.
Use a simple, repeatable triage model: focus first on externally exposed assets, high-value systems (identity, VPN, email, production), vulnerabilities with known exploits, and issues that enable remote code execution or privilege escalation. Then enforce patch SLAs and track progress using consistent metrics so remediation is steady, not reactive.
SynScan combines attack surface monitoring and continuous security auditing to keep your inventory current, flag high-impact vulnerabilities early, and help you turn raw findings into a practical remediation plan.