# openpi serve_policy默认绑定0.0.0.0且泄露Traceback的安全风险

> 原文链接：https://robotics.hellobike.com/pitfalls/2026-09-19-openpi-1039
> 频道：pitfalls | 更新日期：2026-09-19 | 标签：auto, github-issue, openpi
> 核心摘要：serve_policy脚本默认监听0.0.0.0并向客户端返回堆栈信息。临时绕过需手动修改源码绑定127.0.0.1并移除traceback发送逻辑，但需注意浏览器同源攻击风险。

# openpi serve_policy默认绑定0.0.0.0且泄露Traceback的安全风险

::: v-pre
> 本文由 AI 根据公开内容整理，可能有误，请以原文为准：[serve_policy exposes the websocket policy server on 0.0.0.0 with no --host flag and returns tracebacks to the client](https://github.com/Physical-Intelligence/openpi/issues/1039)（GitHub Physical-Intelligence/openpi #1039）

**状态**：有绕过办法

## 问题

`scripts/serve_policy.py` 仅暴露 `--port` 参数，底层 `websocket_policy_server.py` 硬编码 `host="0.0.0.0"` 且无鉴权。服务端在异常时直接通过 WebSocket 发送 `traceback.format_exc()`，导致内网环境下机械臂策略接口可被未授权远程调用，且泄露服务器文件路径等敏感信息。此外 `max_size=None` 允许无限帧大小。

## 环境

Physical-Intelligence/openpi 仓库 main 分支；涉及 `src/openpi/serving/websocket_policy_server.py` 与 `scripts/serve_policy.py`；依赖 `websockets` 库。

## 解决办法

1. 编辑 `scripts/serve_policy.py`，为 CLI 添加 `--host` 参数并将默认值设为 `127.0.0.1`，将其传递给 `WebsocketPolicyServer` 构造函数以限制网络访问。
2. 修改 `websocket_policy_server.py` 中的异常处理逻辑，移除 `await websocket.send(traceback.format_exc())`，改为发送通用字符串 "Internal server error."，防止路径泄露并保持 `websocket_client_policy.py` 的 `isinstance(response, str)` 兼容性。
3. 注意：仅绑定 Loopback 无法防御浏览器端攻击（WebSocket 不受 CORS 预检限制）。需在 `serve()` 调用的 `process_request=_health_check` 钩子中增加 Origin 白名单校验或 Token 验证，…

讨论原作者：@sattyamjjain 等，版权归原作者所有。
:::

## 原始参考来源 (Sources)

- [GitHub Physical-Intelligence/openpi #1039：serve_policy exposes the websocket policy server on 0.0.0.0 with no --host flag and returns tracebacks to the client](https://github.com/Physical-Intelligence/openpi/issues/1039)