Commit 35f71c8
fix(security): harden A2A runtime trust boundaries, scoping, and validation
Security fixes:
- Add authentication to the /invoke endpoint (HMAC trust header gate)
- Add authentication to the A2A proxy catch-all before forwarding
- Require non-empty A2A_RUST_AUTH_SECRET at startup to prevent
predictable trust headers
- Use server-derived owner_email/team_id in agent registration instead
of trusting client-provided values
- Add visibility scoping to the flush_events internal endpoint
- Close visibility bypass on events/replay when task row is absent
- Close visibility bypass on push config get/list when agent_id omitted
- Validate webhook URL through Pydantic schema (SSRF protection) in
internal push config creation endpoint
- Add webhook URL validation via validate_core_url on
A2APushNotificationConfigCreate schema
- Exclude auth_token from A2APushNotificationConfigRead (Field exclude)
- Change _check_agent_access_by_id to fail-closed for deleted agents
- Make encode_auth_context a hard error instead of silent empty fallback
- Sanitize all error responses to external callers — strip internal
backend URLs, Python response bodies, and reqwest error details
- Redact Redis URL credentials in logs
- Use constant-time comparison for session fingerprint validation
- Warn at startup if HTTP listener is non-loopback
Correctness fixes:
- Pass actual JSON-RPC method name through full_authenticate
- Add explicit authz match arms for cancel, delete, create, and stream
- Remove x-forwarded-for from default session fingerprint headers
- Fix cargo fmt conflicts with pragma allowlist comments
- Cap retry backoff at 60 seconds to prevent runaway delays
Error handling improvements:
- Replace expect() in queue worker with graceful error handling for
semaphore closure, panicked JoinSet tasks, and missing results
- Add logger.exception + db.invalidate fallback to all 11 internal
A2A endpoint exception handlers
- Upgrade query param decryption failure log from debug to warning
- Log warning on auth decoding failure during agent update
- Return None from event_store.store_event on serialization failure
- Replace .ok() with logged match on proxy response JSON parsing
- Replace mutex expect("poisoned") with unwrap_or_else recovery
- Upgrade shadow mode payload mismatch log to warning with traceback
- Upgrade Redis cache invalidation failure log to warning
- Bound resolve_inflight DashMap to prevent unbounded memory growth
Comment and code cleanup:
- Fix handle_a2a_proxy doc (does not inject trust headers)
- Fix coalesce_jobs doc (does not match on timeout)
- Fix proxy_task_method doc (also handles cancel, not just reads)
- Clarify trust header as keyed SHA-256, not formal HMAC
- Renumber handle_a2a_invoke steps sequentially (1-2-3-3a-4-5)
- Document _visible_agent_ids admin-bypass divergence
- Remove leftover logger.info debug statements from register_agent
- Remove commented-out dead code from register_agent
- Remove duplicate TOOLS_MANAGE_PLUGINS constant
- Remove constant-comparison test (test_version_endpoint_redis_conditions)
Test coverage:
- Add visibility tests for cancel_task (wrong team, admin, public-only)
- Add deny-path tests for events/replay (inaccessible agent, missing task)
- Add 32 tests for _check_agent_access_by_id, _visible_agent_ids,
get_task, list_tasks, and _check_server_access
- Add tests for auth_secret startup rejection (unit + binary)
- Update integration tests for trust-gated /invoke and authenticated
proxy endpoints
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Jonathan Springer <jps@s390x.com>1 parent 4655195 commit 35f71c8
File tree
33 files changed
+1704
-590
lines changed- mcpgateway
- alembic/versions
- services
- tests/unit/mcpgateway
- services
- tools_rust/a2a_runtime
- benches
- src
- tests
33 files changed
+1704
-590
lines changedLarge diffs are not rendered by default.
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
143 | | - | |
144 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| |||
153 | 159 | | |
154 | 160 | | |
155 | 161 | | |
156 | | - | |
| 162 | + | |
157 | 163 | | |
158 | 164 | | |
159 | 165 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1258 | 1258 | | |
1259 | 1259 | | |
1260 | 1260 | | |
1261 | | - | |
1262 | | - | |
1263 | 1261 | | |
1264 | 1262 | | |
1265 | 1263 | | |
| |||
5066 | 5064 | | |
5067 | 5065 | | |
5068 | 5066 | | |
| 5067 | + | |
5069 | 5068 | | |
5070 | 5069 | | |
5071 | 5070 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8997 | 8997 | | |
8998 | 8998 | | |
8999 | 8999 | | |
| 9000 | + | |
9000 | 9001 | | |
9001 | 9002 | | |
9002 | 9003 | | |
9003 | | - | |
| 9004 | + | |
| 9005 | + | |
| 9006 | + | |
| 9007 | + | |
9004 | 9008 | | |
9005 | 9009 | | |
9006 | 9010 | | |
| |||
9044 | 9048 | | |
9045 | 9049 | | |
9046 | 9050 | | |
| 9051 | + | |
9047 | 9052 | | |
9048 | 9053 | | |
9049 | 9054 | | |
9050 | | - | |
| 9055 | + | |
| 9056 | + | |
| 9057 | + | |
| 9058 | + | |
9051 | 9059 | | |
9052 | 9060 | | |
9053 | 9061 | | |
| |||
9080 | 9088 | | |
9081 | 9089 | | |
9082 | 9090 | | |
| 9091 | + | |
9083 | 9092 | | |
9084 | 9093 | | |
9085 | 9094 | | |
9086 | | - | |
| 9095 | + | |
| 9096 | + | |
| 9097 | + | |
| 9098 | + | |
9087 | 9099 | | |
9088 | 9100 | | |
9089 | 9101 | | |
| |||
9116 | 9128 | | |
9117 | 9129 | | |
9118 | 9130 | | |
| 9131 | + | |
9119 | 9132 | | |
9120 | 9133 | | |
9121 | 9134 | | |
9122 | | - | |
| 9135 | + | |
| 9136 | + | |
| 9137 | + | |
| 9138 | + | |
9123 | 9139 | | |
9124 | 9140 | | |
9125 | 9141 | | |
| |||
9152 | 9168 | | |
9153 | 9169 | | |
9154 | 9170 | | |
| 9171 | + | |
9155 | 9172 | | |
9156 | 9173 | | |
9157 | 9174 | | |
9158 | | - | |
| 9175 | + | |
| 9176 | + | |
| 9177 | + | |
| 9178 | + | |
9159 | 9179 | | |
9160 | 9180 | | |
9161 | 9181 | | |
| |||
9174 | 9194 | | |
9175 | 9195 | | |
9176 | 9196 | | |
| 9197 | + | |
9177 | 9198 | | |
| 9199 | + | |
9178 | 9200 | | |
9179 | 9201 | | |
| 9202 | + | |
| 9203 | + | |
| 9204 | + | |
| 9205 | + | |
| 9206 | + | |
9180 | 9207 | | |
9181 | 9208 | | |
9182 | 9209 | | |
9183 | 9210 | | |
9184 | | - | |
| 9211 | + | |
9185 | 9212 | | |
9186 | 9213 | | |
| 9214 | + | |
9187 | 9215 | | |
9188 | 9216 | | |
9189 | 9217 | | |
9190 | | - | |
| 9218 | + | |
| 9219 | + | |
| 9220 | + | |
| 9221 | + | |
9191 | 9222 | | |
9192 | 9223 | | |
9193 | 9224 | | |
| |||
9213 | 9244 | | |
9214 | 9245 | | |
9215 | 9246 | | |
9216 | | - | |
9217 | | - | |
9218 | 9247 | | |
9219 | 9248 | | |
9220 | 9249 | | |
| 9250 | + | |
| 9251 | + | |
9221 | 9252 | | |
9222 | 9253 | | |
| 9254 | + | |
9223 | 9255 | | |
9224 | 9256 | | |
9225 | 9257 | | |
9226 | | - | |
| 9258 | + | |
| 9259 | + | |
| 9260 | + | |
| 9261 | + | |
9227 | 9262 | | |
9228 | 9263 | | |
9229 | 9264 | | |
| |||
9247 | 9282 | | |
9248 | 9283 | | |
9249 | 9284 | | |
9250 | | - | |
9251 | | - | |
9252 | 9285 | | |
9253 | | - | |
| 9286 | + | |
| 9287 | + | |
| 9288 | + | |
9254 | 9289 | | |
| 9290 | + | |
9255 | 9291 | | |
9256 | 9292 | | |
9257 | 9293 | | |
9258 | | - | |
| 9294 | + | |
| 9295 | + | |
| 9296 | + | |
| 9297 | + | |
9259 | 9298 | | |
9260 | 9299 | | |
9261 | 9300 | | |
| |||
9289 | 9328 | | |
9290 | 9329 | | |
9291 | 9330 | | |
| 9331 | + | |
9292 | 9332 | | |
9293 | 9333 | | |
9294 | 9334 | | |
9295 | | - | |
| 9335 | + | |
| 9336 | + | |
| 9337 | + | |
| 9338 | + | |
9296 | 9339 | | |
9297 | 9340 | | |
9298 | 9341 | | |
| |||
9313 | 9356 | | |
9314 | 9357 | | |
9315 | 9358 | | |
| 9359 | + | |
9316 | 9360 | | |
9317 | 9361 | | |
| 9362 | + | |
9318 | 9363 | | |
| 9364 | + | |
| 9365 | + | |
| 9366 | + | |
| 9367 | + | |
| 9368 | + | |
| 9369 | + | |
| 9370 | + | |
| 9371 | + | |
| 9372 | + | |
| 9373 | + | |
9319 | 9374 | | |
9320 | 9375 | | |
9321 | 9376 | | |
| 9377 | + | |
9322 | 9378 | | |
9323 | 9379 | | |
9324 | 9380 | | |
9325 | | - | |
| 9381 | + | |
| 9382 | + | |
| 9383 | + | |
| 9384 | + | |
9326 | 9385 | | |
9327 | 9386 | | |
9328 | 9387 | | |
| |||
9351 | 9410 | | |
9352 | 9411 | | |
9353 | 9412 | | |
9354 | | - | |
| 9413 | + | |
| 9414 | + | |
| 9415 | + | |
9355 | 9416 | | |
9356 | 9417 | | |
9357 | 9418 | | |
9358 | 9419 | | |
| 9420 | + | |
9359 | 9421 | | |
9360 | 9422 | | |
9361 | 9423 | | |
9362 | | - | |
| 9424 | + | |
| 9425 | + | |
| 9426 | + | |
| 9427 | + | |
9363 | 9428 | | |
9364 | 9429 | | |
9365 | 9430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5575 | 5575 | | |
5576 | 5576 | | |
5577 | 5577 | | |
| 5578 | + | |
| 5579 | + | |
| 5580 | + | |
| 5581 | + | |
| 5582 | + | |
| 5583 | + | |
5578 | 5584 | | |
5579 | 5585 | | |
5580 | 5586 | | |
| |||
5585 | 5591 | | |
5586 | 5592 | | |
5587 | 5593 | | |
5588 | | - | |
| 5594 | + | |
5589 | 5595 | | |
5590 | 5596 | | |
5591 | 5597 | | |
| |||
5595 | 5601 | | |
5596 | 5602 | | |
5597 | 5603 | | |
| 5604 | + | |
5598 | 5605 | | |
5599 | 5606 | | |
5600 | 5607 | | |
| |||
5608 | 5615 | | |
5609 | 5616 | | |
5610 | 5617 | | |
| 5618 | + | |
5611 | 5619 | | |
5612 | 5620 | | |
5613 | 5621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | | - | |
| 396 | + | |
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
313 | 314 | | |
314 | 315 | | |
315 | 316 | | |
316 | | - | |
317 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
318 | 322 | | |
319 | 323 | | |
320 | 324 | | |
| |||
323 | 327 | | |
324 | 328 | | |
325 | 329 | | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
330 | 339 | | |
331 | 340 | | |
0 commit comments