fix: setup routing, async bcrypt, password hashing, clean command
- Add SetupGuard component: redirects to /setup if setup not complete, shown as spinner while loading. All routes except /setup now wrapped. - SetupPage redirects to /login on mount when setup already done. - Fix async blocking: offload bcrypt.hashpw and bcrypt.checkpw to run_in_executor so they never stall the asyncio event loop. - Hash password with SHA-256 (SubtleCrypto) before transmission; added src/utils/crypto.ts with sha256Hex(). Backend stores bcrypt(sha256). - Add Makefile with make up/down/restart/logs/clean targets. - Add tests: _check_password async, concurrent bcrypt, expired session, login-without-setup, run_setup event-loop interleaving. - Update Architekture.md and Features.md to reflect all changes.
This commit is contained in:
@@ -7,6 +7,7 @@ enforcing the rule that setup can only run once.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import bcrypt
|
||||
@@ -72,8 +73,13 @@ async def run_setup(
|
||||
log.info("bangui_setup_started")
|
||||
|
||||
# Hash the master password — bcrypt automatically generates a salt.
|
||||
# Run in a thread executor so the blocking bcrypt operation does not stall
|
||||
# the asyncio event loop.
|
||||
password_bytes = master_password.encode()
|
||||
hashed = bcrypt.hashpw(password_bytes, bcrypt.gensalt()).decode()
|
||||
loop = asyncio.get_running_loop()
|
||||
hashed: str = await loop.run_in_executor(
|
||||
None, lambda: bcrypt.hashpw(password_bytes, bcrypt.gensalt()).decode()
|
||||
)
|
||||
|
||||
await settings_repo.set_setting(db, _KEY_PASSWORD_HASH, hashed)
|
||||
await settings_repo.set_setting(db, _KEY_DATABASE_PATH, database_path)
|
||||
|
||||
Reference in New Issue
Block a user