fix(egress): scan response + websocket DLP against the resolved per-flow config #401
Reference in New Issue
Block a user
Delete Branch "fix/websocket-response-dlp-multitenant"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
In the consolidated (multi-tenant) gateway, the egress addon's static
self.configis empty — each request's real policy is resolved per-request from the orchestrator's/resolve. Butresponse()andwebsocket_message()still matched routes against that emptyself.config, so inbound prompt-injection DLP and WebSocket credential/injection DLP silently skipped every scan (fail-open) whenever the gateway ran multi-tenant.request()was already correct (it resolves per-flow); the two later hooks were not.Closes finding #2 of the audit in #400 — and, as noted there, fixes the same root cause on the response path too, not only WebSocket.
Fix
Resolve the per-flow
(config, slug, env)once inrequest(), stash it onflow.metadata, and haveresponse()/websocket_message()read it back — falling back to the static single-tenant values for a flow that never passed throughrequest(). Reusing the request's single/resolveavoids a round-trip per response and per WebSocket frame, and re-resolving later would be unreliable anyway (the identity token is stripped from the request duringrequest()).Backend-agnostic
The gateway image and this addon are shared by the Firecracker, macOS, and docker consolidated backends, so this one change fixes all of them; no backend-specific code is touched.
Tests
TestMultiTenantInboundDlp: drivesrequest()(resolves + stashes), then exercisesresponse()andwebsocket_message()for a multi-tenant bottle — verified these fail against the old fall-open behaviour and pass with the fix.pyright: 0 errors.pylint: 9.72/10. Full egress suites (199 tests) green. (The 13test_gateway_initfailures on the dev host are a pre-existing/bin/sleeppath issue on NixOS, unrelated.)🤖 Generated with Claude Code
https://claude.ai/code/session_01UoEZHDjv84ChoZbozQERhJ
1afb78094btofd86e7fa99