Skip to content
Access control Disclosed report Intermediate

WooCommerce Blacklist in 'map_meta_cap' leads to Privilege Escalation of Shopmanagers

WooCommerce's capability filter only blocks a Shop manager from editing users who are administrators, so a Shop manager can still change any other user's role and password. An attacker with a Shop manager account could assign a role such as editor to a customer, take over that account and use it to plant stored JavaScript, which the report says can lead to admin compromise.

simonscannell Follow

Originally disclosed on HackerOne

  • Fixed in 49 days
  • Paid in 50 days
  • Disclosed after 16 months

When the Shopmanager role is defined for the first time, it receives the following WordPress core privileges:

	// Shop manager role.
		add_role(
			'shop_manager',
			'Shop manager',
			array(
				'level_9'                => true,
				'level_8'                => true,
				'level_7'                => true,
				'level_6'                => true,
				'level_5'                => true,
				'level_4'                => true,
				'level_3'                => true,
				'level_2'                => true,
				'level_1'                => true,
				'level_0'                => true,
				'read'                   => true,
				'read_private_pages'     => true,
				'read_private_posts'     => true,
				'edit_users'             => true,
				'edit_posts'             => true,
				'edit_pages'             => true,
				'edit_published_posts'   => true,
				'edit_published_pages'   => true,
				'edit_private_pages'     => true,
				'edit_private_posts'     => true,
				'edit_others_posts'      => true,
				'edit_others_pages'      => true,
				'publish_posts'          => true,
				'publish_pages'          => true,
				'delete_posts'           => true,
				'delete_pages'           => true,
				'delete_private_pages'   => true,
				'delete_private_posts'   => true,
				'delete_published_pages' => true,
				'delete_published_posts' => true,
				'delete_others_posts'    => true,
				'delete_others_pages'    => true,
				'manage_categories'      => true,
				'manage_links'           => true,
				'moderate_comments'      => true,
				'upload_files'           => true,
				'export'                 => true,
				'import'                 => true,
				'list_users'             => true,
			)
		);

Most interestingly is the following privilege:

'edit_users'             => true,

With edit_users privileges, Shop managers can by default edit any user and set any user to any user role (including Admin). Since this is obviously not desirable, WordPress added meta capabilities. This allows to restrict Shop managers to not simply assign themselves Admin privileges.

WooCommerce implements these restrictions the following way:

/**
 * Modify capabilities to prevent non-admin users editing admin users.
 *
 * $args[0] will be the user being edited in this case.
 *
 * @param  array  $caps    Array of caps.
 * @param  string $cap     Name of the cap we are checking.
 * @param  int    $user_id ID of the user being checked against.
 * @param  array  $args    Arguments.
 * @return array
 */
function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) {
	switch ( $cap ) {
		case 'edit_user':
		case 'remove_user':
		case 'promote_user':
		case 'delete_user':
			if ( ! isset( $args[0] ) || $args[0] === $user_id ) {
				break;
			} else {
				if ( user_can( $args[0], 'administrator' ) && ! current_user_can( 'administrator' ) ) {
					$caps[] = 'do_not_allow';
				}
			}
			break;
	}
	return $caps;
}
add_filter( 'map_meta_cap', 'wc_modify_map_meta_cap', 10, 4 );

Whenever any capability related to users is in question, WooCommerce disallows it if the target for the modification is an admin.

However, this "blacklist" kind of approach is insufficient. The consequence is that a Shop manager can modify any user and can assign any user role that is not admin.

This means that if I were to hack a Shopmanager account, who does NOT posses the "unfiltered_html" capability, I can simply assign the user role editor, which does have the ability to post JavaScript code, to a random user or customer, change their password, log in and then get a Stored XSS working and hack the admin.

Also, if there are any other custom user roles registered on a Wordpress installation, I can also assign those to me.

For example, the Plugin https://de.wordpress.org/plugins/backwpup/ registers the user type BackWpUp Admin, a user who can create and download backups of the WordPress installation.

Proof of Concept:

Simply login as a Shop manager, set the user role of a random user (e.g. a customer) to editor, change their password and then log into WordPress as that user. Then create a Post with your JavaScript Payload.

Impact

Since Stored XSS is a very reliable way to escalate your privileges to Admin and this is occurs in every WooCommerce installation, I marked this as a high impact.

The original report as published on HackerOne, by simonscannell. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

WooCommerce defines a shop_manager role when it is first set up. That role is intended to let a store owner delegate day-to-day shop administration without handing over full WordPress administrator rights. The report examines what happens when the role's WordPress core capabilities are combined with WooCommerce's own restriction on editing users, and shows that the restriction can be bypassed to escalate a Shop manager to administrator.

The weakness is classified as privilege escalation and was rated high severity. The report was disclosed on 19 December 2019 under the Automattic programme on HackerOne.

Setup

The precondition is a standard WooCommerce installation in which the shop_manager role has been created. The attacker is assumed to hold a Shop manager account. The report considers an attacker who has compromised a Shop manager account. No specific WordPress or WooCommerce version is given in the report.

Finding it

When the Shop manager role is defined for the first time, it receives a long list of WordPress core privileges:

Text
	// Shop manager role.
		add_role(
			'shop_manager',
			'Shop manager',
			array(
				'level_9'                => true,
				'level_8'                => true,
				'level_7'                => true,
				'level_6'                => true,
				'level_5'                => true,
				'level_4'                => true,
				'level_3'                => true,
				'level_2'                => true,
				'level_1'                => true,
				'level_0'                => true,
				'read'                   => true,
				'read_private_pages'     => true,
				'read_private_posts'     => true,
				'edit_users'             => true,
				'edit_posts'             => true,
				'edit_pages'             => true,
				'edit_published_posts'   => true,
				'edit_published_pages'   => true,
				'edit_private_pages'     => true,
				'edit_private_posts'     => true,
				'edit_others_posts'      => true,
				'edit_others_pages'      => true,
				'publish_posts'          => true,
				'publish_pages'          => true,
				'delete_posts'           => true,
				'delete_pages'           => true,
				'delete_private_pages'   => true,
				'delete_private_posts'   => true,
				'delete_published_pages' => true,
				'delete_published_posts' => true,
				'delete_others_posts'    => true,
				'delete_others_pages'    => true,
				'manage_categories'      => true,
				'manage_links'           => true,
				'moderate_comments'      => true,
				'upload_files'           => true,
				'export'                 => true,
				'import'                 => true,
				'list_users'             => true,
			)
		);

The entry that stands out is:

Text
'edit_users'             => true,

With edit_users, a Shop manager can by default edit any user and set that user to any role, including administrator. WordPress addresses this with meta capabilities, which allow a plugin to restrict what a user is permitted to do when the check depends on the object being acted on. WooCommerce uses this mechanism to stop Shop managers from simply granting themselves administrator rights.

Exploitation

Step 1: understand the restriction

WooCommerce implements the restriction through a map_meta_cap filter:

Text
/**
 * Modify capabilities to prevent non-admin users editing admin users.
 *
 * $args[0] will be the user being edited in this case.
 *
 * @param  array  $caps    Array of caps.
 * @param  string $cap     Name of the cap we are checking.
 * @param  int    $user_id ID of the user being checked against.
 * @param  array  $args    Arguments.
 * @return array
 */
function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) {
	switch ( $cap ) {
		case 'edit_user':
		case 'remove_user':
		case 'promote_user':
		case 'delete_user':
			if ( ! isset( $args[0] ) || $args[0] === $user_id ) {
				break;
			} else {
				if ( user_can( $args[0], 'administrator' ) && ! current_user_can( 'administrator' ) ) {
					$caps[] = 'do_not_allow';
				}
			}
			break;
	}
	return $caps;
}
add_filter( 'map_meta_cap', 'wc_modify_map_meta_cap', 10, 4 );

For the user-related capabilities edit_user, remove_user, promote_user and delete_user, the filter checks the target user in $args[0]. If the target is an administrator and the current user is not an administrator, it appends do_not_allow to the capability list, which denies the operation. The check is a blacklist: it only blocks actions whose target is an administrator.

Step 2: identify the gap

The consequence of a blacklist is that everything not on the list is permitted. A Shop manager can therefore modify any user and assign any role that is not administrator.

Step 3: choose a role that leads to code execution

The report describes the escalation path for an attacker who has compromised a Shop manager account that does not possess the unfiltered_html capability. The attacker assigns the editor role to a random user or customer. The editor role has the ability to post JavaScript code. The attacker then changes that user's password, logs in as them, and uses the editor access to get a stored XSS working, which in turn is used to compromise the administrator.

Step 4: consider other custom roles

The report also points out that any other custom user roles registered on the WordPress installation can be assigned to the attacker. As an example, the BackWPup plugin registers a user type called BackWpUp Admin, a user who can create and download backups of the WordPress installation. Assigning such a role to oneself would give access to those capabilities.

Step 5: proof of concept

The proof of concept is described as follows: log in as a Shop manager, set the user role of a random user (for example a customer) to editor, change that user's password, and then log into WordPress as that user. Then create a post containing the JavaScript payload.

Root cause

The role definition grants edit_users to Shop managers, and the compensating control in wc_modify_map_meta_cap only denies operations whose target is an administrator. Because the check is a blacklist rather than an allowlist, any role other than administrator can still be assigned. The report states plainly that this blacklist kind of approach is insufficient. The existing defence therefore does not stop a Shop manager from promoting a controlled account to a role with more dangerous capabilities, such as the editor role with its ability to post JavaScript.

Impact

The report rates this as high impact because stored XSS is a very reliable way to escalate privileges to administrator, and because the issue occurs in every WooCommerce installation. The escalation depends on the attacker having compromised a Shop manager account and being able to assign a role such as editor. The report also notes that custom roles registered by other plugins widen the set of roles an attacker can assign.

Fix

The report does not describe a fix or a change that was made.

Variants to test

  1. Assign a non-administrator role with script-posting ability (such as editor) to a controlled account, change its password, log in, and publish a post containing a JavaScript payload.
  2. Assign any custom role registered by an installed plugin to a controlled account. A positive result is access to the capabilities that role provides, for example backup creation and download for a backup plugin's admin role.
  3. Attempt user-related operations against an administrator target to confirm the blacklist still applies there, then repeat against non-administrator targets to confirm they are allowed.
  4. Test actions on the attacker's own account, where the filter breaks out early because the target equals the current user.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

WooCommerce is a plugin that adds an online shop to a WordPress website. WordPress is the software many people use to run blogs and websites, and it has a system of user roles: administrator, editor, author, and so on. Each role comes with a set of permissions, called capabilities, that decide what a person in that role can do.

WooCommerce adds its own role called Shop manager. The idea is that a shop owner can let a member of staff run the shop day to day without making that person a full administrator of the whole website. The report looks at what a Shop manager can actually do, and shows that the limits WooCommerce puts in place can be worked around. The result is that a Shop manager can end up with administrator power over the site.

This kind of problem is called privilege escalation: someone with a small amount of power finds a way to get a larger amount. The report was rated high severity and disclosed on 19 December 2019 under the Automattic programme on HackerOne. HackerOne is a website where security researchers report bugs to companies, and Automattic is the company behind WordPress and WooCommerce.

The starting point

The report assumes a normal WooCommerce installation where the Shop manager role has been created. The attacker is assumed to have broken into a Shop manager account. The report does not name a specific WordPress or WooCommerce version.

Finding it

The first time the Shop manager role is defined, it is given a long list of WordPress core privileges. Here is the code from the report:

Text
	// Shop manager role.
		add_role(
			'shop_manager',
			'Shop manager',
			array(
				'level_9'                => true,
				'level_8'                => true,
				'level_7'                => true,
				'level_6'                => true,
				'level_5'                => true,
				'level_4'                => true,
				'level_3'                => true,
				'level_2'                => true,
				'level_1'                => true,
				'level_0'                => true,
				'read'                   => true,
				'read_private_pages'     => true,
				'read_private_posts'     => true,
				'edit_users'             => true,
				'edit_posts'             => true,
				'edit_pages'             => true,
				'edit_published_posts'   => true,
				'edit_published_pages'   => true,
				'edit_private_pages'     => true,
				'edit_private_posts'     => true,
				'edit_others_posts'      => true,
				'edit_others_pages'      => true,
				'publish_posts'          => true,
				'publish_pages'          => true,
				'delete_posts'           => true,
				'delete_pages'           => true,
				'delete_private_pages'   => true,
				'delete_private_posts'   => true,
				'delete_published_pages' => true,
				'delete_published_posts' => true,
				'delete_others_posts'    => true,
				'delete_others_pages'    => true,
				'manage_categories'      => true,
				'manage_links'           => true,
				'moderate_comments'      => true,
				'upload_files'           => true,
				'export'                 => true,
				'import'                 => true,
				'list_users'             => true,
			)
		);

Line by line, in plain words:

  • add_role( is a WordPress function that creates a new role. Think of it as opening a new job description and filling in what the person in that job is allowed to do.
  • 'shop_manager', is the internal name of the role, the label the software uses behind the scenes.
  • 'Shop manager', is the human-friendly name that appears on screen.
  • array( starts the list of permissions. Each line inside is one permission set to true, meaning granted.
  • The level_9 down to level_0 lines are old-style numeric levels that WordPress used to use to rank users. Granting all of them gives the role a high rank in that old system.
  • 'read' lets the user read the site.
  • read_private_pages and read_private_posts let them see private pages and posts.
  • 'edit_users' lets them edit user accounts. This is the important one.
  • The edit_*, publish_* and delete_* lines cover posts and pages: editing, publishing and deleting them, including other people's and private ones.
  • manage_categories, manage_links and moderate_comments cover categories, links and comments.
  • upload_files lets them upload files.
  • export and import let them export and import site content.
  • list_users lets them see the list of users.
  • The closing ); ends the call.

The entry that stands out is:

Text
'edit_users'             => true,

This single line says the Shop manager may edit user accounts. With that permission, a Shop manager can by default edit any user and set that user to any role, including administrator. That is clearly not what a shop owner wants.

To stop this, WordPress has a mechanism called meta capabilities. A normal capability is a simple yes or no, like a key that opens a door. A meta capability is a question that gets answered by looking at the specific thing being acted on: not just "may this person edit users?" but "may this person edit this particular user?". It is like a building pass that says you may enter the archive room, but the guard at the door checks which archive room you mean before letting you in. Plugins can hook into that check and change the answer. WooCommerce uses this to try to stop Shop managers from simply giving themselves administrator rights.

Exploitation

Step 1: understand the restriction

WooCommerce implements its restriction through a map_meta_cap filter. A filter is a hook: WordPress runs its own logic, then hands the result to any plugin that has registered an interest, and the plugin can change that result before it is used. Here is the code from the report:

Text
/**
 * Modify capabilities to prevent non-admin users editing admin users.
 *
 * $args[0] will be the user being edited in this case.
 *
 * @param  array  $caps    Array of caps.
 * @param  string $cap     Name of the cap we are checking.
 * @param  int    $user_id ID of the user being checked against.
 * @param  array  $args    Arguments.
 * @return array
 */
function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) {
	switch ( $cap ) {
		case 'edit_user':
		case 'remove_user':
		case 'promote_user':
		case 'delete_user':
			if ( ! isset( $args[0] ) || $args[0] === $user_id ) {
				break;
			} else {
				if ( user_can( $args[0], 'administrator' ) && ! current_user_can( 'administrator' ) ) {
					$caps[] = 'do_not_allow';
				}
			}
			break;
	}
	return $caps;
}
add_filter( 'map_meta_cap', 'wc_modify_map_meta_cap', 10, 4 );

Line by line, in plain words:

  • The block between /** and */ is a comment. It explains that the function changes permissions to stop non-admins from editing admin users, and that $args[0] is the user being edited.
  • function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) { defines the function. It receives four things: $caps, the list of permissions being decided; $cap, the name of the permission being checked; $user_id, the person doing the action; and $args, extra details, such as who the action is aimed at.
  • switch ( $cap ) { starts a set of cases, like a railway switch that sends the train down one track depending on the value.
  • The four case lines list the permissions this function cares about: edit_user, remove_user, promote_user and delete_user. If the permission being checked is anything else, none of the cases match and the function does nothing.
  • if ( ! isset( $args[0] ) || $args[0] === $user_id ) { asks two questions. Is there no target user given? Or is the target the same person as the one doing the action? If either is true, break; jumps out and the function leaves the permissions unchanged.
  • } else { covers the case where there is a target and it is someone else.
  • if ( user_can( $args[0], 'administrator' ) && ! current_user_can( 'administrator' ) ) { asks: is the target user an administrator, and is the person doing the action not an administrator?
  • $caps[] = 'do_not_allow'; adds a special permission called do_not_allow to the list. That entry is a hard no, so the operation is refused.
  • The closing braces end the inner if, the else, the switch and the function.
  • return $caps; hands the possibly modified permission list back to WordPress.
  • add_filter( 'map_meta_cap', 'wc_modify_map_meta_cap', 10, 4 ); registers the function on the map_meta_cap hook, with priority 10 and four arguments. Priority is the order in which hooks run; a lower number runs earlier.

So for the user-related permissions edit_user, remove_user, promote_user and delete_user, the filter looks at the target user in $args[0]. If the target is an administrator and the current user is not, it denies the operation. This is a blacklist: a list of things that are forbidden. Everything not on the list is allowed.

Step 2: identify the gap

The consequence of a blacklist is that everything not on it is permitted. A Shop manager can therefore modify any user and assign any role that is not administrator.

Step 3: choose a role that leads to code execution

The report describes the escalation path for an attacker who has compromised a Shop manager account that does not possess the unfiltered_html capability. unfiltered_html is a permission that lets a user save raw HTML, including scripts, without WordPress cleaning it. Without it, the user's content is filtered and scripts are stripped out.

The attacker assigns the editor role to a random user or customer. The editor role has the ability to post JavaScript code. The attacker then changes that user's password, logs in as them, and uses the editor access to get a stored XSS working, which in turn is used to compromise the administrator.

Stored XSS, short for cross-site scripting, is a class of bug where an attacker gets malicious JavaScript saved on a website, for example inside a post. When another person, such as an administrator, later opens that page, their browser runs the script as if the site itself had written it. The script can then act with the administrator's session. A session is the state of being logged in; the browser holds a cookie, a small piece of data the site gave it at login, and sends it with every request so the site knows who is asking. If a script runs in the administrator's browser, it can use that cookie to do things as the administrator.

Step 4: consider other custom roles

The report also points out that any other custom user roles registered on the WordPress installation can be assigned to the attacker. As an example, the BackWPup plugin registers a user type called BackWpUp Admin, a user who can create and download backups of the WordPress installation. Assigning such a role to oneself would give access to those capabilities. Backups are copies of the site's files and database, so being able to download them means being able to take a copy of everything the site holds.

Step 5: proof of concept

The proof of concept is described as follows: log in as a Shop manager, set the user role of a random user (for example a customer) to editor, change that user's password, and then log into WordPress as that user. Then create a post containing the JavaScript payload. A payload here is the piece of JavaScript the attacker wants the victim's browser to run.

Root cause

The role definition grants edit_users to Shop managers, and the compensating control in wc_modify_map_meta_cap only denies operations whose target is an administrator. Because the check is a blacklist rather than an allowlist, any role other than administrator can still be assigned. The report states plainly that this blacklist kind of approach is insufficient. The existing defence therefore does not stop a Shop manager from promoting a controlled account to a role with more dangerous capabilities, such as the editor role with its ability to post JavaScript.

Impact

The report rates this as high impact because stored XSS is a very reliable way to escalate privileges to administrator, and because the issue occurs in every WooCommerce installation. The escalation depends on the attacker having compromised a Shop manager account and being able to assign a role such as editor. The report also notes that custom roles registered by other plugins widen the set of roles an attacker can assign.

Fix

The report does not describe a fix or a change that was made. An allowlist is the opposite of a blacklist: instead of naming what is forbidden, it names what is allowed, and everything else is refused.

Variants to test

  1. Assign a non-administrator role with script-posting ability (such as editor) to a controlled account, change its password, log in, and publish a post containing a JavaScript payload.
  2. Assign any custom role registered by an installed plugin to a controlled account. A positive result is access to the capabilities that role provides, for example backup creation and download for a backup plugin's admin role.
  3. Attempt user-related operations against an administrator target to confirm the blacklist still applies there, then repeat against non-administrator targets to confirm they are allowed.
  4. Test actions on the attacker's own account, where the filter breaks out early because the target equals the current user.

Glossary

  • WooCommerce: a plugin that turns a WordPress site into an online shop.
  • WordPress: the software used to build and run many websites and blogs.
  • Plugin: an add-on that extends what a piece of software can do.
  • Role: a named job for a user, such as administrator or editor, that comes with a set of permissions.
  • Capability: a single permission, such as the ability to edit posts or edit users.
  • Meta capability: a permission whose answer depends on the specific object being acted on, such as which user is being edited.
  • Filter / hook: a point where WordPress hands a result to plugin code so the plugin can change it.
  • Privilege escalation: getting more power on a system than you were meant to have.
  • Blacklist: a list of things that are forbidden; everything else is allowed.
  • Allowlist: a list of things that are allowed; everything else is forbidden.
  • Stored XSS: a bug where malicious JavaScript is saved on a site and runs in other people's browsers when they view it.
  • Payload: the piece of code an attacker wants to run.
  • Session: the state of being logged in to a site.
  • Cookie: a small piece of data a site stores in the browser, often used to remember who is logged in.
  • unfiltered_html: a permission that lets a user save raw HTML, including scripts, without it being cleaned.
  • Administrator: the highest-level WordPress role, with full control over the site.
  • Shop manager: the WooCommerce role meant to run the shop without full site control.
  • Editor: a WordPress role that can manage and publish other people's posts.
  • BackWPup: a plugin that creates and downloads backups of a WordPress site.
  • HackerOne: a platform where researchers report security bugs to companies.
  • Automattic: the company behind WordPress and WooCommerce.
  • Severity: a rating of how serious a security issue is.
  • Proof of concept: a step-by-step demonstration that a bug can actually be exploited.

More by simonscannell

View all

13 more disclosed reports, best first.

More from Automattic

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.