fix: 修复 upload_file 任意文件读取、downloadFile SSRF 等一批低风险 bug(v0.6.11) - #115
Open
crazywhalecc wants to merge 4 commits into
Open
fix: 修复 upload_file 任意文件读取、downloadFile SSRF 等一批低风险 bug(v0.6.11)#115crazywhalecc wants to merge 4 commits into
crazywhalecc wants to merge 4 commits into
Conversation
- upload_file 的 path 类型增加目录限制,仅允许读取配置的上传目录内文件(realpath 前缀校验,符号链接逃逸一并拦截) - downloadFile 的 URL 校验改为 fail-closed:拒绝内网/保留 IP(含 IPv4/IPv6 各保留段)、DNS 解析失败拒绝、 拒绝十进制/八进制/十六进制等 IP 混淆形式;修复 AAAA 记录(ipv6 键)被跳过导致仅 IPv6 域名绕过校验的问题 - 分片上传 prepare 增加 100 个上限与 10 分钟过期清理,每次 transfer 刷新过期时间;修复 md5(microtime) 快速连续 prepare 时碰撞覆盖的问题
- ObjectPool 的等待协程队列由静态改为实例属性,多个池共存时不再互相 resume 串对象 - AbstractObjectPool::return 对 SplQueue 的 push 返回 void 不再触发 TypeError - 协程环境失效时归还的对象不再被静默丢弃 - HTTP 请求处理异常发生在响应创建前时,兜底发送 500 响应避免客户端永久等待
- 删除 Swoole WebSocket 握手时的 echo 调试残留,保留 Sec-WebSocket-Key 校验逻辑 - 实现 Swoole WSServerSocket::close,此前该接口永远返回 false 导致无法主动关闭连接 - WebSocket 客户端 URI fragment 由 ? 修正为 #,Workerman 客户端端口为 null 时默认 80 - OneBotBuilder 组件构建不再要求配置键的注册顺序 - Driver 未知通信类型不再静默忽略,输出警告日志
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.
概述
本 PR 修复一批不影响公共 API 的低风险 bug(安全、Workerman 驱动、Swoole 驱动、OneBot V12 构建),并配套新增回归测试。版本 bump 至 0.6.11。
修复内容
安全
path类型仅校验了/和..,绝对路径可直接读取服务器任意文件(如/etc/passwd)。现限制为只能读取配置的上传目录内的文件(realpath 双端规范化前缀校验,../、符号链接逃逸、兄弟目录均不可绕过)::1、::、fc00::/7、fe80::/10、::ffff:0:0/96映射地址)dns_get_record对 AAAA 记录返回ipv6键而非ip,原实现只读ip键导致仅解析到内网 IPv6 的域名完全绕过校验::ffff:映射地址前 80 位未校验导致的合法全局地址误判upload_fragment静态缓存无上限、无过期。新增 100 个 prepare 上限与 10 分钟过期清理,transfer 每次刷新过期时间(慢速大文件不会中途被拒);附带修复md5(microtime)快速连续 prepare 时碰撞导致分片互相覆盖的问题Workerman 驱动
AbstractObjectPool::return()必然 TypeError:SplQueue 的push返回 void,在 strict_types 下触发 TypeError,按队列类型分支处理Swoole 驱动
echo调试残留(每次连接向 stdout 输出sec-websocket-key),保留 Sec-WebSocket-Key 校验逻辑WSServerSocket::close()未实现:永远返回 false 导致无法主动关闭连接,现基于server->close($fd)实现其他
?修正为#;Workerman 客户端端口为 null 时生成畸形ws://host:URI,默认补 80测试
composer test:100 tests / 351 assertions,剩余 1 error + 2 failures 为 PHP 8.5 环境存量问题(setAccessible弃用、外部网络测试),与本 PR 无关变更记录
4 个独立 commit:
fix(安全)、fix(Workerman)、fix(驱动)、bump version to 0.6.11。