From a901992d03008dcc08a3f584041afc0b1010a36f Mon Sep 17 00:00:00 2001 From: red person Date: Tue, 2 Jun 2026 18:55:04 +0300 Subject: [PATCH] Ignore non-object vault config (#1258) --- routes/vault_routes.py | 3 ++- tests/test_vault_password_not_in_argv.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/routes/vault_routes.py b/routes/vault_routes.py index 17a635d..b04ba33 100644 --- a/routes/vault_routes.py +++ b/routes/vault_routes.py @@ -61,7 +61,8 @@ def _find_bw() -> str: def _load_config() -> dict: if VAULT_FILE.exists(): try: - return json.loads(VAULT_FILE.read_text(encoding="utf-8")) + data = json.loads(VAULT_FILE.read_text(encoding="utf-8")) + return data if isinstance(data, dict) else {} except Exception: pass return {} diff --git a/tests/test_vault_password_not_in_argv.py b/tests/test_vault_password_not_in_argv.py index df3d50d..2e05ed7 100644 --- a/tests/test_vault_password_not_in_argv.py +++ b/tests/test_vault_password_not_in_argv.py @@ -13,6 +13,7 @@ vault) to any local user for the lifetime of the unlock subprocess. """ import os +import json import re import sys import types @@ -98,3 +99,11 @@ def test_unlock_handler_uses_passwordenv_not_argv(): # And the secure shape must be present. assert "--passwordenv" in text assert re.search(r"bw_password\s*=\s*req\.master_password", text) + + +def test_load_config_ignores_non_object_json(tmp_path, monkeypatch): + vault_file = tmp_path / "vault.json" + vault_file.write_text(json.dumps(["not", "a", "config", "object"]), encoding="utf-8") + monkeypatch.setattr(vr, "VAULT_FILE", vault_file) + + assert vr._load_config() == {}