Skip to content

fix: bind docker compose port to localhost by default#25

Closed
study8677 wants to merge 1 commit into
mainfrom
codex/fix-docker-deployment-api-exposure
Closed

fix: bind docker compose port to localhost by default#25
study8677 wants to merge 1 commit into
mainfrom
codex/fix-docker-deployment-api-exposure

Conversation

@study8677
Copy link
Copy Markdown
Owner

Motivation

  • The Docker setup exposed the unauthenticated local API by setting OPENCMO_WEB_HOST=0.0.0.0 in the image and publishing port 8080 in docker-compose.yml, which makes the API reachable on all host interfaces by default.

Description

  • Update docker-compose.yml to change the ports mapping from 8080:8080 to 127.0.0.1:8080:8080 so the web UI/API remains accessible from the host only and is not exposed to external interfaces by default.

Testing

  • Ran git diff --check which completed with no errors.
  • Attempted docker compose config to validate the composed config but it could not be executed in this environment because docker is not installed (command-not-found).

Codex Task

Copy link
Copy Markdown
Owner Author

@study8677 study8677 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

总体评价

这是一个正确且有必要的安全修复。将 docker-compose.yml 端口绑定从 0.0.0.0:8080 改为 127.0.0.1:8080 有效消除了默认暴露场景下的攻击面。改动精准、没有多余变更。建议合并(Comment),但有两个中等优先级问题值得跟进。


问题清单

级别 文件 & 位置 描述 建议
🟡 建议 DockerfileEXPOSE 8080 + ENV OPENCMO_WEB_HOST=0.0.0.0 直接使用 docker run -p 8080:8080 opencmo(不走 docker-compose)的用户将仍把端口暴露在所有网络接口上,此 PR 对他们无效。OPENCMO_WEB_HOST=0.0.0.0 是容器内网络转发所必须的(不能改为 127.0.0.1,否则 Docker 端口转发失效),但缺少说明容易误导用户以为改这个变量可以加固安全。 Dockerfile 的对应行加一条注释,并在 README 的 Docker 使用说明中注明:裸用 docker run 时需显式指定 -p 127.0.0.1:8080:8080
🟡 建议 README.md / 文档(未修改) 无文档说明此次行为变更的含义:默认情况下 API 只能从本机访问;若要从同网络其他机器访问(如反向代理部署在不同主机时),需手动修改绑定地址。 在 README 的 Docker 部署章节补充说明默认行为及如何覆盖(例:ports: - "0.0.0.0:8080:8080" 用于代理场景)。
🟢 优化 docker-compose.yml L5 绑定 127.0.0.1 的安全意图不言而喻,但加一行注释有助于将来维护者理解原因而不误改回去。 # Bind to localhost only — prevents unintended exposure on public interfaces

亮点

  • 改动最小化:仅改一行,不引入任何噪音,完全符合安全修复的最佳实践。
  • 定位准确:宿主机侧端口绑定(docker-compose ports 映射)才是正确的修复点,而不是去改容器内的 OPENCMO_WEB_HOST(后者改了反而会破坏 Docker 网络转发)。

修改示例(Dockerfile 注释)

# Must bind to 0.0.0.0 inside the container for Docker port forwarding to work.
# Host-side exposure is controlled by the ports mapping in docker-compose.yml.
ENV OPENCMO_WEB_HOST=0.0.0.0

以及 docker-compose.yml

ports:
  # Bind to localhost only — prevents unintended exposure on public interfaces.
  # To allow remote access (e.g. behind a reverse proxy on another host), change to "0.0.0.0:8080:8080".
  - "127.0.0.1:8080:8080"

Generated by Claude Code

study8677 added a commit that referenced this pull request May 21, 2026
* fix: validate and dedupe geo ask platforms

* fix: bind docker compose port to localhost by default

* fix: prevent verify-email auth bypass for verified users

* fix: fail closed for account-scoped publish credentials

* fix: prevent admin privilege escalation via signup

* test: update admin/publisher tests for security fixes

- test_publishers.py: replace env vars with llm.set_request_keys() since
  publish credentials no longer fall back to os.environ (account-scoped).
- test_trial_platform.py: add _seed_admin() helper that activates the
  bootstrapped !unusable admin row directly, since signup can no longer
  claim that row to prevent admin privilege escalation.

* test: fix ruff I001 import order
@study8677
Copy link
Copy Markdown
Owner Author

Incorporated via #27 → main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant