mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #23548] [CLOSED] feat: add database-agnostic chat encryption at rest (WEBUI_CHAT_ENCRYPTION_KEY / WEBUI_CHAT_ENCRYPT_OLD_CHATS) #50297
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/23548
Author: @kraack-tech
Created: 4/9/2026
Status: ❌ Closed
Base:
dev← Head:main📝 Commits (10+)
fe6783cMerge pull request #19030 from open-webui/devfc05e0aMerge pull request #19405 from open-webui/deve3faec6Merge pull request #19416 from open-webui/dev9899293Merge pull request #19448 from open-webui/dev140605eMerge pull request #19462 from open-webui/dev6f1486fMerge pull request #19466 from open-webui/devd95f533Merge pull request #19729 from open-webui/deva7271530.6.43 (#20093)6adde20Merge pull request #20394 from open-webui/devf9b0534Merge pull request #20522 from open-webui/dev📊 Changes
14 files changed (+639 additions, -496 deletions)
View changed files
📝
backend/open_webui/env.py(+13 -13)📝
backend/open_webui/main.py(+8 -54)📝
backend/open_webui/models/chats.py(+107 -299)📝
backend/open_webui/routers/audio.py(+1 -0)📝
backend/open_webui/routers/auths.py(+44 -4)📝
backend/open_webui/routers/chats.py(+33 -42)📝
backend/open_webui/routers/ollama.py(+7 -5)➕
backend/open_webui/test/apps/webui/models/test_chats_encryption.py(+96 -0)➕
backend/open_webui/test/util/test_chat_encryption.py(+60 -0)➕
backend/open_webui/test/util/test_encrypt_old_chats.py(+78 -0)📝
backend/open_webui/utils/auth.py(+1 -3)➕
backend/open_webui/utils/db/chat_encryption.py(+99 -0)➕
backend/open_webui/utils/db/encrypt_old_chats.py(+79 -0)📝
backend/open_webui/utils/oauth.py(+13 -76)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
Before submitting, make sure you've checked the following:
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:
WEBUI_CHAT_ENCRYPTION_KEY: When set, chat content is encrypted before being written to the database and transparently decrypted on read. The UI experience is unchanged.WEBUI_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.
Added
WEBUI_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.WEBUI_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.backend/open_webui/test/util/test_chat_encryption.pybackend/open_webui/test/util/test_encrypt_old_chats.pybackend/open_webui/test/apps/webui/models/test_chats_encryption.pyChanged
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/auths.py: trigger old-chat encryption task on user sign-in whenWEBUI_CHAT_ENCRYPT_OLD_CHATS=true.backend/open_webui/env.py: exposeWEBUI_CHAT_ENCRYPTION_KEYandWEBUI_CHAT_ENCRYPT_OLD_CHATSconfiguration.backend/open_webui/main.py: initialise encryption configuration at startup.Deprecated
Removed
Fixed
Security
WEBUI_CHAT_ENCRYPTION_KEYis configured. This prevents direct database access or database exports from exposing user chat content in plaintext, including admin-level accounts.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.