fix(gateway): re-check allowedSessionKeyPrefixes after /hooks agent-rebind (#2723)#2730
Merged
Merged
Conversation
…ebind (#2723) The /hooks/agent and /hooks/<mapping> paths validated the requested session key against hooks.allowedSessionKeyPrefixes, then rebound it to the target agent (agent:main:* -> agent:hooks:*) and dispatched without re-checking — an authenticated hook caller could rebind a turn into a session namespace it was never authorized for (an authz-confinement gap). Add resolveHookDispatchSessionKey, which rebinds then re-validates the dispatch key against the allowlist, and gate both ingress paths on it (reject 400 on violation). Restore the two covering integration tests (agent + mapping path) removed during the CI-green test-remediation pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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
Fixes #2723 — a gateway authz-confinement gap. The
/hooks/agentand/hooks/<mapping>paths validated the requested session key againsthooks.allowedSessionKeyPrefixes, then rebound it to the target agent(
agent:main:*→agent:hooks:*) vianormalizeHookDispatchSessionKeyanddispatched without re-checking the rebound key. An authenticated hook caller
could therefore rebind a turn into a session namespace it was never authorized
for: e.g. with allowlist
["hook:", "agent:main:"], a request forsessionKey: "agent:main:..."+agentId: hookspassed the pre-rebind check,then rebound to
agent:hooks:...(which matches neither prefix) and dispatched.Fix
resolveHookDispatchSessionKey(src/gateway/hooks.ts): rebinds thesession key to the target agent, then re-validates the rebound key against
allowedSessionKeyPrefixes. Returns the existing{ok,value}|{ok,error}result shape used by
resolveHookSessionKey.createHooksRequestHandler(
src/gateway/server-http.ts) on it — reject400with the existinggetHookSessionKeyPrefixErrormessage when the rebound key violates theallowlist. Single security chokepoint;
dispatchAgentHookhas no otherproduction invoker.
Behavior change
This tightens behavior: post-rebind requests whose rebound key violates the
prefix allowlist now return
400instead of being accepted. Requests areunaffected when no allowlist is configured, or when the rebound key still
matches an allowed prefix.
Tests
CI-green test-remediation pass (the documented deferral lived in
src/gateway/server.hooks.test.ts, nothooks.test.tsas the issue textstates): agent-path + mapping-path "rejects rebinding into a disallowed
namespace" — both assert
400+"sessionKey must start with one of"+cronIsolatedRunnot called. Confirmed RED before the fix, GREEN after.resolveHookDispatchSessionKeyinhooks.test.ts(blocked + allowed cases).
out of scope (net-new feature, separate BACKLOG item) and left unrestored;
the BACKLOG comment documenting them is preserved.
Verification
pnpm test:gateway— 1557 pass / 9 skip / 0 fail (full gateway suite, no regressions)pnpm check— format + typecheck + lint + css-drift all cleanAcceptance criteria
server.hooks.test.tscases are restored and pass.🤖 Generated with Claude Code