fix(19.7): RA-WR-02 stop a shared stateless server flapping its tool set
The identity fingerprint no longer includes token ids: guards decide on scopes, subjects and the ceiling, and an OAuth access token's id changes on every refresh, so a rotation alone no longer re-filters a cached server. The stateless path's refresh only adds tools and prompts for a fingerprint new to the entry (remembered until a fan-out recompute) and never removes: one server serves every live token of a binding, and removing on each alternation between a wider and a narrower token pulled a tool from under the wider token's call. The receiving middleware still filters every list and call per request; fan-out recomputes still narrow. The stateful path keeps its exact widen, a session serves one client. TestFingerprintIgnoresTokenID pins the fingerprint; TestStatelessSharedBinding blocks the wide token's call after its server was chosen, sends a request of the narrow token and asserts the call still succeeds (it failed with "unknown tool" before).
This commit is contained in:
@@ -29,13 +29,16 @@ type statelessEntry struct {
|
||||
server *mcp.Server
|
||||
elem *list.Element
|
||||
|
||||
// mu serializes re-filtering and guards fingerprint, tools and prompts
|
||||
// (see localSession); identity has its own box.
|
||||
// mu serializes re-filtering and guards fingerprint, widened, tools and
|
||||
// prompts (see localSession); identity has its own box.
|
||||
mu sync.Mutex
|
||||
identity identityBox
|
||||
fingerprint string // of the identity the tool set was last filtered for
|
||||
tools map[string]bool
|
||||
prompts map[string]bool
|
||||
// widened lists the other fingerprints whose tools and prompts were
|
||||
// added since (RA-WR-02); a recompute clears it.
|
||||
widened map[string]bool
|
||||
tools map[string]bool
|
||||
prompts map[string]bool
|
||||
}
|
||||
|
||||
// statelessPath serves clients of protocol 2026-07-28 and later (D-32,
|
||||
@@ -182,13 +185,30 @@ func (sp *statelessPath) hit(binding string) *statelessEntry {
|
||||
return e
|
||||
}
|
||||
|
||||
// refresh stores the request's identity on an entry and re-filters its
|
||||
// server when the identity's fingerprint changed (A-WR-04).
|
||||
// refresh stores the request's identity on an entry and, when the
|
||||
// identity's fingerprint is new to the entry, adds the tools and prompts
|
||||
// it allows (A-WR-04). It never removes any (RA-WR-02): one server serves
|
||||
// every live token of the binding, and two of them may differ in reach (two
|
||||
// devices, an older narrower token next to a re-consented one), so removing
|
||||
// on every alternation would pull a tool from under another token's call in
|
||||
// flight. The receiving middleware hides, per request, whatever the
|
||||
// request's identity may not use; a fan-out recompute still narrows.
|
||||
func (sp *statelessPath) refresh(ctx context.Context, e *statelessEntry, id Identity) {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
e.identity.set(id)
|
||||
sp.p.widen(ctx, e.server, id, &e.fingerprint, e.tools, e.prompts)
|
||||
e.mu.Unlock()
|
||||
fp := id.fingerprint()
|
||||
if fp == e.fingerprint || e.widened[fp] {
|
||||
return
|
||||
}
|
||||
ctx, cancel := sp.p.guardContext(ctx)
|
||||
defer cancel()
|
||||
tools, prompts := sp.p.catalog.allowed(ctx, id)
|
||||
addMissing(e.server, sp.p, id, tools, prompts, e.tools, e.prompts)
|
||||
if e.widened == nil {
|
||||
e.widened = map[string]bool{}
|
||||
}
|
||||
e.widened[fp] = true
|
||||
}
|
||||
|
||||
// closeSessions closes every session of a server.
|
||||
|
||||
Reference in New Issue
Block a user