← Back to Pull requests

feat(frontend): pass session token to the crypto worker (#170) #213

Closed
unknown closed this pull request without merging on Nov 11, 2026 22:33 UTC
View on GitHub
unknown unknown commented on Nov 11, 2026 04:06 UTC
Author

What and why

Closes #170. The crypto worker read a build-time VITE_DEV_JWT and kept one vault, with a fixed token, for its whole life. Binding browser keys to the signed-in identity (#175) needs the session identity inside the worker.

  • New session worker message (protocol.ts) delivers the bearer token. DriveWorkerClient sends the dev token as its first message in development, and setSession(token) delivers refreshed tokens (and later the real session tokens from P32).

  • The worker holds the token and its iss/sub/tid claims in memory only (never localStorage or IndexedDB) and no longer reads vaultConfig.devJwt.

  • HttpVault reads the current token on every request, so a refreshed token applies without restarting the worker.

  • decodeSessionClaims() decodes the claims without verifying the signature (the browser cannot check HS256). The API verifies every request; the API accepting the same token is what makes tid authoritative. typ, exp and aud are left to the API.

  • A malformed token clears the session instead of keeping the previous one.

  • In http vault mode, vault calls are refused before any request leaves the worker when no token is set.

  • Claims are copied into a new DriveContext.session field when each operation starts, so one operation never mixes identities. #175 will use it to switch the key store and AAD from the random UUID to the session tid. That work should also check tid against the current token, so a mid-upload refresh can't move chunks to another tenant.
  • How it was tested

  • protocol.test.ts: parser accepts and rejects session messages. The decoder reads iss/sub/tid and rejects malformed tokens (wrong number of segments, bad base64, invalid JSON, missing, empty or non-string claims).

  • worker.test.ts (new) sends messages through the worker:

  • - delivering a token exposes its claims to the crypto core and sends the matching Authorization header
    - a refreshed token is used for the next request without a restart
    - a malformed token is refused, the earlier session is cleared, and no claims are exposed
    - in http mode without a token, vault calls are refused and fetch is never called
    - the token never appears in a worker response
  • Manual: end-to-end in http mode with a devtoken token (upload, list, download, delete), then with VITE_DEV_JWT cleared (the drive reports "no session token").
  • Checklist

  • scripts/check.sh passes locally

  • Every new refusal has a negative test

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs

  • Fails closed on missing configuration, key material, or attestation

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md)

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made
  • Diff: 369 lines (+276 / -93) across 4 files Reviewer: abendrothj Review duration: 1107m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.66) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.66 · 369 lines diff across 4 files
    0.66
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.354
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.066
    Real PR Conversation Timeline
    1 comments
    "Review active on #213"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 66.0% (HIGH) · Higher = larger blast radius
    66.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.5% · Safe to merge
    28.5%