← Back

Server-Side Authorization: Check the Actual Resource

Build server-side authorization around actors, resources, and actions. Trace tenant boundaries through queries, background jobs, caches, and permission tests.

Server-side authorization asks whether this actor may perform this action on this resource now. A logged-in session answers only part of that question. In a multi-tenant application, the dangerous gap is often a valid user requesting a valid record that belongs to someone else.

I would review authorization by following one resource from HTTP input to database query and back to the response. Then I would repeat the exercise for updates, exports, background jobs, and cached responses. The policy has to survive every path that reaches the data.

Start with a resource-specific rule

Suppose a project management service allows workspace members to read tasks, while only project editors may change them. An authorization rule needs the authenticated actor, the task's actual workspace and project, the requested action, and relevant membership state.

OWASP recommends denying by default, validating permissions on every request, and designing access control around application requirements in its Authorization Cheat Sheet. Its Broken Object Level Authorization guidance highlights the risk of endpoints accepting object identifiers without verifying access to those objects.

For the proposed service, I would write the rule in domain language before a middleware abstraction: “An active member of the task's workspace may read the task; an active project editor may update it.” That sentence reveals which relationships the server must verify.

Scope the data access, not just the button

An illustrative read might constrain the resource and membership together:

SELECT t.id, t.title, t.status
FROM tasks t
JOIN workspace_memberships m
  ON m.workspace_id = t.workspace_id
WHERE t.id = $1
  AND m.user_id = $2
  AND m.status = 'active';

This is a simplified query sketch, not a complete policy engine. It assumes membership uniqueness and a trusted authenticated user ID. A project-specific restriction would need an additional condition. The important feature is that the task's own workspace drives the membership check.

Do not accept a client-supplied workspace ID as proof of membership, and do not assume an unguessable resource ID makes the check unnecessary. A hidden edit button improves the interface; it cannot enforce the server rule against a direct request.

For updates, include the authorization conditions in the mutation or perform them within a transaction that preserves the intended consistency. A permission read far ahead of an unconditional write deserves scrutiny when membership can change concurrently.

Trace indirect access paths

The main task endpoint may be correct while a bulk export leaks the same data. I would inventory related paths: search, attachments, activity feeds, CSV exports, webhook payloads, and administrative tools. Each needs an explicit policy rather than permission inherited from a vaguely related screen.

Background jobs require special attention. If a user schedules an export and then loses workspace access, what should happen when the job runs? My proposed policy would re-check access before generating and delivering the export. A different product may preserve previously authorized jobs, but that choice should be deliberate and documented.

Likewise, cached responses need an audience boundary. A response authorized for one workspace must not become reusable by another because a cache key omitted tenant identity. Authorization review should include the representation's delivery path, not stop at the database query.

Use row security with the correct role model

PostgreSQL row-level security can restrict rows for normal queries and writes. When enabled without an applicable policy, it defaults to denial; however, superusers, roles with BYPASSRLS, and usually table owners bypass policies. The exact behavior is documented in Row Security Policies.

For a proposed deployment using RLS, I would test with the actual application role rather than an administrator's connection. Also verify how tenant or actor context is established, reset, and isolated across pooled connections. A correct policy evaluated with the wrong session context is still the wrong result.

RLS can provide another enforcement layer, but it does not choose your product permissions. The application still needs a clear model for actions such as inviting members, changing billing settings, or exporting attachments.

Build a small permission matrix

Before adding a large role system, create fixtures with two workspaces, two projects, and users whose memberships differ. Then test the same operations across those boundaries:

ActorResourceExpected result
Active workspace readerTask in own workspaceRead allowed
Same readerUpdate to that taskDenied without editor permission
Editor in workspace ATask in workspace BDenied
Removed memberPreviously visible taskDenied under current-access policy
Anonymous callerPrivate taskDenied

These expected outcomes belong to the example policy. Adapt the matrix to the actual domain, including exceptions such as deliberately public projects. Test both direct endpoints and bulk operations.

The agent tool-permission guide applies the same actor-resource-action discipline to model-driven calls. The cursor pagination guide shows why a client-supplied token must never establish tenant authority.

I would approve the feature when the team can point from each permission rule to its enforcing query or operation and its negative test. “The route requires login” is evidence of authentication, not completion of authorization design.