All posts
Concept ~12 min read

Logged in is not authorized: broken access control in WordPress plugins

A frequent WordPress plugin bug is not SQL injection or XSS but a handler that checks who you are and never what you may do. Covers vertical vs horizontal access, the three request surfaces and the sinks that decide impact.

If you read WordPress vulnerability feeds for a week, one phrase keeps coming back: “Missing Authorization”, usually followed by “Authenticated (Subscriber+)”. There is no clever payload and no encoding trick. A handler does something privileged, and nobody asked whether the caller was allowed to do it.

It keeps happening because WordPress gives plugin authors three or four things that look like security checks and answer a different question. This post walks through them, shows two real cases, and ends with a checklist and grep recipes you can run on your own plugin.

Authentication is not authorization

Two questions that get confused all the time:

  • Authentication: who are you? WordPress answers this with the login cookie. After it, get_current_user_id() returns a number and is_user_logged_in() returns true.
  • Authorization: are you allowed to do this, to this object? WordPress answers this with capabilities: current_user_can( 'manage_options' ), current_user_can( 'edit_post', $post_id ).

Broken access control (CWE-862 Missing Authorization, CWE-863 Incorrect Authorization, CWE-639 for the object-level variant) is what you get when code answers the first question and acts as if it had answered the second.

On a typical web app that confusion is bad. On WordPress it is worse, because the lowest authenticated role is often open to the public.

Why “Subscriber+” matters

A lot of developers read “requires a Subscriber account” as “requires an insider”. It doesn’t.

  • Open registration. “Anyone can register” is a single checkbox in Settings → General, and membership, forum, LMS and booking sites turn it on. The default role for new users is Subscriber.
  • Shops create accounts for buyers. WooCommerce gives every registered buyer the customer role, which has about the same capabilities as Subscriber: read, and little else. Anyone willing to place an order, or just create an account at checkout, has one.
  • The lowest role holds read. Every built-in role has the read capability. Any check that resolves to read is a check for “logged in”.

So when a handler is reachable by any logged-in user, the honest threat model is “anyone on the internet who fills in a form”, not “a trusted colleague”.

A taxonomy of the failure

“Broken access control” is a family of bugs. It helps to name the directions an attacker can move, because the check you are missing depends on which one applies.

Variant What the attacker does WordPress flavour
Vertical privilege escalation Gains capabilities of a higher role Subscriber → Editor → Admin: flipping default_role, setting their own wp_capabilities meta, reaching an admin-only settings write
Horizontal access (IDOR) Acts on another user’s object at the same privilege level Reading or deleting someone else’s order, booking, ticket or uploaded file by changing the id in the request
Missing function-level access control Calls a privileged function that has no guard An AJAX or REST handler that runs update_option() with no current_user_can() at all
Forced browsing Requests a resource not linked in their UI Hitting admin-ajax.php?action=... or a REST route directly, even though the plugin only renders the button for admins

Forced browsing needs a word now; the rest come up below. It is why “the button is only shown to admins” is not a control: the server, not the browser, decides who may call a handler. If the only thing stopping a Subscriber from triggering wp_ajax_myplugin_export_users is a hidden menu item, there is no control. The action name is guessable, documented in the JS, or sitting in the page source.

Role vs capability confusion

WordPress roles (Administrator, Editor, Author, Contributor, Subscriber) are named bundles of capabilities (manage_options, edit_posts, upload_files, read). Authorization decisions must check capabilities, not role names:

  • current_user_can( 'manage_options' ) is correct. It asks the real question.
  • current_user_can( 'administrator' ) is a smell. It happens to work because WordPress treats a role name as a pseudo-capability, but it is fragile: a custom role with manage_options but not literally named administrator fails it, and a site that renames or clones roles breaks in surprising ways.
  • Comparing wp_get_current_user()->roles by hand is worse. It misses multi-role users, superadmins on multisite, and anyone whose capabilities were granted directly.

Check the capability the action needs, and let WordPress resolve which roles hold it.

The three request surfaces

Almost every plugin access-control bug lives on one of three entry points, and each has a default auth posture you have to override deliberately:

Surface Registered with Default audience Make it safe with
admin-ajax.php wp_ajax_{a} / wp_ajax_nopriv_{a} wp_ajax_ = any logged-in user; wp_ajax_nopriv_ = anonymous current_user_can() inside the handler
admin-post.php admin_post_{a} / admin_post_nopriv_{a} same split as above (_nopriv_ = anonymous) current_user_can() inside the handler
REST API register_rest_route( …, [ 'permission_callback' => … ] ) whatever the callback returns a permission_callback that resolves to a real capability

None of these surfaces authorizes anything for you. admin-ajax.php and admin-post.php run under /wp-admin/, which makes them feel privileged, but the _nopriv_ twin needs no cookie and the plain twin is reachable by every Subscriber. The guard is always something you write inside the handler or callback, never the URL it lives behind.

The four checks that aren’t

1. Nonces are CSRF tokens, not permission checks

wp_verify_nonce(), check_ajax_referer() and check_admin_referer() prove that a request came from a page the site generated for this user session, within the last day or so. That stops cross-site request forgery: a malicious page cannot make your browser fire the action, because it cannot read the token.

It does not prove the user is allowed to perform the action. The attacker is not forging someone else’s request; they are sending their own. If the nonce for an action is printed on any page a Subscriber can load (the checkout, the “My account” page, a front-end shortcode), the Subscriber has a valid nonce. For logged-out visitors it is worse: they all share user ID 0, so a nonce printed on a public page is valid for every anonymous visitor.

A very common patternPHP
add_action( 'wp_ajax_myplugin_delete_item', 'myplugin_delete_item' );

function myplugin_delete_item() {
    check_ajax_referer( 'myplugin', 'nonce' );   // CSRF: yes. Permission: no.
    global $wpdb;
    $wpdb->delete( $wpdb->prefix . 'myplugin_items', [ 'id' => absint( $_POST['id'] ) ] );
    wp_send_json_success();
}

Every line here looks careful: there is a nonce check, the ID is cast with absint(), the query is parameterised. The missing line is the one that decides who can delete items.

2. wp_ajax_ means “any logged-in user”, not “admin”

admin-ajax.php lives under /wp-admin/, and handlers are often written next to admin screens, so it is easy to assume they are admin-only. They are not:

  • wp_ajax_{action} fires for any authenticated user, Subscriber included.
  • wp_ajax_nopriv_{action} fires for unauthenticated visitors.

Registering both hooks for one function makes it public. Registering only wp_ajax_ makes it Subscriber+, which, as above, is often also public in practice.

A related trap: is_admin() is not a permission check. It returns true when the request is for an admin page, and every admin-ajax.php request counts. A guard like if ( is_admin() ) { ... } lets a Subscriber straight through.

admin-post.php behaves the same way: admin_post_{action} is any logged-in user, admin_post_nopriv_{action} is anonymous. The same assumption (“it’s under /wp-admin/, so it must be privileged”) produces the same bug there.

3. REST permission_callback that only checks login

REST routes have a dedicated place for authorization, permission_callback, and WordPress has warned since 5.5 when a route omits it. The problem is what people put there:

Three callbacks, increasing correctnessPHP
'permission_callback' => '__return_true',               // public. Fine only for public data.
'permission_callback' => 'is_user_logged_in',           // Subscriber+. Authentication, not authorization.
'permission_callback' => function () {
    return current_user_can( 'manage_options' );        // a real capability for an admin action.
},

__return_true is correct for public endpoints, and the handler must then treat every caller as anonymous. is_user_logged_in is almost never what you mean.

The subtle version is a callback that calls current_user_can() but with a capability every role holds. With a custom post type registered using map_meta_cap => true, the post type’s read capability maps to the primitive read, so current_user_can( $cpt->cap->read ) is is_user_logged_in() in disguise.

4. Object-level authorization (IDOR)

Even with the right capability, you have to check the object. A customer is allowed to view an order; they are allowed to view their order. A handler that takes order_id, booking_id or ticket_id from the request and loads it without checking ownership is an insecure direct object reference: change the number, read or modify someone else’s record.

