The plugin Rank Math SEO (versions 1.0.107.2 and below), which has over 1,000,000 active installations is known as “The Swiss Army Knife” for WordPress SEO.
This is one of the most popular WordPress SEO Plugins which can be used to help every website owner get access to the SEO tools they need to improve their SEO and attract more traffic to their website.
This plugin suffers from authenticated Local File Inclusion (LFI) vulnerability.
This vulnerability allows any authenticated user with a minimum Contributor role to perform local file inclusion with a limited .php file extension on the WordPress server.
The described vulnerability was fixed in version 1.0.107.3 and assigned CVE-2023-23888
The initial discovery of this vulnerability happened when we analyzed the shortcode features provided by the plugin. One of the shortcodes available is rank_math_rich_snippet that is handled by the rich_snippet function:
The shortcode handler will call get_snippet_content function using a couple of parameters (including the $schema parameter which contains Rank Math schema data of each WP POST) :
plugin_dir() . "includes/modules/schema/shortcode/$type.php";
if ( file_exists( $file ) ) {
include $file;
}
Notice that the $file variable will be built using the $type variable and will be included in the code. The $type variable is built from $schema['@type'] variable.
In this case, if we are able to control that variable, we could achieve path traversal resulting to limited arbitrary .php Local File Inclusion.
As a Contributor role user, we could set a Rank Math schema of each WP POST by making a POST request to /wp-json/rankmath/v1/updateSchemas with this JSON data:
We inject the path traversal payload on the schemas["@type"] field. After setting up the schema, we just need to draft a new WP POST containing the shortcode string as a content :
[rank_math_rich_snippet post_id=""]
Viewing the drafted WP POST will trigger the LFI. The ideal attack scenario would need other vulnerability to inject or upload PHP code to a .php file on the WordPress server. If the file could not be reached directly, we are able to utilize this LFI vulnerability.
The patch in Rank Math SEO
Since this issue is mainly because the code tries to include some part of the file path from user input, the developer decided to filter the data using regex and sanitize_file_name function. The patch can be found here:
Disclosure timeline
26-01-2022 – We found the vulnerability in Rank Math SEO and compiled a vulnerability report. 29-01-2022 – We reached out to the plugin vendor. 30-01-2022 – Rank Math SEO plugin version 1.0.107.3 was published to patch the reported issues. 10-02-2023 – Added the vulnerabilities to the Patchstack vulnerability database. 14-02-2023 – Published the article.
Help us make the web a safer place
Making the WordPress ecosystem more secure is a team effort, and we believe that plugin developers and security researchers should work together.
If you’re a plugin developer, join our mVDP program that makes it easier to report, manage and address vulnerabilities in your software.
If you’re a security researcher, join Patchstack Alliance to report vulnerabilities & earn rewards.