# ABAC (attribute-based access control)

ABAC, attribute-based access control, decides whether a person may perform an action by checking attributes of the person, the record, the action and sometimes the environment against rules. In a business app those attributes are things like whose record it is and which status it is in, and Meadowstack 2.1 writes them as conditions on the record in the same `domain/permissions.ts` that holds the roles.

Checked 2 December 2026. By Bohuslav Poláček. https://meadowstack.com/glossary/abac/

*The starter's canFor(): after the role check, each action asks about the record's owner and status.*

From `templates/starter/src/modules/requests/domain/permissions.ts` in the Meadowstack repository:

```ts
export function canFor(person: Person): CanFn {
  return (action, subject) => {
    if (!roleActions[person.role].includes(action as Action)) return false;
    const request = subject as PurchaseRequest | undefined;
    // Without a record the question is "may this person ever do it" (show the "New request" button?).
    if (!request) return true;
    const mine = request.requesterId === person.id;
    switch (action) {
      case "request.read":
      case "request.comment":
        return request.status !== "draft" || mine || person.role === "admin";
      case "request.edit":
      case "request.submit":
        return (request.status === "draft" || request.status === "rejected") && (mine || person.role === "admin");
      case "request.withdraw":
        return request.status === "submitted" && mine;
      case "request.delete":
        return request.status === "draft" && (mine || person.role === "admin");
      case "request.approve":
      case "request.reject":
        return request.status === "submitted" && !mine;
      case "request.reopen":
        return (request.status === "approved" || request.status === "rejected") && request.decidedById === person.id;
```

## Why it matters in a business app

Roles answer "may approvers approve?". They cannot answer "may Dana approve this request?", because the answer depends on the request: Dana wrote it, it is still a draft, someone else already decided it. Those are attributes of the record, and the rules that read them are where most real permission bugs live: a person editing a request after it was approved, or reading a colleague's draft.

NIST's guide to ABAC (SP 800-162) describes the same idea in general terms: subject, object, operation and environment attributes checked against policy.

## How Meadowstack handles it

In 2.1 the record rules sit right after the role check in one function, `canFor(person)`, which returns the `can(action, record)` every screen asks:

| Action | Attribute it reads |
| --- | --- |
| `request.read` | the status (a draft is private) and the requester |
| `request.edit`, `request.submit` | the status is draft or rejected, and the person wrote it or is an admin |
| `request.withdraw` | the status is submitted, and the person wrote it |
| `request.approve`, `request.reject` | the status is submitted, and the person did not write it ([four-eyes](https://meadowstack.com/glossary/four-eyes-principle/)) |
| `request.reopen` | the person is the one who decided |

Asked without a record, `can("request.create")` answers "may this person ever do it", which decides whether the button shows. The same conditions appear again in the Supabase example's policies and trigger ([row-level security](https://meadowstack.com/glossary/row-level-security/)); in 2.1 keeping the server side in step is your job, and Meadowstack 3.0, coming as an update to every licence, generates the database policies from one policy file.

## Common mistakes

- **A new role for every exception.** "Approver who may not approve their own" is not a role; it is a condition on the record.
- **Checking the attribute the browser sent.** The requester and the status come from the stored record, never from the request body.
- **Forgetting the status.** An edit rule without a status check lets people change a request after it was approved.
- **Rules spread across components.** One function per module, tested (`test/permissions.test.ts` in the starter), is what keeps them readable.

## Questions

### Is ABAC better than RBAC?

Neither replaces the other in a typical business app. Roles give the broad lines that people understand, and attributes of the record handle ownership, status and four-eyes. The starter does exactly that: roles first, then the record.

### Do I need a policy engine for ABAC?

Not for most business apps. A plain function per module that reads the person and the record covers ownership and status rules, and the same conditions can be written as database policies.

### What counts as an environment attribute?

Conditions outside the person and the record, such as the time of day or the network a request comes from. The starter's rules use none; a rule like that belongs on the server, where the time and the network can be trusted.

## Sources

- [NIST SP 800-162, Guide to Attribute Based Access Control (ABAC) Definition and Considerations](https://csrc.nist.gov/pubs/sp/800/162/upd2/final), checked 2 December 2026

## Related

- [Team and roles, with the rules in code](https://meadowstack.com/screens/roles-and-permissions/) (Screens)
- [Permissions](https://meadowstack.com/patterns/permissions/) (Patterns)
- [The approval flow](https://meadowstack.com/patterns/approval-flow/) (Patterns)
- [Postgres: the person in a transaction setting](https://meadowstack.com/integrations/postgres/) (Integrations)
- [Supabase: the rules in the database](https://meadowstack.com/integrations/supabase/) (Integrations)
- [Roles and permissions UI patterns for business apps](https://meadowstack.com/blog/roles-and-permissions-ui-patterns/) (Blog)
