fix(security): gate deregister() with the same plugin opt-in policy as register() - #56261
Merged
kshitijk4poor merged 1 commit intoJul 1, 2026
Conversation
…ookup
_plugin_override_policy is keyed by the plugin package root
(e.g. hermes_plugins.allowed), but the lookup used caller_mod
(the exact leaf module string). A call from hermes_plugins.allowed.cleanup
would evaluate _plugin_override_policy.get("hermes_plugins.allowed.cleanup")
→ False and raise PermissionError even when the plugin registered opt-in
under its package root.
Switch the policy lookup to caller_root (.join of the first two segments)
so submodule callers inherit the package-level allow_tool_override grant.
Adds a focused regression test for the opted-in submodule case.
kshitijk4poor
enabled auto-merge (rebase)
July 1, 2026 10:04
Collaborator
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.
Summary
Closes a symmetric authorization hole:
ToolRegistry.deregister()was ungated, letting a plugin bypass the mergedregister(override=True)opt-in gate (#55599) entirely — deregister a built-in it doesn't own, then plain-register()a malicious handler over the now-empty slot (the override check only fires when anexistingentry is present, so clearing it first skips the check).Salvaged from #55840 by @srojk34 onto current
main(253 commits behind); authorship preserved. The trivialpop→get/delconflict and a dropped_caller_module/import syshunk were resolved so the salvaged files are byte-identical to the contributor's intended change.Changes
tools/registry.py:deregister()now inspects the calling module (_caller_module(), frame-based, mirroring_plugin_owner_of's bind-to-definition philosophy). Ahermes_plugins.*caller that does not own the entry's handler and lacks operator opt-in (plugins.entries.<id>.allow_tool_override) gets aPermissionErrorand the entry is left intact. Ownership binds to the plugin package root (hermes_plugins.<slug>) so root-module cleanup code can remove tools registered by a submodule of the same plugin.mcp-*toolsets are exempt (dynamic tool refresh legitimately nuke-and-repaves its own tools). Core (non-plugin) callers are never gated.tests/tools/test_registry.py:TestDeregisterAuthorization— blocked-without-opt-in, allowed-with-opt-in, self-cleanup, package-root submodule ownership, opted-in submodule caller, MCP exemption, core-caller-always-allowed, and the full deregister→register bypass rejected end-to-end.Validation
PermissionError, entry intactallow_tool_overridederegisterspytest tests/tools/test_registry.py→ 41 passed.pytest tests/tools/test_mcp_tool.py→ 202 passed (dynamic refresh unaffected). E2E against a realToolRegistrywith a realhermes_plugins.*caller frame confirmed the bypass is closed for naive/accidental plugin code.Scope note
This gate — like the existing
register(override=True)gate it mirrors — is an operator-consent + auditability guard against a plugin silently shadowing a built-in, at the project's established plugin-trust level. It is not a sandbox against actively-hostile plugin code (frame__globals__can be forged; the same is true of the mergedregister()gate). Upgrading both gates from frame inspection to a capability-token / entry-stored-owner model is tracked as a follow-up.Closes #55840.