fix: resources vanish from server pages when stored x402 response is invalid#775
Open
clawdbot-glitch003 wants to merge 1 commit into
Open
Conversation
…led parse
Two bugs caused resources to disappear from server pages:
1. `registerResource()` stored `advisory.paymentRequiredBody` without validation,
casting it directly as `ParsedX402Response`. When the body was undefined or
malformed, `{}` was stored in the database. The ping route already validates
with `parseX402Response()` before storing — this aligns the registration path
with that pattern.
2. `listOriginsWithResources()` re-validated stored responses at render time via
`parseX402Response()`, then spread the result (including `{ success: false }`)
onto each resource. The UI filters out resources where `success !== true`,
so any resource with a bad stored response became invisible — even though its
accepts data was correctly stored in the database.
The fix:
- Validate `advisory.paymentRequiredBody` before storing; skip storage if invalid
- When stored response fails to parse at render time, fall back to
`{ success: true, data: null }` so the resource remains visible using its
DB-level accepts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
@glitch003 is attempting to deploy a commit to the Merit Systems Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Report
Resources registered via the
public.resources.registertRPC mutation can become invisible on server overview pages, even though they are correctly stored in the database with valid accepts data.Reproduction
registermutation (e.g. from an automated publish pipeline)Root Cause
Two issues combine to cause this:
1.
registerResource()stores response without validation (apps/scan/src/lib/resources.ts:140-143)When
advisory.paymentRequiredBodyis undefined or doesn't pass the Zod schema,{}gets stored in theResourceResponse.responseJson column. The ping route (app/api/resources/ping/route.ts:71-73) already validates before storing — this path skips that validation.2.
listOriginsWithResources()re-validates at render time and hides failures (apps/scan/src/services/db/resources/origin.ts:171-182)The spread overwrites the resource with
{ success: false }. The UI component (origin-resources.tsx:39-41) filters to only show resources whereresource.success === true && resource.accepts.length > 0, so any resource with a bad stored response disappears — even though its accepts data is correctly stored.Fix
Validate before storing:
registerResource()now callsparseX402Response()beforeupsertResourceResponse(), matching the ping route pattern. Invalid responses are logged and skipped.Graceful render fallback:
listOriginsWithResources()now falls back to{ success: true, data: null }when the stored response fails to parse, so resources remain visible using their DB-level accepts data.Impact
This affects any x402 resource registered via the
registermutation where the stored response body doesn't pass strict Zod validation. The resource, its accepts, and its origin are all correctly stored — only the response rendering path is broken.Test Plan
registermutation