Our Plugin Security Checker Warned of Misuse of esc_sql() in WordPress Plugin That Leads to SQL Injection Vulnerability
One of the things we offer to help people keep their WordPress websites protected from vulnerabilities in WordPress plugins is our Plugin Security Checker, which flags the possibility of some instances of security issues in plugins.
To continue to improve the results being produced by that, we occasionally check issues being flagged by that when people run plugins from the WordPress plugin directory through that. Recently the plugin Code Manager was run through that. One of the issues identified was the possible misuse of the esc_sql() function:
As explained by the tool’s message, when escaping SQL input using that function, the input needs to be in quotes, which it isn’t in that code. The lack of that can permit SQL injection, depending on the rest of the code. We confirmed that SQL injection is possible with that code.
That code is located in the function get_codes() in the file /Code_Manager/Code_Manager_List.php. The rest of the code that is used in generating the SQL statement that is open to SQL injection is as follows:
324 325 326 327 328 329 330 331 332 333 334 335 | $sql = "select * from " . $code_manager_model::get_base_table_name(); if ( '' !== $where ) { $sql .= $where; } if ( ! empty( $_REQUEST['orderby'] ) ) { $sql .= ' ORDER BY ' . esc_sql( $_REQUEST['orderby'] ); $sql .= ! empty( $_REQUEST['order'] ) ? ' ' . esc_sql( $_REQUEST['order'] ) : ' ASC'; } $sql .= " LIMIT $per_page"; $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page; $result = $wpdb->get_results( $sql, 'ARRAY_A' ); |
Nothing else in that prevents SQL injection from occurring.
That code runs when accessing the plugin’s admin page, which is limited to Administrators:
259 260 261 262 263 264 265 266 267 | add_menu_page( CODE_MANAGER_MENU_SLUG, CODE_MANAGER_MENU_TITLE, 'manage_options', CODE_MANAGER_MENU_SLUG, null, 'dashicons-editor-code', 999999999 ); |
So this wouldn’t be a vulnerability on its own, as the Administrators normally have the ability to do the equivalent of SQL injection, but this could be exploited through cross-site request forgery (CSRF).
WordPress provides the sanitization function sanitize_sql_orderby() for handling the user input that is being brought in there.
WordPress Causes Full Disclosure
As a protest of the moderators of the WordPress Support Forum’s continued inappropriate behavior we changed from reasonably disclosing to full disclosing vulnerabilities for plugins in the WordPress Plugin Directory in protest, until WordPress gets that situation cleaned up, so we are releasing this post and then leaving a message about that for the developer through the WordPress Support Forum. (For plugins that are also in the ClassicPress Plugin Directory, we will follow our reasonable disclosure policy.)
You can notify the developer of this issue on the forum as well.
Hopefully, the moderators will finally see the light and clean up their act soon, so these full disclosures will no longer be needed (we hope they end soon). You would think they would have already done that, but considering that they believe that having plugins, which have millions installs, remain in the Plugin Directory despite them knowing they are vulnerable is “appropriate action”, something is very amiss with them (which is even more reason the moderation needs to be cleaned up).
If the moderation is cleaned up, it would also allow the possibility of being able to use the forum to start discussing fixing the problems caused by the very problematic handling of security by the team running the Plugin Directory, discussions which they have for years shut down through their control of the Support Forum.
Update: To clear up the confusion where developers claim we hadn’t tried to notify them through the Support Forum (while at the same time moderators are complaining about us doing just that), here is the message we left for this vulnerability:
Is It Fixed?
If you are reading this post down the road the best way to find out if this vulnerability or other WordPress plugin vulnerabilities in plugins you use have been fixed is to sign up for our service, since what we uniquely do when it comes to that type of data is to test to see if vulnerabilities have really been fixed. Relying on the developer’s information can lead you astray, as we often find that they believe they have fixed vulnerabilities, but have failed to do that.
Proof of Concept
The following proof of concept will take varying amounts of time for the page to fully load depending on how long you specify MySQL sleep function to run, when logged in as Administrator.
Replace “[path to WordPress]” with the location of WordPress and “[sleep time]” with how many seconds you want sleep to occur for.
http://[path to WordPress]/wp-admin/admin.php?page=code_manager&orderby=1 AND SLEEP ([sleep time])