mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 19:38:46 -05:00
[PR #624] [MERGED] Improve Session Security #20399
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/624
Author: @explorigin
Created: 2/2/2024
Status: ✅ Merged
Merged: 2/4/2024
Merged by: @tjbck
Base:
main← Head:session-security📝 Commits (10+)
d67f3d9Start by renaming variables to something more generic. This will give us a bit more flexibility as we look to other session management mechanisms.03a7e35Default docker installations should generate a random key instead of using a static secret that everyone can see.2c1dacbWe should verify signatures to make the whole session secret meaningful.8c37eddEven though "User.email" is enforced as unique at signup, it is not a unique field in the database. Let's use "User.id" instead. This also makes it more difficult to do a session stealing attack.e15dbdcPass the instance we're using.4fceb40Calljwt.decodewith the expected algorithms44799e2Remove some extraneous importse2d481dMove the random secret generation to start.sh.1031638Maintain backward compatibility with WEBUI_JWT_SECRET_KEY for the time being8298cefFix bash condition formatting📊 Changes
8 files changed (+34 additions, -23 deletions)
View changed files
📝
Dockerfile(+1 -1)📝
backend/apps/web/models/auths.py(+1 -6)📝
backend/apps/web/routers/auths.py(+2 -2)📝
backend/apps/web/routers/chats.py(+0 -3)📝
backend/config.py(+6 -3)📝
backend/start.sh(+16 -1)📝
backend/utils/utils.py(+7 -7)📝
docker-compose.yaml(+1 -0)📄 Description
This PR changes a few things around how sessions are handled in order to improve security.
Problem 1: The session secret is hard-coded. Few people will provide their own thus the security of the whole project is a risk for everyone who deploys it.
Solution: One first run, the start script generates a randomly generated session key and stores it to a file. If no secret key is provided, the start script will grab this one. WEBUI_JWT_SECRET_KEY is still accepted. I flagged the line in config.py to be deprecated in the next major release.
Problem 2: JWT signatures were not verified. This makes session stealing easy.
Solution: Remove the option turning off jwt signature verification.
Problem 3: JWTs use email address as the primary method to identify a user. This makes step 2 involve no guesswork at all. If you know someone has session, you can just build the correctly formed JWT and BE them.
Solution: Use database user ids in the JWT instead.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.