mirror of
https://github.com/open-webui/open-webui.git
synced 2026-06-05 00:10:27 -05:00
[PR #23721] feat: encrypt user valve values at rest using Fernet #50381
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/23721
Author: @ethan-l-geotab
Created: 4/14/2026
Status: 🔄 Open
Base:
dev← Head:feature/encrypt-user-valves📝 Commits (1)
8cf75e5feat: encrypt user valve values at rest using Fernet📊 Changes
4 files changed (+169 additions, -6 deletions)
View changed files
➕
backend/open_webui/internal/migrations/019_encrypt_user_valves.py(+116 -0)📝
backend/open_webui/models/functions.py(+5 -3)📝
backend/open_webui/models/tools.py(+5 -3)➕
backend/open_webui/utils/valve_encryption.py(+43 -0)📄 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
User valves (per-user API keys and configuration for tools and functions) are stored as plaintext JSON in the
user.settingscolumn in the database. This is a security concern since valve values often contain sensitive data such as API keys. This PR adds Fernet symmetric encryption at the model layer so user valve data is encrypted at rest, while remaining fully transparent to the API and UI layers.Related issue: https://github.com/open-webui/open-webui/issues/20852 (complementary — that issue covers UI password masking, this covers at-rest encryption)
Added
backend/open_webui/utils/crypto.py— Fernet-basedencrypt_user_valves()anddecrypt_user_valves()helpers, usingWEBUI_SECRET_KEYfor encryption with automatic key derivation019_encrypt_user_valves.pyto encrypt all existing plaintext valve data in-place on upgrade using raw SQL (avoids Peewee ORM schema mismatches)decrypt_user_valves()transparently handles both legacy plaintext dicts and encrypted strings, so no data loss occurs during the transitionChanged
backend/open_webui/models/tools.py—get_user_valves_by_id_and_user_id()now decrypts on read;update_user_valves_by_id_and_user_id()now encrypts on writebackend/open_webui/models/functions.py— Same encrypt-on-write / decrypt-on-read wiring for function user valvesDeprecated
Removed
Fixed
Security
oauth_sessions.py) and OAuth client info (oauth.py) in the codebaseBreaking Changes
Additional Information
cryptographylibrary which is already a project dependency (used by OAuth encryption)WEBUI_SECRET_KEYdirectly for encryption, consistent with the existing OAuth encryption patternSELECT id, settings FROM "user") instead of the Peewee ORM to avoid schema mismatch issues with columns that may have been added or removed between versionsScreenshots or Videos
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.