For posts, WordPress’s meta capabilities do the ownership work for you: current_user_can( 'edit_post', $id ) checks authorship and role. For your own tables and for WooCommerce orders, you have to write the comparison yourself, for example that the order’s customer ID equals get_current_user_id(), or that the caller holds a store-management capability such as manage_woocommerce.

The sinks that decide the impact

A missing check is only as bad as what the handler does next. On a handler that returns a cached counter it is a nuisance; on one that writes options it can hand over the site. Rank unguarded handlers by their sink:

  • update_option() with an attacker-controlled key or value. The options table is WordPress’s global config. A handler that lets a low-privilege user set an arbitrary option leads to vertical privilege escalation: write default_role = administrator and users_can_register = 1, then register, and the next account is an admin. Writing siteurl/home can redirect the whole site or load attacker JS site-wide. Even a “save my plugin settings” handler that takes the whole $_POST and stores it is dangerous if any stored field is privileged.
  • update_user_meta() / add_user_meta() on a controllable key. The capabilities themselves live in user meta under the {$prefix}capabilities key. A handler that writes a meta key derived from request input can let a user grant themselves wp_capabilities or wp_user_level, which is self-promotion to admin without touching the options table.
  • Settings that accept HTML, as a stored-XSS pivot. A missing-authz write into a field that is later echoed without escaping (a “custom header”, “thank-you message” or “tracking code” box) lets a Subscriber plant a script that runs in an admin’s browser. The weak authorization then chains into a stored XSS that steals the admin session, which is the privilege the handler itself lacked. Broken access control is often the first link in a chain rather than the whole attack.
  • File and attachment handlers. Unguarded wp_handle_upload(), media_handle_upload(), or custom delete-by-path handlers turn into arbitrary upload (webshell), arbitrary file read, or deletion of another user’s media. Attachment deletes are also a common IDOR: pass any attachment ID.
  • Anything that emails, exports, or enumerates. A Subscriber-reachable “export users” or “list orders” handler is a data-breach sink even though it only reads; a “send test email to {address}” handler is an open relay.

Find the entry points, then follow each one to its sink. A list of unguarded handlers is a to-do list; the sink tells you which line to fix first.

Real cases

Salon Booking System: a callback that every role passed

In Salon Booking System (CVE-2026-110012 and CVE-2026-110035), the plugin’s REST controllers shared a base permissions_check('read') that, for controllers backed by a custom post type, resolved to the post type’s mapped read capability. Every Subscriber holds that. The result: any logged-in user could list every customer’s bookings, with contact details and staff notes, from /bookings/upcoming.

The developer had noticed part of the problem: the main /bookings handler had its own manage_salon check inside. Its sibling routes, sharing the same weak callback, did not. The first fix overrode the callback in the bookings controller only, so the discounts controller, inheriting the same base check, kept handing every coupon code to Subscribers until a later release fixed the base class. That is checks 3 and 4 from the list above in one plugin.

SmartyParcel: nonce-only AJAX actions

In the SmartyParcel write-up (CVE-2026-107788), the plugin’s router registered AJAX actions with wp_ajax_ and a default middleware that verified a nonce. That nonce was printed on the WooCommerce checkout page, which any logged-in customer can load. An earlier security fix added a manage_woocommerce check to two order-address actions, but the neighbouring shipping-label actions kept only the nonce, so any Subscriber or customer account could delete the shipping label and tracking records of any order in the store by passing its ID. I found it by diffing the release that carried that earlier fix, then confirmed it on a local test site, where a Subscriber account deleted another order’s label row. Checks 1, 2 and 4 together: a CSRF token standing in for authorization, wp_ajax_ treated as private, and no ownership check on the object ID.

Both cases have the same shape: the developer knew authorization was needed somewhere, added it in one place, and the siblings stayed open. When a plugin ships a security fix for one handler, the patch tells you where to look for the checks that are still missing.

How to find it in your own code

