Appearance
ADR-2551: Share Session Resilience, Draft-Safe Sign-Out, and Part 11 Signature Primitives
- Status: Accepted
- Date: 2026-11-20
- Authors: @fderuiter
- Deciders: @fderuiter
- Requirements: PRD-SYS-001 (Operational authentication resilience and participant boundary isolation), PRD-CRF-015 (21 CFR Part 11 electronic signature re-authentication and credential hygiene)
1. Context & Problem Statement
Both the staff clinical workspace (apps/web) and the participant portal (apps/subject-portal) authenticate via Keycloak OIDC (cadence-web), retain unsigned clinical or questionnaire drafts locally while a user works, and verify electronic signatures against the gateway step-up endpoint (POST /api/v1/auth/signature-verification).
Previously, session lifecycle, sign-out confirmation, and signature verification logic diverged across the two clients:
- Fragmented OIDC refresh & 401 handling: Concurrent API calls and background expiry callbacks (
onTokenExpired) could trigger duplicatekeycloak.updateToken()requests,subject-portaldid not registeronTokenExpired/onAuthRefreshSuccessor pass an explicitredirectUriinlogin(), and involuntary401expiry did not consistently attempt a single-flight refresh, preserve return URLs, or transitionParticipantCard.vueout ofAuthenticatedtoSession Expired. - Unconfirmed voluntary sign-out with unsaved drafts: Clicking Sign out immediately purged user-scoped eCRF storage (
purgeUserScopedStorage(null)) or reset active questionnaire progress without flushing debounced drafts or asking the user to confirm discarding unsaved entries. - Duplicated step-up payloads & signing UX gaps: Seven callers constructed
/api/v1/auth/signature-verificationbodies separately,CtmsView.vueomittedsemantic_action: "ctms.doa.sign_off", password inputs lacked shared alphanumeric attributes (inputmode="text"),"Other"custom reason validation was duplicated,SignatureCaptureModal.vuewiped passwords on failed submission without an inline re-entry cue or claim-derived signer role default, anddocker/cadence-realm.jsonlacked a deterministicSubjectaccount for local E2E testing.
2. Decision Drivers & Constraints
- Draft preservation vs. account isolation (#5369, ADR-2360): Involuntary token expiry (
onTokenExpiredor unrecoverable401) must clear stale bearer tokens in memory without purging user-scoped eCRF drafts or PIN-encrypted IndexedDB questionnaire drafts, whereas confirmed voluntary sign-out must continue purgingpurgeUserScopedStorage(null)and clearingactiveQuestionnaire. - Zero raw token storage (ADR-2493, ADR-2360): Raw OIDC access tokens and unwrapped session encryption keys must never be persisted to
localStorageorsessionStorage. - 21 CFR Part 11 cryptographic contract (
docs/SDLC/Signature_Token_Cryptographic_Contract.md): Step-up requests must carry canonical lowercasesemantic_actionstrings matching^[a-z0-9_]+(\.[a-z0-9_]+)+$, enforce custom text when reason"Other"is selected, and wipe password/TOTP fields on submit, cancel, andEscape. - Participant kernel isolation (K027, ADR-2457): A seeded Keycloak
Subjectuser must carrySubjectrealm role and scopedtenant_id,study_ids, andsite_idtoken attributes while holding zero staff kernel grants.
3. Options Considered
Option 1: Centralize Session, Sign-Out Guard, and v3 Signing Primitives in packages/ui + Seed Deterministic Subject Realm User (Selected)
- Overview:
- Export
createOidcSessionCoordinator(packages/ui/session.js) to registeronTokenExpiredandonAuthRefreshSuccess, coalesce concurrentupdateTokenrefreshes into one single-flight promise, retry401responses once with a refreshed bearer token, and preserve return URLs on involuntary expiry without purging local drafts. - Export
SignOutConfirmModalanduseSignOutGuard(packages/ui) and wire debounced draftflush()hooks inuseEcrfForm.ts,useEcrfDrafts.js, andquestionnaire.jsso voluntary sign-out flushes pending drafts and requires explicit confirmation before purging drafts when unsaved work exists. - Export
SEMANTIC_ACTIONS,isValidSemanticAction,buildStepUpVerificationPayload,SIGNATURE_PASSWORD_INPUT_ATTRS,requiresCustomSignatureReason,resolveSignatureReason, andderiveSignerRoleFromClaims(packages/ui/signing.js), standardize all seven/api/v1/auth/signature-verificationcallers (includingctms.doa.sign_offinCtmsView.vue), and surface an inline password re-entry cue inGxpCredentialsInput.vue/SignatureCaptureModal.vue. - Seed deterministic
subject.site101indocker/cadence-realm.jsonwithrealmRoles: ["Subject"]andtenant_id: ["cadence-local"],study_ids: ["CADENCE-101"],site_id: ["SITE-101"].
- Export
- Pros:
- Eliminates duplicated refresh, sign-out confirmation, and Part 11 step-up payload code across
apps/webandapps/subject-portal. - Guarantees consistent WCAG 2.1 AA focus-trapped confirmation dialogs, credential wiping, and v3 step-up token binding.
- Eliminates duplicated refresh, sign-out confirmation, and Part 11 step-up payload code across
- Cons:
- Requires keeping
packages/uibuilt (pnpm --filter ui build) before downstream workspace typechecks and tests.
- Requires keeping
Option 2: Patch Individual App Stores and Views Independently
- Overview: Implement separate refresh locks, custom browser
window.confirm()dialogs, and inline step-up request bodies in each app. - Pros:
- Avoids touching
packages/uiexports.
- Avoids touching
- Cons:
- Fails shared-code governance, breaks WCAG 2.1 AA focus containment (
window.confirm), and invites future drift across step-up signature endpoints.
- Fails shared-code governance, breaks WCAG 2.1 AA focus containment (
4. Decision Outcome
- Chosen Option: Option 1
- Justification: Sharing session coordination, accessible sign-out confirmation, and Part 11 v3 signature helpers in
packages/uienforces one tested contract across staff and participant applications while preserving strict memory-only token security and K027 participant isolation.
5. Consequences & Trade-offs
- Positive Impact: Single-flight token refresh prevents refresh stampedes; involuntary expiry preserves clinical and participant drafts with clear
Session Expiredrecovery; voluntary sign-out prevents accidental draft loss; all seven step-up callers emit contract-valid v3 payloads; andsubject.site101enables deterministic participant OIDC testing. - Negative Impact / Technical Debt: Browser-side eCRF drafts remain user-scoped in
localStorageuntil server-side unsigned draft persistence lands. - Mitigation Strategy:
useSignOutGuardflushes debounced writes before evaluating draft presence and warns users that continuing sign-out discards unsaved entries on the shared workstation.
6. Implementation & Verification
- Affected Repositories / Services:
packages/ui,apps/web,apps/subject-portal,docker/cadence-realm.json,tests/Cadence.UnitTests,tests/Cadence.IntegrationTests. - Verification Plan: Vitest suites (
packages/ui/tests/session_logout_signing.test.js,apps/subject-portal/tests/session-logout-signature-resilience.test.js,apps/web/tests/session_logout_signature_primitives.spec.ts), xUnit realm and K027 isolation tests (KeycloakRealmTenantTests,KernelDevelopmentTenantPostgresTests), axe-core accessibility assertions, and fullcadence check --pre-commitquality gates.