fix(brief): keep the dev hatches out of production builds (RB-11)

BIO-012: roleInterceptor/subjectInterceptor are correctly registered
only under isDevMode(), but three hand-written fetch adapters
(reveal-bignummer, letter-preview, org-template's proefbrief) bypass
HttpClient and set X-Role/X-Subject themselves with no guard. The
readers underneath, role.ts and subject.ts, were ungated too: they
read ?role=/?subject= and wrote it into sessionStorage on any
navigation, in any build -- for ?subject= that value is a BSN, which
is exactly what SessionStore's G1 comment promises never happens.

Gate both layers: currentRole()/currentSubject() return their safe
default immediately outside isDevMode() (no query-param read, no
sessionStorage write), and the three adapters additionally wrap their
headers in isDevMode() so a production request carries neither header
at all, matching what an HttpClient request already does once the
interceptors aren't registered.

TE-002: reveal-bignummer's response-shape validation was a "Trust
boundary" a spec could only reach by stubbing globalThis.fetch.
Exported it as parseRevealed(body), matching the other 30 parse*
boundaries in the repo. Same treatment for letter-preview's
errorMessage and org-template's proefbrief error mapping (extracted
from an inline try/catch into a named, exported function first, since
it wasn't already separate).

BIO-006(a): reveal-bignummer sent X-Step-Up: 'true' unconditionally,
so the backend's step-up precondition constrained nothing. reveal()
now takes a stepUp flag; BriefStore.revealBigNummer() -- reachable
only after the UI's confirm() gesture -- is the one that supplies it,
so the literal no longer lives in the transport adapter.

BIO-006(b): documented in roles-and-access.md that drafter is also
the backend's fallback identity (StubIdentityProvider's catch-all
arm), not just the dev switcher's initial choice -- so the
least-privilege consequence of it also being the only role that may
reveal a BSN is visible.

Doc correction, same diff: roles-and-access.md's "wired only under
isDevMode()" claim was false for the three hand-written fetch paths;
it now says where the gate lives (interceptor registration and the
reader functions) so it doesn't go stale the same way again.
CLAUDE.md's dev-only claims needed no correction -- they already
noted these three calls bypass the interceptor.

Every fix has a test confirmed red by temporarily reverting the
source change and rerunning the suite before restoring it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
eho
2026-08-27 14:20:47 +02:00
co-authored by Claude Opus 5
parent ae7781efef
commit 772c47ea43
14 changed files with 632 additions and 37 deletions
+53 -1
View File
@@ -20,7 +20,7 @@ tested where._
Every bullet below is a real test name from the suite — an `it()` title (frontend) or a test
method name (backend), read as a sentence. Nothing here is hand-written prose: this page
**is** the suite, reshaped for a business reader. 406 frontend behaviours across
**is** the suite, reshaped for a business reader. 431 frontend behaviours across
8 contexts; 217 backend behaviours across 36 test
classes.
@@ -186,6 +186,16 @@ classes.
- swaps the masked value for the revealed one on success
- keeps the value masked and surfaces the error on failure
#### LetterPreviewAdapter.preview (BIO-012)
- sends no X-Role/X-Subject headers outside isDevMode()
- sends X-Role (and X-Subject when known) under isDevMode()
#### RevealBigNummerAdapter.reveal (BIO-006a + BIO-012)
- sends X-Step-Up only when the caller passes stepUp: true
- sends X-Role only under isDevMode()
#### besluitGuidance
- positief: counts inserted passages, no reden needed (positief has no redenen)
@@ -237,6 +247,12 @@ classes.
- marks added, removed, changed and unchanged by blockId
- changedBlocks drops unchanged and keeps added/removed/changed
#### errorMessage (TE-002 trust boundary)
- surfaces the ProblemDetails detail when present
- falls back to PREVIEW_FAILED when the body has no detail
- falls back to PREVIEW_FAILED when the body is not JSON
#### inferSelection
- round-trips a positief selection
@@ -275,6 +291,13 @@ classes.
- rejects a missing count field
- rejects a malformed history entry
#### parseRevealed (TE-002 trust boundary)
- accepts a well-formed body
- rejects a bigNummer sent as a number
- rejects a missing bigNummer field
- rejects null and non-object bodies
#### passagesForBesluit
- positief = shared intro + the positief passage, no negatief/reason passages
@@ -283,6 +306,12 @@ classes.
- preserves library order (= reading order)
- never offers non-kern passages
#### proefbriefErrorMessage (TE-002 trust boundary)
- surfaces the ProblemDetails detail when present
- falls back to PROEFBRIEF_FAILED when the body has no detail
- falls back to PROEFBRIEF_FAILED when the body is not JSON
#### redenenFor
- derives reason checkboxes (code + label) from the negatief reason passages
@@ -635,6 +664,29 @@ classes.
- applies the pure update on dispatch
- dispatch from inside an effect does not self-loop
#### currentRole (dev mechanism)
- lists the three roles
- reads a valid ?role= from the URL and persists it for the tab
- falls back to drafter when nothing is set or the value is invalid
#### currentRole (dev mechanism) outside isDevMode() (production build)
- ignores a ?role= in the URL and returns the default
- never touches sessionStorage
- ignores a role already sitting in sessionStorage from a prior dev session
#### currentSubject (dev mechanism)
- reads a ?subject= from the URL and persists it for the tab
- returns undefined when nothing has ever been set
#### currentSubject (dev mechanism) outside isDevMode() (production build)
- ignores a ?subject= (a BSN) in the URL and returns undefined
- never writes the BSN into sessionStorage
- ignores a subject already sitting in sessionStorage from a prior dev session
#### delete flow (optimistic, revertible)
- UploadDeleteRequested keeps the documentId for revert