mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-02 02:12:25 +00: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:
parent
a973e77cfa
commit
443736e1fe
1 changed files with 2 additions and 2 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue