fix(security): bound fan-out and method surface and scrub relayed text

- Add a process-wide gate on MCP tools/list backend connections. The
  per-request limit alone let N callers open N times as many.
- Reject CONNECT and TRACE on native passthrough and on MCP and A2A
  targets with 405.
- Scrub URL query strings and the target URL from a backend JSON-RPC
  error message before it reaches the caller.
- Replace the value of redis.address in GET /admin/api/config. The
  users file path stays visible by design.
- Escape line breaks in every log line so an upstream string cannot
  forge log entries.
- Add stripClientAnthropicBeta. When true, POST /v1/messages does not
  forward the client anthropic-beta header. The default stays false.
This commit is contained in:
2026-10-15 22:20:07 +01:00
parent 8c4bd16a22
commit d0d29b8c52
10 changed files with 272 additions and 6 deletions
+7
View File
@@ -172,6 +172,11 @@ type Config struct {
// callers that set one — and nothing for a model that has a price.
// Prefer adding the missing "pricing" entry over setting this.
AllowUnpricedWithCostBudget bool `json:"allowUnpricedWithCostBudget,omitempty"`
// StripClientAnthropicBeta stops POST /v1/messages from forwarding the
// client's anthropic-beta header to the provider, as native passthrough
// already does. Without it a tenant can enable beta features on the
// operator's own Anthropic account. Defaults to false.
StripClientAnthropicBeta bool `json:"stripClientAnthropicBeta,omitempty"`
}
// ProviderConfig describes one upstream LLM provider.
@@ -767,6 +772,7 @@ type Gateway struct {
events *eventLog
bodyAdmission chan struct{}
teeBudget *teeBudget
fanoutGate chan struct{}
failoverHealth *requestHealthTracker
targetHealth *targetHealthTracker
limiter *limiter
@@ -1056,6 +1062,7 @@ func newGateway(ctx context.Context, next http.Handler, config *Config, name str
}
g.bodyAdmission = make(chan struct{}, bodyAdmissionCap)
g.teeBudget = newTeeBudget(maxAccountingTeeTotalBytes)
g.fanoutGate = make(chan struct{}, mcpFederatedFanoutGlobalConcurrency)
if config.Users != nil && config.Users.File != "" {
if err = attachUsersFile(auth, config.Users.File, g); err != nil {