fix(server): 未配置 root_api_key 时仅允许 localhost 绑定#310
Merged
Conversation
当 root_api_key 未配置时 resolve_identity() 将所有请求解析为 ROOT, 结合默认绑定 0.0.0.0 会导致任何网络请求均可执行管理员操作。 - 将默认 host 从 0.0.0.0 改为 127.0.0.1 - 添加 validate_server_config() 启动校验:无 key + 非 localhost 时拒绝启动 - 将 dev mode 日志从 info 升级为 warning - 更新中英文认证文档的开发模式段落 Closes #302 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
|
zhoujh01
approved these changes
Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
修复安全漏洞:当
server.root_api_key未配置时,resolve_identity()将所有请求解析为Role.ROOT,结合默认绑定0.0.0.0(所有网络接口),导致任何网络请求均可执行管理员操作。本 PR 将默认绑定地址改为
127.0.0.1,并在启动阶段校验配置安全性:无认证 + 非 localhost 绑定时拒绝启动。Related Issue
Fixes #302
Type of Change
Changes Made
openviking/server/config.py:默认host从0.0.0.0改为127.0.0.1(ServerConfig和load_server_config两处);新增_is_localhost()辅助函数和validate_server_config()启动校验函数,无 key + 非 localhost 时调用sys.exit(1)并输出错误日志和修复建议openviking/server/app.py:create_app()中加载 config 后调用validate_server_config();dev mode 日志从logger.info升级为logger.warning,明确提示认证已禁用tests/server/test_auth.py:新增 6 个测试用例(含参数化共 10 个 case),覆盖_is_localhost和validate_server_config的各种场景docs/{en,zh}/guides/04-authentication.md:更新开发模式段落,示例 host 改为127.0.0.1,添加安全说明Testing
验证场景:
pytest tests/server/test_auth.py— 全部 22 个测试通过host: "0.0.0.0"+ 无root_api_key→ 服务器拒绝启动(SystemExit)host: "127.0.0.1"+ 无root_api_key→ 正常启动,输出 WARNING 日志host: "0.0.0.0"+ 有root_api_key→ 正常启动Checklist
Additional Notes
ServerConfig()默认值改为127.0.0.1后,因属于 localhost 范围,校验自动通过,无需修改 conftestauth.py中resolve_identity()逻辑保持不变,安全保护在启动阶段完成