Skip to content

Commit 8c7ac96

Browse files
switch to header only
1 parent 165b751 commit 8c7ac96

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

src/agentex/lib/sdk/fastacp/base/base_acp_server.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,14 @@ async def _handle_jsonrpc(self, request: Request):
152152
),
153153
)
154154

155-
# Extract application headers, excluding sensitive/transport headers per FASTACP_* rules
155+
# Extract application headers using allowlist approach (only x-* headers)
156+
# Matches gateway's security filtering rules
156157
# Forward filtered headers via params.request.headers to agent handlers
157158
custom_headers = {
158159
key: value
159160
for key, value in request.headers.items()
160-
if key.lower() not in FASTACP_HEADER_SKIP_EXACT
161+
if key.lower().startswith("x-")
162+
and key.lower() not in FASTACP_HEADER_SKIP_EXACT
161163
and not any(key.lower().startswith(p) for p in FASTACP_HEADER_SKIP_PREFIXES)
162164
}
163165

@@ -166,6 +168,7 @@ async def _handle_jsonrpc(self, request: Request):
166168
params_data = dict(rpc_request.params) if rpc_request.params else {}
167169

168170
# Add custom headers to the request structure if any headers were provided
171+
# Gateway sends filtered headers via HTTP, SDK extracts and populates params.request
169172
if custom_headers:
170173
params_data["request"] = {"headers": custom_headers}
171174
params = params_model.model_validate(params_data)
Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
from __future__ import annotations
22

33
# Header filtering rules for FastACP server
4+
# These rules match the gateway's security filtering
45

5-
# Prefixes to skip (case-insensitive beginswith checks)
6-
FASTACP_HEADER_SKIP_PREFIXES: tuple[str, ...] = (
7-
"content-",
6+
# Hop-by-hop headers that should not be forwarded
7+
HOP_BY_HOP_HEADERS: set[str] = {
8+
"connection",
9+
"keep-alive",
10+
"proxy-authenticate",
11+
"proxy-authorization",
12+
"te",
13+
"trailer",
14+
"transfer-encoding",
15+
"upgrade",
16+
"content-length",
17+
"content-encoding",
818
"host",
9-
"user-agent",
10-
"x-forwarded-",
11-
"sec-",
12-
)
19+
}
1320

14-
# Exact header names to skip (case-insensitive matching done by lowercasing keys)
15-
FASTACP_HEADER_SKIP_EXACT: set[str] = {
16-
"x-agent-api-key",
17-
"connection",
18-
"accept-encoding",
21+
# Sensitive headers that should never be forwarded
22+
BLOCKED_HEADERS: set[str] = {
23+
"authorization",
1924
"cookie",
20-
"content-length",
21-
"transfer-encoding",
25+
"x-agent-api-key",
26+
"x-request-id",
2227
}
2328

29+
# Legacy constants for backward compatibility
30+
FASTACP_HEADER_SKIP_EXACT: set[str] = HOP_BY_HOP_HEADERS | BLOCKED_HEADERS
31+
32+
FASTACP_HEADER_SKIP_PREFIXES: tuple[str, ...] = (
33+
"x-forwarded-", # proxy headers
34+
"sec-", # security headers added by browsers
35+
)
36+
2437

0 commit comments

Comments
 (0)