Skip to content

x402 Payload now returns the root delegator, instead of the leaf delegator#251

Open
jeffsmale90 wants to merge 2 commits into
mainfrom
fix/x402-delegator
Open

x402 Payload now returns the root delegator, instead of the leaf delegator#251
jeffsmale90 wants to merge 2 commits into
mainfrom
fix/x402-delegator

Conversation

@jeffsmale90
Copy link
Copy Markdown
Collaborator

@jeffsmale90 jeffsmale90 commented May 27, 2026

📝 Description

The x402DelegationProvider was incorrectly returning the leaf delegator, instead of the root delegator.

This PR fixes that.

🔄 What Changed?

List the specific changes made:

🚀 Why?

Explain the motivation behind these changes:

🧪 How to Test?

Describe how to test these changes:

  • Manual testing steps:
  • Automated tests added/updated
  • All existing tests pass

⚠️ Breaking Changes

List any breaking changes:

  • No breaking changes
  • Breaking changes (describe below):

📋 Checklist

Check off completed items:

  • Code follows the project's coding standards
  • Self-review completed
  • Documentation updated (if needed)
  • Tests added/updated
  • Changelog updated (if needed)
  • All CI checks pass

🔗 Related Issues

Link to related issues:
Closes #
Related to #

📚 Additional Notes

Any additional information, concerns, or context:


Note

Medium Risk
Changes the semantics of the experimental x402 delegator field (breaking for callers) and adds a hard error when no parent delegation chain exists to derive a root delegator.

Overview
Fixes the experimental x402 delegation provider so payment payloads identify the root delegator in the parent permission chain, not the newly signed leaf delegation’s delegator.

resolveDelegationCreationContext now derives rootDelegator from the last entry in decoded parentPermissionContext delegations and fails with Root delegator not found when that chain is empty. createx402DelegationProvider returns that address in the payload’s delegator field. Tests and the changelog entry for createx402DelegationProvider are updated accordingly.

Breaking for integrators: any consumer that assumed delegator was the leaf signer must switch to the root account; flows without a valid parent permission context will now error at resolution time.

Reviewed by Cursor Bugbot for commit a823df6. Bugbot is set up for automated code reviews on this repo. Configure here.

@jeffsmale90 jeffsmale90 requested a review from a team as a code owner May 27, 2026 07:27
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 37e110f. Configure here.


if (!rootDelegator) {
throw new Error('Root delegator not found');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function always throws when optional parentPermissionContext is absent

High Severity

When parentPermissionContext is not provided (it's optional in x402DelegationProviderConfig), existingDelegations is set to []. Then existingDelegations[existingDelegations.length - 1] evaluates to existingDelegations[-1] which is undefined, causing the rootDelegator check to unconditionally throw 'Root delegator not found'. This makes the else branch at line 546–553 unreachable dead code and effectively makes parentPermissionContext required at runtime despite being typed as optional.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 37e110f. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant