安全性更新

This commit is contained in:
Sahik committed 2026-11-25 15:57:10 +08:00
1 parent 5bd77d2599
commit e75f0c95e9
29 files changed
+726 -143

No files matched your search

+4 -1
View File
@@ -131,12 +131,15 @@ def _migrate(conn: sqlite3.Connection) -> None:
def _init_admin(conn: sqlite3.Connection) -> None:
"""建立或更新管理員帳號(uid 0)。改了 ADMIN_LOGIN 重啟就會生效。"""
global admin_ok
from . import totp
from . import limits, totp
admin_ok = False
login, secret = config.ADMIN_LOGIN, config.ADMIN_TOTP
if not login or not secret:
return
if not limits.valid_email(login):
print("[ERROR] ADMIN_LOGIN 要是信箱格式(例如 [email protected],不會真的寄信),管理員登入停用", flush=True)
return
try:
if len(totp.decode_secret(secret)) < 10:
raise ValueError("too short")