Reject invalid cookbook CLI state (#1531)

This commit is contained in:
red person
2026-06-03 08:11:56 +03:00
committed by GitHub
parent 2f6d339073
commit dfbc94f929
2 changed files with 32 additions and 0 deletions

View File

@@ -411,6 +411,8 @@ def cmd_state_set(args) -> None:
obj = json.loads(data)
except json.JSONDecodeError as e:
fail(f"invalid JSON on stdin: {e}")
if not isinstance(obj, dict):
fail("invalid cookbook state: expected a JSON object")
_STATE_PATH.parent.mkdir(parents=True, exist_ok=True)
# Backup the existing state — undo button if a bad pipe clobbers it.
if _STATE_PATH.exists():