Commit 2cb5103
authored
Gateway: enforce allowed-tools filtering server-side on tools/list and tools/call (#3334)
Agents with raw HTTP access to the gateway could bypass client-side
`--allowed-tools` filters by directly sending `tools/call` JSON-RPC
requests for tools they shouldn't be able to call. The existing `tools`
field in `StdinServerConfig`/`ServerConfig` was parsed but never
enforced at runtime.
## Changes
### Pre-computed allowed-tools sets (`unified.go`)
- Added `allowedToolSets map[string]map[string]bool` to `UnifiedServer`,
built once at init via `buildAllowedToolSets(cfg)` for O(1) per-call
lookup
- Added `isToolAllowed(serverID, toolName)` — returns `true` when no
list is configured (unrestricted)
### Enforcement in `callBackendTool` (`unified.go`)
Before any DIFC/guard work, rejects calls for tools not in the allowed
set:
- Returns `IsError: true` `CallToolResult` with a descriptive message
- Sets OTEL span HTTP status to 403
- Logs at WARN with `logger.LogWarn("client", ...)` including the server
ID
### tools/list defense-in-depth (`tool_registry.go`)
During backend tool registration, non-allowed tools are filtered out —
they never appear in `tools/list` responses and are never registered
with the SDK server.
### Lint fix
- Removed unused `sendUnifiedMCPRequest` and `parseSSEBody` helper
functions from `allowed_tools_integration_test.go` (golangci-lint
`unused` violations)1 file changed
+0
-49
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
17 | 15 | | |
18 | 16 | | |
19 | | - | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
| |||
80 | 77 | | |
81 | 78 | | |
82 | 79 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | 80 | | |
130 | 81 | | |
131 | 82 | | |
| |||
0 commit comments