The root cause of the vulnerability is an authentication bypass in the phpMyFAQ\Controller\AbstractController::hasValidToken function. This function is responsible for validating the API token for several write-access API endpoints. The vulnerability is triggered because the application, by default, initializes the API token (api.apiClientToken) to an empty string during installation. The hasValidToken function used a strict inequality comparison (!==). When an attacker sends a request with an empty x-pmf-token header to a vulnerable endpoint, the check becomes '' !== '', which evaluates to false, thereby incorrectly validating the request and bypassing authentication. This allows an unauthenticated attacker to create and modify content such as FAQs, categories, and questions.
The patch addresses this in three key places:
AbstractController.php: The hasValidToken function is modified to first check if the configured token is empty and reject the request if so. It also replaces the weak comparison with the constant-time hash_equals function to prevent timing attacks.
Installer.php: The installation logic is changed in startInstall to generate a cryptographically secure random token, ensuring new installations are not vulnerable by default.
Update.php: A new update step, applyUpdates413, is added to check for and replace empty tokens in existing installations, remediating systems that are already deployed with the insecure default.