1 KiB
1 KiB
Token Storage & Encryption-at-Rest Architecture
This document describes how user access and refresh tokens are protected at rest.
1. Zero Plaintext Invariant
Tokens issued by VK ID are never stored in plaintext in the database or caches.
2. AES-256-GCM Token Vault (src/lib/auth/token-vault.ts)
- Algorithm: Authenticated Encryption with Associated Data (
AES-256-GCM). - Key Derivation: 256-bit key derived via
SHA-256fromTOKEN_ENCRYPTION_KEYorAUTH_SECRET. - Initialization Vector (IV): 12 bytes (96 bits) of fresh cryptographic randomness generated per encryption operation.
- Authentication Tag: 16 bytes (128 bits) ensuring ciphertext integrity against tampering.
- Format:
iv_hex:authTag_hex:ciphertext_hex
3. Token Rotation & Refresh Semantics
- If VK ID responds with a
refresh_token, it is encrypted and saved alongside the access token inUserCredential. - Invalidation: Calling
/api/auth/logoutdestroys the user session and local credential cache.