From 864d9e79c37df7fc4300f736e8f76421cb4ac70b Mon Sep 17 00:00:00 2001 From: dhonitheja Date: Mon, 23 Nov 2026 15:49:28 +0000 Subject: [PATCH] Verifiers: a blank Stripe refund id is unverified, never verified A refund id of "" or whitespace passed the empty check, became a snapshot key, and let an otherwise matching refund return verified. FHIR Appointment ids were already rejected; this adds end-to-end regression cases for blank FHIR ids and actor shapes too. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ agent_readback/verifiers/stripe.py | 3 ++- tests/test_fhir_verifier.py | 3 +++ tests/test_stripe_sql_alerts.py | 13 +++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf119b6..8eb69a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ All notable changes to `agent-readback`. Dates are UTC. (`tabindex="0"`), is a labelled region named by its heading, and has a visible focus outline, so keyboard users can scroll it in any browser. Column headers carry `scope="col"` and each table is labelled by its heading. +- Stripe: a refund whose id is empty or only whitespace is now a malformed + read (`unverified`). It used to pass the id check, become a snapshot key, and + could return `verified` for an otherwise matching claim. FHIR already + rejected such Appointment ids; both now have end-to-end regression tests. ## 0.3.1 — 2026-11-22 diff --git a/agent_readback/verifiers/stripe.py b/agent_readback/verifiers/stripe.py index def02fd..dd2c787 100644 --- a/agent_readback/verifiers/stripe.py +++ b/agent_readback/verifiers/stripe.py @@ -78,7 +78,8 @@ def _refunds(self, payment_intent: str) -> dict[str, dict[str, Any]]: if not isinstance(items, list) or not isinstance(has_more, bool): raise ValueError("malformed Stripe response: data is not a list or has_more is not a boolean") for item in items: - if not isinstance(item, dict) or not isinstance(item.get("id"), str) or not item["id"]: + if not isinstance(item, dict) or not isinstance(item.get("id"), str) or not item["id"].strip(): + # A blank id would become a snapshot key and let a malformed refund verify a claim. raise ValueError("malformed Stripe response: refund without a string id") found[item["id"]] = {name: item.get(name) for name in FIELDS} if not has_more: diff --git a/tests/test_fhir_verifier.py b/tests/test_fhir_verifier.py index 9bb7e0c..1e7abde 100644 --- a/tests/test_fhir_verifier.py +++ b/tests/test_fhir_verifier.py @@ -284,7 +284,10 @@ def handle(request): "bundle without resourceType": {"entry": []}, "matched entry is not an Appointment": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Patient", "id": "p1"}}]}, "appointment without an id": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment"}}]}, + "appointment id is empty": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": ""}}]}, + "appointment id is whitespace": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": " "}}]}, "actor is a list": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": "a1", "participant": [{"actor": []}]}}]}, + "actor is an empty dict list": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": "a1", "participant": [{"actor": [{}]}]}}]}, "actor is an empty string": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": "a1", "participant": [{"actor": ""}]}}]}, "entry search is a string": {"resourceType": "Bundle", "entry": [{"search": "match", "resource": {"resourceType": "Appointment", "id": "a1"}}]}, } diff --git a/tests/test_stripe_sql_alerts.py b/tests/test_stripe_sql_alerts.py index 9f6407f..773f889 100644 --- a/tests/test_stripe_sql_alerts.py +++ b/tests/test_stripe_sql_alerts.py @@ -403,6 +403,8 @@ def sync_auth_flow(self, request): "page is a list": [], "refund is a string": {"data": ["re_1"], "has_more": False}, "refund id is a number": {"data": [{"id": 7}], "has_more": False}, + "refund id is empty": {"data": [{"id": ""}], "has_more": False}, + "refund id is whitespace": {"data": [{"id": " "}], "has_more": False}, "has_more is a string": {"data": [], "has_more": "false"}, "data is an object": {"data": {"id": "re_1"}, "has_more": False}, "error body with 200": {"error": {"type": "api_error", "message": "x"}}, @@ -453,3 +455,14 @@ def test_has_more_with_an_empty_page_is_an_incomplete_read_not_verified(): before = verifier.snapshot(REFUND) assert before == set() assert verifier.check(REFUND, before).status is Status.UNVERIFIED + + +def test_blank_refund_id_never_verifies_an_otherwise_matching_refund(): + # Stripe ids never contain whitespace; a blank one is a malformed read, not a new refund to verify against. + blank = {"id": " ", "amount": 2500, "currency": "usd", "status": "succeeded", "payment_intent": "pi_1"} + pages = [{"data": [], "has_more": False}, {"data": [blank], "has_more": False}] + transport = httpx.MockTransport(lambda request: httpx.Response(200, json=pages.pop(0) if len(pages) > 1 else pages[0])) + with httpx.Client(transport=transport, base_url="https://stripe.test") as client: + verifier = StripeRefundVerifier(client) + verdict = verifier.check(REFUND, verifier.snapshot(REFUND)) + assert verdict.status is Status.UNVERIFIED and kinds(verdict) == [FindingKind.UNREACHABLE]