Spaces:
Running
Running
Transformer Claude Opus 4.6 (1M context) commited on
Commit ·
94e4a6a
1
Parent(s): 817572f
fix: 过滤泄露客户端真实 IP 的请求头
Browse files转发时移除 X-Forwarded-For、X-Real-IP 等头,防止目标服务器看到客户端真实 IP。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -106,10 +106,16 @@ async def proxy(target_url: str, request: Request, _: None = Depends(verify_auth
|
|
| 106 |
proxy_header = request.headers.get("proxy")
|
| 107 |
proxy_url = parse_proxy_header(proxy_header)
|
| 108 |
|
| 109 |
-
# 过滤 host 和 proxy 头
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
forward_headers = [
|
| 111 |
(k, v) for k, v in request.headers.raw
|
| 112 |
-
if k.lower() not in
|
| 113 |
]
|
| 114 |
|
| 115 |
client = httpx.AsyncClient(
|
|
|
|
| 106 |
proxy_header = request.headers.get("proxy")
|
| 107 |
proxy_url = parse_proxy_header(proxy_header)
|
| 108 |
|
| 109 |
+
# 过滤会泄露客户端真实 IP 的头,以及 host 和 proxy 头
|
| 110 |
+
STRIP_HEADERS = {
|
| 111 |
+
b"host", b"proxy",
|
| 112 |
+
b"x-forwarded-for", b"x-forwarded-host", b"x-forwarded-proto",
|
| 113 |
+
b"x-real-ip", b"forwarded", b"via",
|
| 114 |
+
b"cf-connecting-ip", b"true-client-ip",
|
| 115 |
+
}
|
| 116 |
forward_headers = [
|
| 117 |
(k, v) for k, v in request.headers.raw
|
| 118 |
+
if k.lower() not in STRIP_HEADERS
|
| 119 |
]
|
| 120 |
|
| 121 |
client = httpx.AsyncClient(
|