mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-26 17:30:27 -04:00
refactor: use secrets module for generated secret key (#30441)
Generates the default WEBUI_SECRET_KEY file with secrets.token_bytes, matching how the start scripts read from the OS random source.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import base64
|
||||
import os
|
||||
import random
|
||||
import secrets
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Annotated
|
||||
@@ -45,7 +45,7 @@ def serve(
|
||||
if key_length < 1:
|
||||
raise ValueError('WEBUI_SECRET_KEY_LENGTH must be a positive integer')
|
||||
typer.echo(f'Generating a new secret key and saving it to {KEY_FILE}')
|
||||
KEY_FILE.write_bytes(base64.b64encode(random.randbytes(key_length)))
|
||||
KEY_FILE.write_bytes(base64.b64encode(secrets.token_bytes(key_length)))
|
||||
typer.echo(f'Loading WEBUI_SECRET_KEY from {KEY_FILE}')
|
||||
os.environ['WEBUI_SECRET_KEY'] = KEY_FILE.read_text()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user