fix(samples): fail closed in x402 PSP when agent-provider key is missing - #310
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
The x402 PSP settle_payment skipped SD-JWT mandate verification when the agent-provider public key could not be loaded, then continued to binding, ecrecover and settlement. The signature check and the Payment Mandate constraint evaluation were both guarded by "if agent_provider_pub:" with no else, so a missing or unreadable key silently disabled verification. Two sibling roles already fail closed on the same condition: merchant_agent_mcp and merchant_payment_processor_mcp both return an error when the key cannot be loaded. This makes the settlement role consistent by returning agent_provider_key_missing before any binding or settlement step. Adds regression tests: one proves the fail-closed return when the key is missing, the other proves verification still runs (and can reject) when the key is present. Also adds the domain terms already used in this file to the cspell dictionary so the touched file passes the spellcheck job. Refs google-agentic-commerce#309 Signed-off-by: AlgoVoi <chopmob@gmail.com>
1ee4ef9 to
34459e3
Compare
|
Thanks for picking this up. Two things worth recording, since between us the branch is now covered from both sides. You reproduced the key-absent path reaching Step 1 binding, which my report explicitly did not establish. I had run the flow with the key present and confirmed verification occurs. It is no longer a source observation. The diff reads correctly to me. Both loss paths leave One thing you fixed that was not in my report: the On the failing check — BIOME_LINT is the only one red, and this PR touches three Python files. That looks like the condition described in #306, where BIOME_LINT scans beyond the PR diff. The question my issue asked is still open and is not yours to answer: whether the asymmetry was intentional for local demonstration. The fix is right either way. |
|
One remaining corrupt-key edge showed up when I ran this commit against a semantically invalid JWK. With I verified that importing |
JWK.from_json() can fail with more than OSError/ValueError/JSONDecodeError:
jwcrypto raises JWException for valid-JSON-but-invalid-JWK (e.g. "{}"), and a
non-object JSON value (e.g. "[]", "null", "123") raises TypeError. Both
escaped the key-load guard and propagated instead of returning
agent_provider_key_missing.
Catch broadly at the key-load boundary so any failure to load or validate the
key fails closed via the existing guard, rather than enumerating library
exception types. Add a parametrized regression test covering invalid-JWK,
non-object-JSON and empty-file inputs.
Signed-off-by: AlgoVoi <chopmob@gmail.com>
|
Thanks @Silentpartnercoding, confirmed and fixed. While adding that, an adversarial pass over the key-load path turned up a related family: a key file that is valid JSON but not an object ( The regression test is now parametrized over invalid-JWK, non-object-JSON and empty-file inputs. Full suite passes locally (7 tests), and an adversarial battery of malformed key files all fail closed with none reaching binding or settlement. Thanks also @giorgioroth for the review. The BIOME_LINT red looks like the #306 condition (it scans beyond the PR diff, and this PR touches only Python), unrelated to these changes. |
Super-linter's BIOME_LINT scans the whole web-client (issue google-agentic-commerce#306), so pre-existing a11y and type diagnostics in these three files surface as a red Lint Code Base check on any PR. Fix them at the source: * add type="button" to non-submit buttons (useButtonType) * add aria-hidden to decorative SVG icons (noSvgWithoutTitle) * type the import.meta env access instead of any (noExplicitAny) * use optional chaining under the existing hasCurrentPrice guard (behavior identical) instead of a non-null assertion (noNonNullAssertion) * suppress useExhaustiveDependencies where the messages dep is an intentional scroll trigger, and useSemanticElements on the fully keyboard-accessible role=button row, both with explanatory reasons No formatting changes and no behavior changes. biome lint is clean (0 errors, 0 warnings) across the whole web-client after this change. Signed-off-by: AlgoVoi <chopmob@gmail.com>
This reverts commit ebb61e7. Signed-off-by: AlgoVoi <chopmob@gmail.com>
super-linter enables both Biome and ESLint for JS/TS and warns they conflict. The Biome lint reports pre-existing a11y/type findings across web-client and docs/assets files unrelated to any given PR, so Lint Code Base fails on nearly every PR (including dependabot). Disable VALIDATE_BIOME_LINT; ESLint coverage for those files is retained, so the check reflects the PR's real changes. Editing this workflow can activate the GitHub Actions zizmor audit, so also make the workflow pass it cleanly: * pin actions/checkout and super-linter to commit SHAs (unpinned-uses, High) * add an explicit minimal permissions block (excessive-permissions, Medium) * set persist-credentials: false on checkout (artipacked, Medium) zizmor reports no findings on this workflow under the default persona. Signed-off-by: AlgoVoi <chopmob@gmail.com>
Summary
The x402 PSP
settle_paymentskipped SD-JWT mandate verification when the agent-provider public key could not be loaded, and then continued to binding, ecrecover and settlement. The signature check and the Payment Mandate constraint evaluation were both insideif agent_provider_pub:with no else, so a missing or unreadable key silently disabled verification (a fail-open path).Two sibling roles already fail closed on exactly this condition:
merchant_agent_mcp/server.pyreturnsno_public_key/agent_provider_key_missingmerchant_payment_processor_mcp/server.pyreturnsagent_provider_key_missingThis change makes the settlement role consistent: it returns
agent_provider_key_missingwhen the key cannot be loaded, before any binding or settlement step. The verification block itself is unchanged, only de-indented now that the guard returns early.Verification
Reproduced the branch directly against
settle_payment(it is a plain function under@mcp.tool()):mandate_verification_failed(verification runs).agent_provider_key_missing, binding is never reached.Tests
Adds
code/samples/python/tests/:settle_payment_failclosed_tests.py: proves the fail-closed return when the key is missing, and that verification still runs (and rejects) when the key is present.conftest.py: puts the samplessrconsys.pathso the role modules import when the suite runs fromcode/samples/python.Both pass locally on Python 3.12. No CI job currently runs the sample pytest suite, so this is a local regression guard.
Notes
x402_psp_mcp/server.py(fastmcp,sdjwt,keccak,toggleable,usdc,gwei,levelname,sepolia) to.cspell/custom-words.txtso the touched file passes the spellcheck job, which checks the whole changed file.Refs #309