Skip to content

perf(auth): load the encryption key once and derive purpose keys #658

Backlog

Description

@RentnerKev

Problem

  • getEncryptionKey re-reads the key file and re-imports the key on every encrypt and decrypt (web/src/server/Auth/Core/encryption.server.ts:18-33, web/src/server/env.server.ts:43-98, :244-246). That is about six blocking file syscalls plus importKey per operation, on the event loop. A page of 100 app events with cursors repeats it 100 times.
  • The raw key is used directly for stored secrets, app event cursors (web/src/server/AppRuntime/events.server.ts:76) and frame tokens (web/src/server/AppRuntime/ui/assets.server.ts:38). Purposes are separated only by AES-GCM additional data, and they share one key and one nonce budget.

Proposal

  • Load and import the key once at startup.
  • Derive separate keys per purpose with HKDF-SHA256 (stored secrets, cursors, frame and asset tokens).
  • Keep decrypting existing stored secrets: version the ciphertext format and re-encrypt lazily or in a migration. Cursors and frame tokens are short-lived and can switch directly.

Acceptance

  • Test: encrypt/decrypt does no file I/O after startup.
  • Test: existing stored secrets still decrypt after the change; a token sealed for one purpose does not open under another.

Found in the app platform audit of 2026-11-30.

Activity

  1. added
    enhancement
    area: auth
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: authenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions