AP2 icon indicating copy to clipboard operation
AP2 copied to clipboard

Constraint evaluation is presence-driven: a withheld disclosure silently disables enforcement (+ budget.max unit is undocumented)

Open CODER7657 opened this issue 3 months ago • 2 comments

Two related issues in the Python SDK's constraint layer, found while building a verification layer against AP2.

Both were reported through the Google OSS VRP (issues 551304805, 551303152) and closed as Won't Fix (Intended Behavior). The reviewer confirmed the mechanism and suggested I raise it here:

"You've clearly identified a mechanism where a selectively withheld constraint could lead to a permissions bypass, potentially allowing reported over-cap payments."

"We still encourage you to open an issue or submit a pull request directly on the GitHub repository to help the maintainers address this."

I'm filing this as a documentation and API-safety issue rather than a vulnerability report. If the behaviour is intended — and I accept that it is — the remaining risk is that integrators won't realise what an empty violation list does and does not mean.

Tested against e1ea56db72a6385bce3e5c1112b3a56ce60acb43 (current main), Python 3.13.2.


1. An empty violation list does not mean the constraints were satisfied

create_payment_evaluator() is invoked once per constraint found in the OpenPaymentMandate. There is no step asserting which constraints should be present, so a constraint that is not disclosed produces no evaluator and therefore no violation.

check_preset_payment_claims() documents the same shape:

"If a field is set in the open mandate, the closed mandate must contain an identical value."

A field that is not set is not checked. ExecutionDateEvaluator shows it directly: if not exec_date: return [].

Separately, DisclosureMetadata accepts arbitrary sd_array_indices, so an issuer can mark entries of the constraints array selectively disclosable. That seems like a reasonable thing for an issuer to want — not revealing a customer's total budget to a merchant is close to the motivating use case for SD-JWT here.

Composed, the privacy feature disables the enforcement mechanism.

Reproduction

Full script: spike_chain_e2e.py

issuer marks constraints[0..1] selectively disclosable:
    DisclosureMetadata(children={"constraints":
        DisclosureMetadata(sd_array_indices=[0, 1])})

open mandate  : [Budget(max=5000.0, currency="INR"), AllowedPayees([merchant])]
closed mandate: 750000 paise (INR 7,500) -- above the INR 5,000 cap
hash_mode     : sd_hash (the default)
Presentation verify() constraints visible violations outcome
full disclosure passes payment.budget, payment.allowed_payees 1 blocked
Budget withheld passes none 0 allowed

The blocked case reports Cumulative spend 750000 exceeds budget limit 500000 (past spend: 0). The allowed case reports nothing — correctly, since nothing remained to evaluate.

What this is not

Stated explicitly so it isn't read as more than it is:

  • Not a signature forgery or chain-integrity break. verify_chain behaves correctly throughout.
  • The redaction is performed by the legitimate holder through the documented claims_to_disclose parameter, not injected by an unauthorised party.
  • I used the default hash_mode="sd_hash". I have not demonstrated a downstream delegate stripping a disclosure under issuer_jwt_hash, though the SDK README describes that mode as permitting exactly that. I'd genuinely be interested in whether that path is reachable adversarially.
  • Single delegation hop, and the withheld disclosure removed the whole constraints array rather than the Budget entry alone.

Suggested changes

In order of preference:

  1. A verifier-side API to declare required constraint types, raising if any are absent from the presented mandate.
  2. Return coverage metadata alongside violations, so an integrator can assert completeness rather than infer it.
  3. At minimum: document in the SDK README that an empty violation list does not imply the constraints were present, and that integrators should pin their expected constraint set.

Happy to open a PR for (2) or (3) if either would be welcome.


2. Budget.max and AmountRange.max use different units

payment.amount_range.max is documented as:

"Maximum allowed amount in minor (cents) unit of currency."

and AmountRangeEvaluator compares directly, which is correct:

and amount.amount > self.constraint.max

payment.budget.max is documented as:

"Maximum amount for the budget."

No unit stated. But BudgetEvaluator multiplies by 100:

budget_max_cents = int(self.constraint.max * 100)
if total_spend > budget_max_cents:

So budget.max is in major units and amount_range.max is in minor units, in the same module, with only one of the two saying which.

Impact

An issuer populating budget.max in minor units — consistent with its sibling constraint, and with Amount.amount — gets a cap 100x larger than intended. An INR 5,000 cap silently becomes INR 500,000. Enforcement looks like it is working: the evaluator runs, returns no violation, the transaction is authorised.

I hit this myself on first implementation, using the schema descriptions as the guide. I set Budget(max=5000.0) against a charge of 47500 paise and expected a violation; there is none, because the effective ceiling is 500000 paise.

Suggested change

A one-line clarification in code/sdk/schemas/ap2/open_payment_mandate.json:

"max": {
  "type": "number",
  "description": "Maximum amount for the budget, in the major unit of the currency (e.g. 5000.0 is 5000 rupees, not 5000 paise). Note this differs from payment.amount_range.max, which is expressed in the minor unit."
}

