On this page
- Status: Accepted (platform generalization programme, Workstream B, 2026-09-18). Code in tree.
- Date: 2026-09-18
- Owners: Platform (tenancy & security).
- Related: generalizes the term primitive of ADR 0032; keeps every invariant of ADR 0007 (demo posture), which this ADR amends by reference; identity kinds are declared per domain under ADR 0048; §44 (store verbatim, mask at display), §116 (one posture per request).
Context#
Three uncoordinated maskers existed. The ADR 0007 positional aliaser was one org-wide boolean a
super admin set, aliasing every brand, product, shop and creator uniformly. The ADR 0032 deck alias
was a per-deck term matcher, already per-role, reachable only from a delivered deck. A third masker
read the DEMO_DISPLAY_MASKING environment variable, so it masked every tenant on a host or none of
them and could not tell a viewer from an admin.
None of the three could answer the question an org admin actually asks: hide THESE names from THESE people. An org-wide boolean has no list; a deck alias reaches one deck; an env flag has no org.
Exports, notifications, the org-wide assistant's streamed answer and several report surfaces carried raw identity with no masker at all.
Decisions#
D1 — The registry is CURATED TERMS, not a wider switch
org_masking_terms holds the names an org wants hidden, in the operator's own spelling, one row per
term: a kind, the verbatim term, a folded form for matching, a match_mode of term / exact /
prefix, an optional replacement, a status, an origin and a nullable brand_id. There is no
regular expression: a pattern language over streamed chunks is a denial-of-service surface, and the
three modes cover what an admin can state about a name.
An org that adds no row is unchanged in every respect.
D2 — It generalizes the ADR 0032 TERM primitive, not the ADR 0007 positional aliaser
A notification body and a chat answer are PROSE. "Ton kho Vinasoy 200ml sap het" has no column to alias and no rank to position an alias by, so only a term matcher can reach the name inside the sentence. That is the mechanism, and it already exists: diacritic-folded, word-boundary anchored, longest-match-first, idempotent, with a chunked-stream filter for a streamed answer.
@yng/mask re-exports that primitive as its own single door (@yng/mask/apply). Nothing is
reimplemented, and neither door is implemented in terms of the other: ADR 0032 asks whether THIS
DELIVERABLE is published under an alias, the registry asks whether THIS VIEWER is inside the scope
the ORG curated. Two questions, two answers, one matcher.
The positional aliaser stays for the blanket posture and gains an optional posture argument, so a
surface applies the org's own wording first and falls back to Nhan A / SP-01 only for the kinds
the posture still covers.
D3 — One POSTURE, resolved once per request, carried everywhere
resolveMaskPosture(db, { orgId, brandId, viewer, override }) returns a MaskPosture — active,
mode, the identity kinds the positional aliaser still applies to, and the compiled terms. Every
surface that prints an identity carries that object; no surface resolves its own.
Resolution order, in full:
- an explicit
override(the super-admin demo toggle, the URL override) wins over everything; - the
market_intel_settings.demo_maskBLANKET — every viewer, super admin included, because the demo runner is a super admin and a posture that exempted them would mask nothing on the screen being shown; - the org's registry, when the viewer's ROLE is in scope;
- off.
It lives in a package rather than in apps/web because three runtimes need the same answer: the web
app prints it, packages/alerts builds an external channel's message per recipient, and
apps/worker runs both. A resolver inside apps/web is one the other two cannot import.
D4 — Per-role scope, with the current behaviour as the floor
org_masking_settings.masked_roles is the list of roles the org masks. NULL is not the empty
array: it means the org turned the registry on and never said who, and the answer is the non-admin
tier — someone has to be able to administer the list, read back the terms they typed and check which
real name a replacement stands for. A product that masks its own administrator is a product nobody
can operate.
An anonymous reader (a public share link, an unauthenticated render) is ALWAYS in scope: "could not tell who this is" must resolve to more masking, never less. A super admin is never in scope under a TENANT posture — the tenant's curated list is a decision about the tenant's own people — and always in scope under the BLANKET one, which is how a platform operator masks their own screen.
D5 — Identity KINDS are declared per domain
Each vertical declares the identityKinds its data produces (packages/plugin-host/src/verticals.ts).
An org's usable kinds are the union over its ACTIVATED domains, with NO fallback: commerce names a
brand, a product, a shop and a creator; HR names a person and a subsidiary; CRM names a person,
because crm_leads carries a lead's own name. A domain that produces no identity declares none, and
an empty list is a statement rather than a placeholder.
D6 — AI Recommend DRAFTS a batch; a human accepts it
The Recommend action reads a bounded slice of the org's own catalog and proposes candidate terms. It
writes nothing to the registry. Only acceptSuggestions writes, and it writes what a person
confirmed. A field carrying a pii_kind never leaves the tenant, so the proposal is a field-level
rule rather than a row of people's names sent to a provider; the model's output is schema-validated
and any term absent from the catalog it was given is dropped as invented.
D7 — DEMO_DISPLAY_MASKING is ratcheted, not retired
The display readers move to the request posture. Upload-filename masking becomes a lookup over the
org's registry terms — a curated term matches a filename the way it matches a label — with the env
flag remaining as the platform-wide fallback ONLY under the blanket posture. The hardcoded list of
one customer's words that decided "is this filename sensitive" is deleted. The remaining readers are
pinned per file by scripts/audit/mask-posture-single-source.py, and that list may only shrink.
D8 — The guard is behavioural, per surface class
A masking rule is only as good as its least covered surface, so each surface class has a test that proves a role in scope sees no registered term and a role out of scope sees it verbatim: request resolution, chat (tool results plus the streamed answer, on a term split across two frames), exports (the serialized cell stream), notifications (per declared type, in-app and per external recipient). The static half is the audit above: a closed set of doors onto the positional aliaser, no posture-less masker, and the env-flag ratchet.
No verify:data assertion accompanies this work, and that absence is deliberate: masking changes no
number (§44). It is recorded here so it is not read as an omission.
Non-goals#
- Anonymisation. Rows keep the operator's own spelling; only the display is rewritten, at a return boundary. A masked value is never persisted and never reused as a lookup key.
- A pattern language. No regular expressions, now or later.
- Replacing the ADR 0032 deck alias. It stays its own door, with its own actor and its own scope.
- Buyer PII.
mask/pii_kindon a dataset column is a different law with a different mechanism, and the registry does not touch it. - Masking a number, a date, an id or an href. An address that is masked goes nowhere.
Consequences#
- An org with no registry rows resolves byte-identically to the behaviour it had before, for every viewer, in both blanket states — asserted as a truth table rather than claimed.
- A surface that reads the posture under a
brandOrchestratedProceduremust read it INSIDE an RLS phase. Outside one the registry read returns zero rows and masking silently stops. - Notification producers stay verbatim. One row is written once and read by people whose scope differs, so the decision belongs to the reader's request; external channels build the message inside the per-recipient loop for the same reason.
packages/alertsandapps/workernow depend on@yng/mask, a leaf package whose only dependencies are the schema tables and the term primitive.