mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-08 04:16:03 -05:00
[PR #23574] [CLOSED] feat: add chat encryption at rest (v2) #50307
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23574
Author: @kraack-tech
Created: 4/10/2026
Status: ❌ Closed
Base:
dev← Head:feat/chat-encryption-fixes-v2📝 Commits (3)
1a8f7d5feat: add chat encryption at rest (v2)7aea7fafix: preserve string semantics and guard pin toggle null path9bae142fix: safe enqueue and deterministic backfill of old-chat encryption + handle invalid keys📊 Changes
7 files changed (+506 additions, -60 deletions)
View changed files
📝
backend/open_webui/env.py(+16 -0)📝
backend/open_webui/models/chat_messages.py(+53 -10)📝
backend/open_webui/models/chats.py(+50 -27)📝
backend/open_webui/routers/auths.py(+30 -1)📝
backend/open_webui/routers/chats.py(+34 -22)➕
backend/open_webui/utils/db/chat_encryption.py(+136 -0)➕
backend/open_webui/utils/db/encrypt_old_chats.py(+187 -0)📄 Description
Pull Request Checklist
devbranch. PRs targetingmainwill be immediately closed.devto ensure no unrelated commits (e.g. frommain) are included. Push updates to the existing PR branch instead of closing and reopening.Changelog Entry
Description
Adds application-level encryption of chat content at rest, controlled by two environment variables:
DATABASE_CHAT_ENCRYPTION_KEY: When set, chat content is encrypted before being written to the database (chat/chat_message tables) and and transparently decrypted on read. The UI experience is unchanged.DATABASE_CHAT_ENCRYPT_OLD_CHATS: Whentrue, schedules per-user background encryption of existing plaintext chats at sign-in, avoiding bulk-operation container timeouts. Once all historical chats are encrypted the flag can be disabled.This is a database-agnostic solution that specifically addresses deployments using PostgreSQL (e.g. on Azure or AWS) where the existing SQLCipher approach is not applicable, as confirmed in Discussion #21469.
Outcome: Admin users can no longer view user chat content in plaintext via database exports or direct database access. Both features are optional and entirely controlled with the environment variables.
Changes from v1 (prior closed PR)
Added
DATABASE_CHAT_ENCRYPTION_KEYenv var: enables encryption of chat content at rest. Encryption is idempotent: plaintext content is detected and encrypted; already-encrypted content is left untouched.DATABASE_CHAT_ENCRYPT_OLD_CHATSenv var: whentrue, triggers per-user background encryption of historical plaintext chats on sign-in.backend/open_webui/utils/db/chat_encryption.py: centralised encrypt/decrypt helper functions.backend/open_webui/utils/db/encrypt_old_chats.py: batch encryption utility function for historical chats.Changed
backend/open_webui/env.py: ExposeDATABASE_CHAT_ENCRYPTION_KEYandDATABASE_CHAT_ENCRYPT_OLD_CHATSconfiguration.backend/open_webui/main.py: Initialise encryption configuration at startup.backend/open_webui/models/chats.py: Encrypt chat content on write; decrypt (normalise) on read so the UI always receives plaintext.backend/open_webui/routers/chats.py: Normalise chat payloads before returning to callers.backend/open_webui/routers/chat_messages.py: Normalise chat_messages payloads before returning to callers.backend/open_webui/routers/auths.py: Trigger old-chat encryption task on user sign-in whenDATABASE_CHAT_ENCRYPT_OLD_CHATS=true.Deprecated
Removed
Fixed
Security
Breaking Changes
Additional Information
Screenshots or Videos
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.