feat(中间件): 添加演示环境IP白名单功能

在演示环境中间件中添加IP白名单检查,只有白名单中的IP才能执行非GET请求
This commit is contained in:
zhangtao
2025-08-24 22:22:57 +08:00
parent e346f1ede1
commit 630619e2aa
2 changed files with 6 additions and 1 deletions
+2 -1
View File
@@ -77,7 +77,8 @@ class DemoEnvMiddleware(BaseHTTPMiddleware):
async def dispatch(
self, request: Request, call_next: RequestResponseEndpoint
) -> Response:
if settings.DEMO_ENABLE and request.method != "GET":
client_ip = request.client.host
if settings.DEMO_ENABLE and request.method != "GET" and client_ip not in settings.DEMO_IP_WHITE_LIST:
path = request.scope.get("path")
if path in settings.DEMO_BLACK_LIST_PATH:
return ErrorResponse(msg="演示环境,禁止操作",)