4. Security — BYOK Encryption, SSRF, Prompt Injection
Q4.1 — Walk me through your BYOK (Bring Your Own Key) implementation end-to-end.
Short: User pastes their OpenAI key in the UI, the client POSTs it to /api/settings/api-key, the server validates the format with regex, encrypts it with AES-256-GCM using a server-side master key, stores the ciphertext in the User.encryptedApiKey column. On chat requests, the server decrypts it, uses it for the LLM call, and never returns the plaintext to the client (only a masked version like sk-...XXXX).
In-depth: