T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- start-simple.py:76
- Finding
- Unauthenticated network access to memory, persona, and administrative APIs<![CDATA[ ## Vulnerability Details **File Location**: `start-simple.py:76-82`; `app/config.py:17-19, 81-82`; `app/main.py:66-76`; `app/api/routes.py:37-43, 65-72, 109-115, 198-235`; `app/api/persona_routes.py:17-110` **Vulnerability Type**: Missing authentication and authorization on a network-exposed API **Risk Level**: High ### Vulnerable Code ```python # start-simple.py:76-82 print("📡 服务启动中...") print(" 地址: http://0.0.0.0:9090") print(" 文档: http://localhost:9090/docs") print() uvicorn.run(app, host="0.0.0.0", port=9090, reload=False) ``` ```python # app/config.py:81-82 API_KEY: str = "" ALLOWED_ORIGINS: List[str] = ["*"] ``` ```python # app/main.py:66-76 app.add_middleware( CORSMiddleware, allow_origins=settings.ALLOWED_ORIGINS, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(router) app.include_router(persona_router) ``` ```python # app/api/routes.py:37-43 @router.post("/memory", response_model=SetMemoryResponse) async def set_memory( request: SetMemoryRequest, service: MemoryService = Depends(get_memory_service) ): try: return await service.set(request) ``` ```python # app/api/routes.py:198-235 @router.post("/tasks/daily") async def run_daily_persistence( service: MemoryService = Depends(get_memory_service) ): try: await service.run_daily_persistence() logger.info("Daily persistence task triggered manually") return {"success": True, "task": "daily_persistence"} except Exception as e: logger.exception(f"Error in daily persistence: {e}") raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to run daily persistence" ) @router.post("/tasks/weekly") async def run_weekly_archive( service: MemoryService = Depends(get_memory_service) ): try: await service.run_weekly_archive() logger.info("Weekly archive task triggered manually") ...[truncated 1901 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Bind to `127.0.0.1` by default and require an explicit configuration change for remote access. 2. Require a strong API key, signed token, or mutually authenticated transport for every non-health endpoint. 3. Implement authentication as a global FastAPI dependency or middleware so individual routes cannot accidentally omit it. 4. Add authorization checks separating read, write, persona-management, and administrative-task privileges. 5. Refuse to start in non-loopback mode when `API_KEY` is empty. 6. Replace wildcard CORS origins with an explicit allowlist and enable credentials only when necessary. 7. Rate-limit write, search, persona mutation, and task-trigger endpoints. 8. Disable or separately protect `/docs` and `/redoc` in production. 9. Place the service behind a firewall or authenticated reverse proxy. ]]>
