Skip to content
Toolkit

ADR-0076 — A capability that qualifies a write is gated on the field

  • Status: Accepted
  • Date: 2026-08-28
  • Deciders: Track 004 phase 02
  • Follows: ADR-0072 (a capability is a subsystem this port has), ADR-0074 (a block type declares the capability it needs), ADR-0075 (a capability with no write path is not a capability)

Context

The first four capabilities enforced gate a resource: minting a token, creating a PWA, creating a premium block, generating with the AI tools. In each, the request either is the gated thing or is not, and the gate reads the operation.

targeting_is_enabled is not like that. Nothing creates a "targeting"; a resource that already exists — a link, a bio page, a block — carries display_rules, and narrowing it to an audience is one field on a write that is otherwise ungated. Refusing POST /api/v1/links because the capability is withheld would stop every link, not every targeted link. password_protection is the same shape one field over: settings.password on file links and static pages.

Two further questions came with it.

What counts as targeting. display_rules also carries scheduled_at and scheduled_end, which DisplayRulesService.Match evaluates in the same object. A schedule narrows when, not who, and the capability the glossary defines is audience: "narrow a resource or a block to an audience by country, device, browser or language".

What a withheld capability does to rules that already exist. Enforcement in this track is create-only (ADR-0074): existing rows stay readable, editable and deletable. A field-scoped gate has a sharper version of the same question, because the field is edited in place.

Decision

The gate reads the payload, not the route. At each of the five call sites that write display_rules — link create and update, block create and update, bio page update — the capability is required only when the incoming rules would narrow the audience:

if services.RulesNarrowAudience(input.DisplayRules) &&
    !requireCapability(w, r, h.capabilities, userID, "targeting_is_enabled") {
    return
}

Audience, not schedule. RulesNarrowAudience answers from audienceDimensions — the seven keys Match evaluates as audience — and Match now iterates the same list, so a dimension added to the evaluator is gated by construction. The schedule keys are deliberately outside it: they are not what the capability was minted to sell.

Clearing is never refused. A rules object that is absent, empty, or names only empty lists narrows nothing, so it is not targeting and takes no gate. A plan that does not include targeting can always remove rules it already has, and an update that touches other fields passes untouched. This is create-only enforcement stated for a field: the gate fires on the value being set, never on the value being removed, and never on the row being edited.

Alternatives

Gate the whole write. Refusing every link create for a plan without targeting is wrong on its face, and refusing every update would trap a user who has rules and no capability, unable even to delete them.

Strip the rules silently and continue. The write appears to succeed and the targeting is not there — the shape ADR-0040 found on the picker that silently voided every schedule. A refusal a client can read is the whole point of the 422 (ADR-0072's refusal shape).

Gate on any non-empty display_rules. Simpler, and it would charge for scheduling under a key whose label says audience. The vocabulary is what an operator and a user read; a gate that exceeds it is a second, undeclared capability.

Put the predicate in the handlers. Two copies of "what counts as targeting", one in the evaluator and one in the gate, drift the first time a dimension is added — and drift here means a dimension that targets an audience nobody is charged for. It lives beside Match, off one list.

Consequences

Five call sites, one predicate, and the two gates on the block create path each read their own half of the payload: a premium type asks about premium_blocks, targeted rules ask about targeting_is_enabled, and a free untargeted block asks about neither.

password_protection, the last of phase 02, inherits this shape rather than inventing one: it is a field on a write, gated when the field is being set, never when it is being cleared.

A dimension added to Match is gated automatically. A dimension added outside audienceDimensions is not — that is the seam to watch, and it is named in one place with a comment saying so.

Source: docs/decisions/0076-a-capability-that-qualifies-a-write-is-gated-on-the-field.md

Library