I'm happy to send that as a PR — I'll sign the CLA first. Aligning both constraints on minor units would be cleaner still, but that's a breaking change and your call, not mine.


Context, for transparency: I built PRAMANA, an open-source verification layer that treats an unevaluated constraint as indeterminate rather than satisfied. So I have an interest in this area. The two issues above stand on their own regardless, and I'd rather they were fixed upstream than kept as a reason for my project to exist.

CODER7657 avatar Aug 23 '26 14:08 CODER7657

The agent_recurrence handling in check_payment_constraints already does the thing this issue is asking for, just scoped to one case:

if has_recurrence:
    if not has_amount:
        violations.append('payment.agent_recurrence requires payment.amount_range constraint')
    if not has_budget:
        violations.append('payment.agent_recurrence requires payment.budget constraint')

That is a required-presence assertion. A constraint that should be there and isn't produces a violation instead of silence. The loop below it evaluates only what happens to be present, so the same absence is a clean pass.

So the gap looks narrower than "presence-driven evaluation is intended". The SDK already has the pattern, it just isn't reachable for a verifier that wants to say "I expect payment.budget to have been evaluated on this mandate".

Separately, the return type may be doing some of the damage. check_payment_constraints returns list[str], so an empty list means either every constraint was evaluated and satisfied, or nothing was evaluated. Returning the set of constraints that were actually evaluated alongside the violations would let a caller assert its own expected set, without changing any disclosure semantics.

On the issuer_jwt_hash question left open above: curious whether anyone has checked if a downstream delegate can strip a disclosure there, rather than the holder withholding one. That seems like the line between a documented design choice and something with a different severity.

Ectsang avatar Sep 01 '26 05:09 Ectsang

@Ectsang You're right, and I'd missed it. Reproduced against the pinned SHA before replying — check_payment_constraints is not purely presence-driven, and the agent_recurrence block is exactly the pattern this issue is asking for.

Where that assertion stops is the more interesting part.

It is triggered by AgentRecurrence, which lives in the same constraints array as the Budget it protects — and is therefore just as selectively disclosable. Calling check_payment_constraints with the constraint sets a verifier is left holding after redaction, cap ₹5,000 and charge ₹7,500:

budget + recurrence + range   -> BLOCKED   Cumulative spend 750000 exceeds budget limit 500000
budget WITHHELD, recurrence   -> BLOCKED   payment.agent_recurrence requires payment.budget constraint
budget + recurrence WITHHELD  -> ALLOWED   (clean pass)
budget WITHHELD, nothing else -> ALLOWED   (clean pass)

So a holder who withholds the cap gets caught. A holder who withholds the cap and the recurrence marker does not, because there is nothing left to trigger the check. The defence protects the holder who chose to disclose the thing that triggers it — and an adversary is precisely the party who won't.

That reframes the issue better than my original wording did: the problem isn't that AP2 lacks presence assertions, it's that the one it has takes its requirement from the presentation being examined rather than from the verifier's own expectations.

Which is why I think your second point is the actionable fix. Returning the set of constraints actually evaluated alongside the violations resolves the ambiguity in list[str] — empty currently means either "all evaluated and satisfied" or "nothing evaluated", and a verifier can't tell those apart. With the evaluated set returned, a verifier can assert its own expected set without any change to disclosure semantics, and without the requirement being something the presenter can opt out of. That seems strictly better than special-casing more constraint combinations.

On issuer_jwt_hash: I went looking for the downstream-strip case and could not reach it through the public API. present() parses its mandate_token argument with parse_token, which splits on ~ and rejects the empty segment that the ~~ chain separator produces — so it appends a hop to a token, never to a chain, and a third hop can't be constructed:

two-hop chain builds and verifies : 2 payloads
common.parse_token(chain)         : ValueError: Malformed SD-JWT: empty disclosure segment
present(chain, ...)               : ValueError: Malformed SD-JWT: empty disclosure segment

claims_to_disclose hits the same limit on a chain, since it rebuilds the token from split('~', maxsplit=1)[0]. Both fail closed, so neither is a security issue — but it does mean the delegation story currently stops at two hops through the documented API. I did not try hand-assembling hops beneath present() with kb_sd_jwt.create, so I can say it doesn't reproduce this way, not that it's unreachable. Happy to be told I've missed an intended path here too.

Reproductions, if useful: spike_recurrence.py for the table above, spike_three_hop.py for the chain result. Local keys, no network.

One unrelated thing found on the way: an AgentRecurrence mandate can't be issued with selective disclosure at all — Frequency is not JSON-serialisable where the SD-JWT library hashes array-element disclosures, so _create_sd_claims_list raises TypeError: Object of type Frequency is not JSON serializable. Fails closed, so it's robustness rather than security. Happy to file separately if that's more useful.

CODER7657 avatar Sep 01 '26 11:09 CODER7657