Skip to content

feat: add ParticipantTokens.require and portal X-Participant-Token header plumbing - #1439

Open
JorimTheuns wants to merge 6 commits into
fix/verify-manual-edit-pii-redactionfrom
feat/portal-participant-token
Open

JorimTheuns wants to merge 6 commits into
fix/verify-manual-edit-pii-redactionfrom
feat/portal-participant-token

Conversation

@JorimTheuns

@JorimTheuns JorimTheuns commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds strict participant token verification on the backend and X-Participant-Token storage and header attachment in the web portal so upcoming landscape, handoff, and public-intake routes can require participant tokens without breaking existing sessions.

Changes

  • Backend (dembrane/platform/packages/conversations/src/participant-token.ts):
    • Added ParticipantTokens.require(header, conversationId, projectId?), which rejects missing headers with UnauthenticatedError and invalid, forged, or mismatched tokens with ForbiddenError regardless of PARTICIPANT_TOKEN_REQUIRED.
    • Kept all existing portal routes on lenient tokens.check(...) so in-flight recordings and dashboard uploads are unaffected on deploy.
    • Added unit tests for ParticipantTokens.require in portal-units.test.ts.
  • Frontend (dembrane/frontend/src/lib/participantToken.ts, dembrane/frontend/src/lib/api.ts, portal routes/hooks/components):
    • Captured X-Participant-Token from POST /api/participant/projects/:project_id/conversations/initiate in the apiNoAuth response interceptor (CORS already exposes x-participant-token and reflects Access-Control-Request-Headers).
    • Stored tokens in sessionStorage under portal:token:<conversationId> with an in-memory fallback when sessionStorage throws in private browsing, so tokens do not linger across sessions on shared tablets.
    • Cleared stored tokens on conversation finish/exit (ParticipantPostConversation, dashboard upload finish, and ParticipantStart mount for fresh shared-tablet sessions) and on 403 token-rejection errors (participant.token_invalid or bare 403) across both apiNoAuth and Explore useChat.
    • Attached X-Participant-Token via one shared explicit helper (participantTokenConfig / participantTokenHeaders) at every participant conversation API call: upload URL, upload confirmation, text upload, finish, summary, conversation/chunk/reply polling, chunk delete, S3 connectivity check, heartbeat and keepalive leave pings, report subscription, Explore replies (useChat), and Verify artifact generation, listing, fetching, revision, and approval.
    • Added frontend unit tests covering sessionStorage storage, private-browsing fallback, initiate capture, header attachment, finish/start clearing, and 403 token-rejection clearing.

Verification

  • Platform: bun test (57/57 passing in packages/conversations unit tests), bunx biome ci ., bun run typecheck.
  • Frontend: vitest run src/portal src/lib (51 files, 398/398 passing), pnpm lint, pnpm exec tsc, pnpm messages:extract, pnpm messages:compile, node scripts/check-translations.mjs --strict, node scripts/sync-accounts-contract.mjs --check, node scripts/sync-error-codes.mjs --check, pnpm run check:case.

Review fixes (supersede the Changes above where they differ)

  • Tokens are cleared only on participant.token_invalid, not on a bare 403.
  • When a request sent with a token gets that error, the client retries it once without the token, so a chunk upload is not lost while tokens are optional. The server checks the token before any side effect, so the retry cannot double-write.
  • The finish page keeps the token while it is open, because summary and Verify still need it. It clears the token when the participant leaves. The clear is deferred per conversation, so a React StrictMode remount does not wipe it.
  • getVerificationArtefactById and updateVerificationArtefact now require conversationId.
  • Checked on the local stack: record, Verify, approve and finish all work with the token; a forged token retries and the chunk lands.

Known limits

  • The retry only helps while PARTICIPANT_TOKEN_REQUIRED is off.
  • The token lives in sessionStorage until the finish page is left or the tab closes.

@JorimTheuns
JorimTheuns force-pushed the feat/portal-participant-token branch from da5f99b to 2ffc356 Compare November 30, 2026 12:15
@JorimTheuns
JorimTheuns changed the base branch from main to fix/verify-manual-edit-pii-redaction November 30, 2026 12:15
@JorimTheuns
JorimTheuns force-pushed the fix/verify-manual-edit-pii-redaction branch from 98ffb51 to 7c2d14e Compare December 1, 2026 22:29
@JorimTheuns
JorimTheuns force-pushed the feat/portal-participant-token branch from 24b8fbb to ee3da74 Compare December 1, 2026 22:33
… it on finish

- A participant.token_invalid answer clears the stored token and resends the call
  once without it (the server checks the token before doing anything), so a chunk
  upload is not lost. The retry logs a warning.
- Only participant.token_invalid counts as a rejection; other 403s keep the token.
- The finish screen keeps the token while open (report sign-up, the landscape
  step) and clears it on leaving, deferred so StrictMode's dev remount does not
  count; /start still clears every token.
- Verify helpers take the conversation id as a required string.
…participant-token

# Conflicts:
#	dembrane/frontend/src/locales/cs-CZ.po
#	dembrane/frontend/src/locales/de-DE.po
#	dembrane/frontend/src/locales/en-US.po
#	dembrane/frontend/src/locales/es-ES.po
#	dembrane/frontend/src/locales/fr-FR.po
#	dembrane/frontend/src/locales/it-IT.po
#	dembrane/frontend/src/locales/nl-NL.po
#	dembrane/frontend/src/locales/uk-UA.po

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants