Security: fix plugin auth/access bypasses + fail-open controls#91
Merged
Conversation
Hardens the plugin layer per the security review. All touched plugins build and pass their tests; the SDK and workspace pass the clippy gate. - sdk: add `resolve_client_ip(req, trusted_proxies)` so security middlewares share one trusted-proxy-aware client-IP resolver instead of independently spoofable implementations. - ip-restriction: support IPv6 (std::net::IpAddr) so an IPv6 client is no longer silently allowed past a denylist; honor X-Forwarded-For only behind configured `trusted_proxies`; fail closed on an unparseable IP when restrictions exist. - cors: a literal `*` with credentials no longer allows arbitrary origins (Fetch-spec violation); reflect the validated origin with `Vary: Origin` on responses via request context. - rate-limit / ai-token-limit: fail CLOSED (503) when the host limiter is unavailable by default (`fail_open` to opt out); partition by the trusted-proxy-aware client IP so rotating XFF can't mint fresh buckets; ai-token-limit logs (instead of silently zeroing) an unparseable token count. - ai-prompt-guard: fail CLOSED on an unparseable body or non-array `messages` (`fail_open` to opt out) so the guard can't be bypassed with a malformed body. - dispatchers (kafka, nats, lambda, s3, http-upstream, oauth2-auth, oidc-auth, ws-upstream): clamp the host-returned read length to the buffer before slicing, removing a panic vector. - ai-proxy: schema guidance to use secret references for api_key (keys are not logged anywhere; verified). New config: `trusted_proxies` (ip-restriction, rate-limit, ai-token-limit), `fail_open` (rate-limit, ai-token-limit, ai-prompt-guard).
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.
Hardening of the plugin layer (security review item #7). Secure-by-default: controls that previously failed open now fail closed, with an explicit opt-out. All touched plugins build and pass their tests; the SDK + workspace pass the clippy gate.
Fixes
resolve_client_ip(req, trusted_proxies)— one trusted-proxy-aware client-IP resolver shared by the security middlewares (kills the per-plugin spoofable variants).std::net::IpAddr) so an IPv6 client is no longer silently let past a denylist;X-Forwarded-For/X-Real-IPhonored only behind configuredtrusted_proxies; fail closed on an unparseable client IP when restrictions exist.*withallow_credentialsno longer allows an arbitrary origin (Fetch-spec violation); responses now reflect the validated origin withVary: Origin(carried fromon_requestvia context).fail_open: trueto opt out); partition by the trusted-proxy-aware client IP so rotatingX-Forwarded-Forcan't mint fresh buckets; ai-token-limit logs (instead of silently charging 0) an unparseable token count.messages(fail_open: trueto opt out) so the guard can't be bypassed with a malformed body.env:///file://) forapi_key(keys are not logged anywhere — verified).New config (all backward-compatible, secure defaults)
trusted_proxies[](forwarded headers untrusted)fail_openfalse(fail closed)Behavior changes (secure-by-default)
X-Forwarded-Foris ignored unless the immediate peer is a configured trusted proxy.fail_open: trueto keep the old behavior.Tracked privately as #7. Remaining auth/crypto items (constant-time compare, OIDC alg binding, etc.) are issue #6.