Skip to content

Broken Access Control in WordPress: How Permission Mistakes Expose Other People’s Data

11 min read
Broken Access Control in WordPress: How Permission Mistakes Expose Other People’s Data
Contents8 sections · 11 min read
  1. 1Where the risk actually starts in WordPress
  2. 2REST API: why one callback matters more than it seems
  3. 3Why extra fields in API responses are dangerous
  4. 4When themes and the Site Editor also become leak points
  5. 5The same principle for REST, Ajax, and custom forms
  6. 6Minimal safe check logic
  7. 7What to check first in existing code
  8. 8Tests that should be part of development

Broken Access Control in WordPress rarely looks like a loud “hack.” More often, it is a quiet mistake that lets a user see not only what they are allowed to see, but also other people’s orders, profiles, drafts, comments, or operational data. For a business, this can be even more painful than a site outage: the page keeps working, but private information is no longer private.

Broken Access Control is ranked first (A01) in the OWASP Top 10 — both in the 2021 edition and in the OWASP Top 10:2025. OWASP recommends treating authorization as a separate, explicit access check for every action and every data object. This is especially important in WordPress, because the platform heavily relies on roles, capabilities, REST API, Ajax handlers, and other entry points where the temptation to assume “if it’s not visible in the UI, it’s fine” is very strong.

Key takeaways

  • Broken Access Control is the #1 risk in the OWASP Top 10 (A01:2025).
  • Check not just the role but the right to the specific object: who owns it, what state it is in, what the context is.
  • Every REST route needs a permission_callback; use __return_true only for truly public data.
  • A nonce protects against CSRF, but it is not a permission check.
  • Return only the fields a specific screen actually needs.

Where the risk actually starts in WordPress

In WordPress, the problem is rarely a single “bad” line of code. The danger appears when access to a resource is checked too broadly: for example, “the user is logged in,” “has the editor role,” or “can see the button in the admin area.” That kind of check is often not enough if the action concerns a specific post, order, template, or setting.

WordPress distinguishes between roles and capabilities. This is an important principle: authorization should not be based only on the role name, because the same capability may be available to different roles, and in multisite a Super Admin has broader privileges than a regular Administrator on a single site. For security, it is important to check the capability itself and, when needed, the object context as well.

That is why the vulnerability often looks mundane: an endpoint or form works “as intended” for a legitimate user, but it lacks sufficient checks to prevent access to someone else’s data. The UI may hide the button, but if the server-side check is weak or missing, that does not protect anything.

REST API: why one callback matters more than it seems

In the WordPress REST API, every endpoint should have a callback and a permission_callback. The official WordPress documentation states directly that permission_callback is critical for security. For public endpoints, it is acceptable to use __return_true, but only when the data truly does not need protection.

Starting with WordPress 5.5, if permission_callback is not provided when a REST route is registered, WordPress shows a _doing_it_wrong notice. That is a useful signal, but it does not save older installations on its own: legacy code may contain routes without access checks that have been working for years without a visible warning.

An important detail: permission_callback runs after authentication, so you can use current_user_can() there. But a capability check by itself still does not guarantee safety. If you only verify a general permission, for example “can edit posts,” but do not verify whether the specific object belongs to that user, a data leak is still possible.

Practical rule: if an endpoint returns or modifies a specific object, the check must take into account not only the user, but also the object itself, its owner, the post type, and the request context.

What exactly to check in permission_callback

For WordPress projects, it is better to think not “is the user logged in?” but “is this user allowed to perform this exact action on this exact object?” That may mean checking a capability, the current post ID, the author, the resource status, or business-logic conditions.

For example, a user with permission to edit posts is not necessarily allowed to see other people’s orders in WooCommerce-like logic, private profile fields, or operational records from another department. If an endpoint returns a list or details, authorization should be tied to the specific data row, not just to the fact that the user is signed in.

Why extra fields in API responses are dangerous

The OWASP API Security Top 10 (2023) treats this as a separate risk, Broken Object Property Level Authorization (API3): access has to be controlled not only for resources, but also for individual data attributes. For WordPress, this is very practical advice: even if the resource itself is legitimately exposed, extra fields in the response can create an object-property-level risk, where the user sees something they should not see.

In REST responses, this happens more often than it seems. A developer correctly locked down the endpoint at the access level, but returned too broad an array of fields: internal metadata, operational flags, hidden identifiers, manager notes, address data, or technical fields that should never reach the client interface. If a piece of data is not needed for a specific scenario, it is better not to return it at all.

This is especially important when the same endpoint serves different roles or different screens. What is safe for an administrator may be unnecessary for an author, manager, or customer. Without selective response shaping, even correct resource-level authorization does not fully eliminate the risk.

When themes and the Site Editor also become leak points

Broken Access Control risk is not limited to plugins. In block themes and the Site Editor, access to related REST endpoints relies on capabilities such as edit_theme_options, edit_posts, edit_pages, edit_others_posts, and upload_files depending on the resource type. If such an endpoint is exposed too broadly, the consequences may affect not just one page, but the entire site interface.

That is what makes this kind of mistake especially unpleasant: it affects not only confidentiality, but also integrity. Access to templates, navigation, or another global part of the site can change what all visitors see. That is why permissions for themes and the Site Editor need to be checked just as carefully as CRM features or a customer portal.

The same principle for REST, Ajax, and custom forms

