Skip to content

refactor(permission-controller): decouple permission middleware via messenger actions#8532

Draft
rekmarks wants to merge 6 commits intofb/create-method-middlewarefrom
rekm/permission-methodmiddleware
Draft

refactor(permission-controller): decouple permission middleware via messenger actions#8532
rekmarks wants to merge 6 commits intofb/create-method-middlewarefrom
rekm/permission-methodmiddleware

Conversation

@rekmarks
Copy link
Copy Markdown
Member

@rekmarks rekmarks commented Apr 20, 2026

Advances #4238
Reverts #8502

  • Rewrites permission-middleware.ts as a standalone createPermissionMiddleware({ messenger, subject }) factory that dispatches through the PermissionController:executeRestrictedMethod and PermissionController:hasUnrestrictedMethod messenger actions instead of bound controller hooks. Removes the createPermissionMiddleware property from PermissionController.
  • Exposes hasUnrestrictedMethod as a public method / messenger action, and makes getRestrictedMethod #-private (it has no remaining external consumers now that the middleware goes through the messenger).
  • When a restricted method returns undefined, the middleware now propagates the plain Error thrown by executeRestrictedMethod; the JSON-RPC engine serializes it as a standard internal error response instead of a custom internalError with a request data payload.

Note

Medium Risk
Breaking API change to how JSON-RPC permission enforcement middleware is created and wired, which can impact authorization behavior and downstream integrations. Adds a new JsonRpcEngineV2 middleware path and changes error propagation, so regressions would surface at runtime if consumers misconfigure messengers or rely on prior error shapes.

Overview
Permission middleware creation is now standalone and messenger-driven. PermissionController.createPermissionMiddleware is removed (breaking) and replaced by exported createPermissionMiddleware (legacy JsonRpcEngine, deprecated) and new createPermissionMiddlewareV2 for JsonRpcEngineV2, both calling PermissionController:hasUnrestrictedMethod and PermissionController:executeRestrictedMethod via a provided messenger.

Controller surface and tests/docs updated to match. hasUnrestrictedMethod is added/exposed as a public method + messenger action, restricted-method lookup is made private, docs/examples and unit tests are rewired to delegate the required actions to a scoped middleware messenger, and the undefined-result case now propagates the plain executeRestrictedMethod error (wrapped by the engine as -32603) rather than returning a custom internalError payload.

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

rekmarks and others added 3 commits April 20, 2026 15:43
…essenger actions

Replace the hook-based permission middleware factory with a standalone
`createPermissionMiddleware` export that dispatches through messenger
actions (`PermissionController:executeRestrictedMethod` and
`PermissionController:hasUnrestrictedMethod`). Removes the
`createPermissionMiddleware` property from `PermissionController`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Now that the permission middleware invokes restricted methods through
the messenger, `getRestrictedMethod` has no remaining external consumers
and is made `#`-private. Its caller signature is tightened so
`requestingOrigin` is required, eliminating a dead optional-origin
branch in `#getTypedPermissionSpecification`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@rekmarks rekmarks requested review from a team as code owners April 20, 2026 23:43
rekmarks and others added 2 commits April 20, 2026 16:50
Add a `JsonRpcEngineV2` variant of the standalone permission middleware
factory that uses the same messenger actions as the v1 factory. The
existing `createPermissionMiddleware` is marked `@deprecated` in favor
of the v2 variant.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@rekmarks rekmarks marked this pull request as draft April 20, 2026 23:54
@rekmarks
Copy link
Copy Markdown
Member Author

@cursor review

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 706f8dc. 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