Start from the entry points, not from the sinks. Every handler a request can reach needs an answer to “which roles can get here, and should they?”

Grep recipes (ripgrep, run from the plugin root):

Shell
# Every AJAX and admin-post entry point, logged-in and anonymous
rg -n "add_action\(\s*['\"](wp_ajax|admin_post)_(nopriv_)?" --type php

# Explicitly anonymous entry points: read every one of these
rg -n "add_action\(\s*['\"](wp_ajax|admin_post)_nopriv_" --type php

# Every REST route, and the weakest callbacks
rg -n "register_rest_route" --type php
rg -n "permission_callback['\"]?\s*=>\s*['\"]?(__return_true|is_user_logged_in)" --type php

# REST routes with NO permission_callback at all (read the surrounding block;
# a route array missing the key defaults to public with a warning)
rg -n -A8 "register_rest_route" --type php | rg -n "permission_callback" -v

# Checks that look like authorization but aren't
rg -n "is_admin\(\)|is_user_logged_in\(\)" --type php
rg -n -e "->cap->read|\[['\"]read['\"]\]|current_user_can\(\s*['\"]read['\"]" --type php

# Hooks built dynamically by a router or loader (the first recipe misses these)
rg -n "['\"](wp_ajax|admin_post)_(nopriv_)?['\"]\s*\." --type php

# Object IDs taken straight from the request
rg -n "\\\$_(POST|GET|REQUEST)\[['\"][a-z_]*(order|booking|ticket|user|post|item|label)_?id['\"]\]" --type php

# Privileged sinks: cross-reference these against the unguarded handlers above
rg -n "update_option\(|update_user_meta\(|add_user_meta\(|wp_handle_upload\(|media_handle_upload\(" --type php

Then, for each handler the first two commands return, read the function and check:

  • Is there a current_user_can() call before the first side effect? A nonce check alone does not count.
  • Which roles hold that capability? If the answer includes Subscriber or Customer (read, a mapped CPT read), it is a login check.
  • Does the handler take an object ID? If so, is there an ownership check or a meta-capability check on that ID?
  • Is the nonce exposed to low-privilege pages? Search for where the action’s nonce is created (wp_create_nonce( '...' )) and which front-end pages print it.
  • Do sibling handlers agree? If one handler in a group has an extra check and the others don’t, that difference is your lead.
  • Is the check in a shared place? A base class, router middleware or a single callback is easier to get right once than many handlers are to get right individually.

Finally, test it the way an attacker would: create a Subscriber (and a WooCommerce Customer, if relevant), log in, and call every route and action. An anonymous 401 or 0 response is not a pass; it only proves the route needs a login.

The fix

The fix is usually one line in the right place, plus the habit of putting it there:

Nonce for CSRF, capability for authorization, ownership for the objectPHP
function myplugin_delete_item() {
    check_ajax_referer( 'myplugin', 'nonce' );
    if ( ! current_user_can( 'manage_options' ) ) {
        wp_send_json_error( 'forbidden', 403 );
    }
    $id   = absint( $_POST['id'] );
    $item = myplugin_get_item( $id );
    // For user-owned objects, check ownership instead of (or as well as) an admin capability:
    if ( ! $item || (int) $item->user_id !== get_current_user_id() ) {
        wp_send_json_error( 'not found', 404 );
    }
    myplugin_delete( $id );
    wp_send_json_success();
}

The rules behind it:

  • Keep the nonce, add the capability. They defend against different attacks; you need both on state-changing actions.
  • Choose the capability for the action: manage_options for site settings, manage_woocommerce for store operations, edit_post with the ID for post-backed objects, or a custom capability you grant to the roles that should have it.
  • For REST, put it in permission_callback, and check which roles actually hold the capability you test.
  • Check the object, not just the role, whenever an ID comes from the request.
  • Fix the shared layer. If the weak check lives in a base class or router, fix it there, so routes added later are covered too.

Takeaway

Knowing who the user is does not tell you what they may do.

Every WordPress handler needs a capability check that a Subscriber fails, plus an ownership check whenever it takes an object ID from the request.