Skip to content

The agent that grows with you

fix(gateway-windows): attestation PID list accepts exact positive ints only

kshitijk4pooraec8a58611db
diff --git a/hermes_cli/gateway_windows.py b/hermes_cli/gateway_windows.py
index 91cc7bafa4d..b20c8cb98a3 100644
--- a/hermes_cli/gateway_windows.py
+++ b/hermes_cli/gateway_windows.py
@@ -903,9 +903,11 @@ def _attested_pids_from(data: object) -> list[int]:
return []
pids = data.get("pids")
# Fail closed: a null/malformed marker must never authorize a cold start (or raise on iteration).
- if not isinstance(pids, list):
+ # Exact positive ints only — ``isinstance(True, int)`` holds, and 0 / negatives are not PIDs; one
+ # bad item taints the whole list because the writer never emits such values.
+ if not isinstance(pids, list) or not all(type(p) is int and p > 0 for p in pids):
return []
- return [p for p in pids if isinstance(p, int)]
+ return list(pids)
def _attested_pid_exited_cleanly(pid: int) -> bool:
diff --git a/tests/hermes_cli/test_gateway_start_attestation.py b/tests/hermes_cli/test_gateway_start_attestation.py
index 2f83db97773..e38a3f6f26e 100644
--- a/tests/hermes_cli/test_gateway_start_attestation.py
+++ b/tests/hermes_cli/test_gateway_start_attestation.py
@@ -207,7 +207,12 @@ def test_attested_probe_fails_closed_without_a_well_formed_dead_attestation(atte
assert gateway_windows.attested_gateway_died(current_pids=[]) is False # no marker yet
marker.parent.mkdir(exist_ok=True)
- for malformed in ('{"pids": null}', '{"pids": 555}', '["not", "a", "dict"]', "not json"):
+ # Exact positive ints only: ``True`` is an int subclass, 0/-1 are not PIDs, and a single
+ # malformed item taints the list (the writer never emits such values).
+ for malformed in (
+ '{"pids": null}', '{"pids": 555}', '["not", "a", "dict"]', "not json",
+ '{"pids": [true]}', '{"pids": [0]}', '{"pids": [-1]}', '{"pids": [555, "556"]}', '{"pids": [555, 0]}',
+ ):
marker.write_text(malformed, encoding="utf-8")
assert gateway_windows.attested_gateway_died(current_pids=[]) is False, malformed