Although the official documentation about permission_callback applies to the REST API, the same approach should be carried over to other entry points: admin-ajax.php, custom forms, theme handlers, exports, imports, and quick actions in the admin area. You cannot consider code safe just because access to the button is hidden in the frontend.

A useful mental model is this: every request should pass three checks — who is making the request, what exactly they are requesting, and whether this specific action is allowed in this context. If even one of these layers is missing, access control can become a “wide open door” instead of a filter.

Minimal safe check logic

Below is a short example of what an endpoint with checks for a specific record might look like — here, a customer support ticket (a custom post type wsp_ticket). This is not a ready-made template for every project, but only a basic structure that you need to adapt to your data type, roles, and business rules. The code should live in a plugin or in functions.php of a child theme, but for production projects it is better to move such logic into a separate plugin module.

PHP
<?php
/**
 * REST endpoint: a customer's support ticket (custom post type "wsp_ticket",
 * registered with 'map_meta_cap' => true).
 */
add_action( 'rest_api_init', function () {
    register_rest_route(
        'wsp/v1',
        '/tickets/(?P<id>\d+)',
        array(
            'methods'             => WP_REST_Server::READABLE,
            'callback'            => 'wsp_get_ticket',
            'permission_callback' => 'wsp_can_view_ticket',
            'args'                => array(
                'id' => array(
                    'type'              => 'integer',
                    'required'          => true,
                    'sanitize_callback' => 'absint',
                ),
            ),
        )
    );
} );

/**
 * Who may read this ticket: its author or a user allowed to edit it.
 */
function wsp_can_view_ticket( WP_REST_Request $request ) {
    if ( ! is_user_logged_in() ) {
        return new WP_Error( 'rest_forbidden', 'Authentication required.', array( 'status' => 401 ) );
    }

    $ticket = get_post( (int) $request['id'] );

    if ( ! $ticket || 'wsp_ticket' !== $ticket->post_type ) {
        return new WP_Error( 'rest_not_found', 'Ticket not found.', array( 'status' => 404 ) );
    }

    // Check the right to this specific object, not just a general capability.
    if ( get_current_user_id() === (int) $ticket->post_author ) {
        return true;
    }

    return current_user_can( 'edit_post', $ticket->ID );
}

function wsp_get_ticket( WP_REST_Request $request ) {
    $ticket = get_post( (int) $request['id'] );

    // Return only the fields this screen needs: no meta, no internal notes.
    return rest_ensure_response(
        array(
            'id'     => $ticket->ID,
            'title'  => get_the_title( $ticket ),
            'status' => get_post_status( $ticket ),
        )
    );
}

There are two important things in this example. First, access is checked against a specific object, not just against the user type. Second, the response contains only the fields that are actually needed for the scenario. If in a real project the object has multiple owners, intermediate states, or delegated access, the condition in permission_callback needs to become more complex.

WooCommerce orders need an adapted version of this example: with High-Performance Order Storage (HPOS), enabled by default for new stores since WooCommerce 8.2, orders live in dedicated tables rather than as WordPress posts. Use wc_get_order() for them and compare $order->get_customer_id() with the current user ID.

It is also worth remembering that current_user_can() is a capability-checking mechanism, not a magical security guarantee. It is useful and correct as part of authorization, but it does not replace business logic that understands who owns the object and what state it is in.

What to check first in existing code

When you audit a plugin or theme, do not start with all files at once; begin with the riskiest entry points. The first candidates are REST routes without an explicit permission_callback, Ajax handlers that rely only on a nonce, and methods that return lists of objects without tying them to the owner or role.

Pay especially close attention to older installations before WordPress 5.5 and to outdated plugins. That is where routes without access checks or with checks that exist only “for show” have historically been more common. If a capability check already exists in the code, verify whether it is too broad for the actual data returned by the endpoint.

A practical review order might be this: find all entry points, determine what data they read or change, mark whether there is an access control check, and separately verify whether extra fields are being returned. It is a simple path, but it often reveals problems faster than complex reverse engineering.

Access control audit checklist

  • Every register_rest_route() call has a meaningful permission_callback.
  • Ajax handlers (wp_ajax_*) check current_user_can(), not just a nonce.
  • Object-level actions verify the owner or current_user_can( 'edit_post', $id ).
  • Lists, search, filters and exports limit data to the current user.
  • API responses contain no internal meta fields, manager notes or unnecessary personal data.
  • There is an automated test: “user A cannot see user B’s data.”

Tests that should be part of development

OWASP recommends testing authorization with automated unit and integration tests, but not treating them as a replacement for full security testing or a pentest. For WordPress projects, this is very practical advice: every sensitive endpoint should have a scenario where “user A cannot see user B’s data.”

Those tests do not have to be complicated. It is enough to verify that an unauthenticated or unrelated user gets a 401 or 403 where expected, rather than a full JSON response with another account’s data. It is also worth testing lists, detail pages, search, filtering, and export — that is where access control often leaks in edge cases.

The most reliable approach is to combine automation with manual checks. Automated tests are good at catching regressions, but they do not always catch business-logic errors where access is determined not only by role, but also by relationships between objects, states, and context.

If we reduce all of this to one principle, it is simple: in WordPress, you cannot consider data protected just because it sits behind the REST API or an admin button. Protection begins where every request goes through an explicit check of the right to perform an action and an explicit restriction on exactly what can be seen. That discipline is often what separates a secure endpoint from a quiet leak of someone else’s information.