Broken function-level authorization: admin actions any user can call

Why hiding an admin menu does not protect the admin endpoint, how to map routes against roles from an OpenAPI file, and how central authorization policies with deny-by-default tests close the gap.

Lesson 34 of 69 · 12 min read · practice only with authorization

Diagram

A route the UI never shows a normal user

Follow the path. One example at a time.

Step 1 of 4

Discovery

The JavaScript bundle and the OpenAPI file list every route, including admin ones.

Illustration: Discovery
$ jq -r '.paths | keys[]' openapi.json | grep admin
/api/admin/users
/api/admin/users/{id}/disable
/api/admin/export

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. Authenticated is not authorized

    What fails
    Handlers check that a user is signed in and stop there.
    Who is affected
    Everyone affected by the admin action, such as disabled accounts or exported data.
    What you would notice
    A 200 from an admin route with a normal user’s token.
    What you change
    Require an explicit role or permission per route.
  2. Method confusion

    What fails
    GET is protected but PUT or DELETE on the same path is not.
    Who is affected
    Owners of the records the unprotected method changes.
    What you would notice
    Authorization middleware keyed on path alone.
    What you change
    Key policies on method plus path and test each method.
  3. Route drift

    What fails
    New routes ship without a policy entry.
    Who is affected
    Whatever the new route touches.
    What you would notice
    No test that walks the route table.
    What you change
    Fail CI when a registered route has no policy.

A role matrix from the spec

Export the route list from the OpenAPI file or the framework, list the roles, and call each route with a token for each role in a test environment. The result is a table of expected and actual status codes. Any cell where a lower role gets 2xx on a higher role’s route is a finding.

route                               anon  user  support  admin
GET  /api/admin/users               401   403   200      200
POST /api/admin/users/{id}/disable  401   200!  200      200
GET  /api/admin/export              401   403   403      200

Keeping it closed

Generate that matrix in an integration test. A route added without a policy fails the build, and the matrix doubles as documentation for reviewers.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

A normal user gets 200 from POST /api/admin/users/88/disable. What was missing?

Sibling techniques

Pages at the same depth, plus a lab and a glossary card for this one.

  1. MapIDOR and broken object-level authorization: ids without an owner checkHow changing an id in a URL or API body returns someone else’s record, why it tops the OWASP API list, how to test it with two accounts you own, and the ownership-scoped query that fixes it.
  1. 01IDOR in exports and batch endpointsA list of ids is still a list of objects.
  2. 02Nested object authorizationA check on the parent record does not authorize every child id inside the request.
  3. 03Mass assignment: when request bodies write fields they should notHow binding a whole JSON body to a model lets callers set roles, prices, or owners, how to spot it in Rails, Django, Express, and Spring code, and why explicit write schemas are the fix.

Practice

  1. LabRequest replay authorization diffReplay each API request with a second user’s session and compare the responses line by line to find the endpoints that skip an ownership or role check.

Glossary

  1. CardBroken function level authorizationAn administrative endpoint is hidden in the UI but still accepts calls from a normal account.