Introduction

A routine penetration test uncovered a serious authorization flaw: a user with read-only Viewer permissions could export full Stripe invoice PDFs and rotate webhook secrets by calling a protected API endpoint directly. The discovery was especially uncomfortable because the team already maintained 85 Playwright tests specifically for role-based access control. Those browser-based checks took 18 minutes to run in CI, broke whenever frontend labels changed, and still missed a high-severity gap on the very routes they were meant to protect.

What Happened

The problem came down to a blind spot in the testing strategy. UI tests verify what React renders in the browser, not what the Express backend actually permits. Developers had hidden buttons conditionally in the frontend—for example, hiding a Rotate Secret button from non-admins—but had not always added matching authorization middleware on the server. As a result, the application looked secure in the browser while leaving critical API routes exposed.

When the platform expanded from two roles to five—Owner, Admin, Billing, Member, and Viewer—the team copied and parameterized Playwright specs for every sensitive action across every role. That produced 85 browser tests, each booting Chromium, loading the React bundle, and checking whether a button was missing from the DOM. New endpoints often shipped with only a single happy-path test, leaving cross-role authorization unverified.

To fix this, the team created a single source of truth: a permission matrix file mapping every API route and HTTP method to the exact roles allowed to call it. That same file now powers two consumers. First, an Express route guard middleware refuses to start the server in CI if any mounted route is missing from the matrix, enforcing a fail-closed posture. Second, one data-driven API test loops through every matrix row, sends real HTTP requests using five pre-minted JWTs, and asserts that disallowed roles receive 403 while allowed roles are not blocked by authorization.

Why This Matters

Hiding a button in React is a user experience decision. Returning 403 Forbidden on the server is a security control. The old suite was only testing UX, which meant backend authorization could lag behind frontend changes without anyone noticing. By moving authorization checks to the API layer and treating the permission matrix as the authoritative policy, the team ensured that new routes cannot be deployed without an explicit role assignment visible in the pull request.

The change also added cross-tenant isolation checks to the same loop. For routes marked as tenant-scoped, the test attempts access using a different tenant's credentials, helping prevent IDOR vulnerabilities where one customer could access another's resources.

Key Takeaways

  • UI tests cannot replace backend authorization testing; they verify rendering, not server-level access control.
  • A declarative permission matrix serves as a single source of truth for both middleware and automated tests.
  • Fail-closed route guards prevent unprotected endpoints from reaching production.
  • Replacing 85 browser tests with one API matrix reduced RBAC test runtime from 18 minutes to approximately 1.9 seconds.
  • The same test loop can cover vertical privilege escalation and horizontal cross-tenant IDOR checks.
  • Startup route-coverage audits make it impossible to mount an Express route without declaring its allowed roles.

Conclusion

The team kept a small number of Playwright tests for navigation user experience, such as confirming that sidebar links disappear for roles that should not see them. The remaining browser-based role tests were removed entirely. The result was faster CI pipelines, zero selector breakage during frontend redesigns, and significantly stronger security coverage across every mounted route.

If your team is still spinning up headless browsers to prove that a hidden button cannot be clicked, consider checking the backend routes instead. Attackers do not use your React sidebar; they call your API directly. A compact permission matrix can catch authorization gaps before they reach production.