Repository navigation
Conversation
|
@CieveMe is attempting to deploy a commit to the 648540858's projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
关联议题:#2238
问题
/index/hook/**在安全配置里是免认证的(WebSecurityConfig的defaultExcludes),任何人都可以伪造媒体服务器的回调。其中on_record_mp4会把请求体里的文件路径原样写入wvp_cloud_record,之后读取侧按库内路径取文件 —— 回调来源不可信是这条链的起点。根因
媒体服务器(ZLMediaKit)的 hook 请求不带任何凭据:
server/WebHook.cpp只往 body 里加mediaServerId/hook_index,然后 POST 到配置里的 URL;官方conf/config.ini的[hook]段也没有 secret 项。wvp 本来就通过setServerConfig把自己拼好的 hook URL 下发给媒体服务器,所以要在 URL 上带一个校验值,成本最低且不需要改媒体服务器。改动范围
UserSetting新增hookSecret(user-settings.hook-secret,默认空字符串)。hookSecret就往 hook URL 追加?secret=xxx:ZLMMediaServerStatusManager(10 个hook.on_*)ABLMediaServerStatusMangerHookSecretFilter:hookSecret为空时不做任何处理;配置后,/index/hook(及/index/hook/前缀)的请求必须携带同一个secret,否则返回 401。比较使用常量时间实现,过滤器显式排序在 Spring Security 之前。src/main/resources/配置详情.yml,docker 部署给了注释示例。改动文件(6 files / +126 −11):
conf/UserSetting.javahookSecretconf/security/HookSecretFilter.java(新增)/index/hook/**的secretmedia/zlm/ZLMMediaServerStatusManager.java?secret=media/abl/ABLMediaServerStatusManger.javasrc/main/resources/配置详情.ymldocker/wvp/wvp/application-docker.yml本 PR 选择的方案:A + 放行(保持向后兼容)
密钥来源(横向)与"密钥未配置时如何处理"(纵向)可以组合成四格,本 PR 实现的是 (1) A + 放行;其余三格如果需要,可以快速切换(两个变体补丁已经写好,见文末):
user-settings.hook-secretmedia_server.secret(ZLM 的 API 密钥)改动:新增配置 + 两处 URL 追加 + 过滤器空值放行。
兼容:未配置时行为与今天完全一致;配置后需媒体服务器重新下发一次 hook(在下发前会被 401)。
凭据卫生:好(hook 专用密钥,泄露也调不动 ZLM 的 API)。
升级:加
user-settings.hook-secret(或USER_SETTINGS_HOOKSECRET)→ 重启 → 重启/重新注册媒体服务器。改动:下发改用媒体服务器自己的
secret;过滤器改为"匹配任一已注册媒体服务器的 secret";不新增配置。兼容:有
secret的部署默认生效;没有secret的部署等于没开——"看起来开了、其实没开"。凭据卫生:差(见下)。
改动:仅把过滤器空值分支反转(未配置即 401,只告警一次)。
兼容:破坏性——未配置的部署升级后所有 hook 断链(录像完成事件写不进
wvp_cloud_record、设备状态/心跳回调失效),必须先配置再升级。凭据卫生:好。
改动:B2 的下发 + 过滤器语义,且未配置/匹配不上时拒绝。
兼容:最严格且默认开启,影响面比 (3) 更大。
凭据卫生:差(同 B2)。
关于 B2 的凭据卫生(必须说明,避免只看到"零配置"的优点):复用
media_server.secret会把调用媒体服务器 HTTP API 的密钥放进 hook URL;ZLM 在 hook 失败时会把完整 URL + body 打进自己的日志(server/WebHook.cpp:202,本地核实)。日志一旦被采集/转发/贴出,就等于泄漏 API 密钥。A 用的是独立密钥,即使泄漏也调不动 ZLM 的 API。如果维护者选 (2)/(3)/(4),我可以马上换分支:
fix/2238-hook-secret-b2(B2)与fix/2238-hook-secret-deny(未配置即拒绝)都已实现并编译通过,patch 见raw/2238/hook-secret-b2.patch、raw/2238/hook-secret-deny.patch。验证方式
mvn -DskipTests -q compile→ exit 0。@Component+@Order(Ordered.HIGHEST_PRECEDENCE + 100),会排在 Spring Security 之前;/index/hook/**在WebSecurityConfig里是permitAll,不会短路过滤器链。ZLMHttpHookListener与ABLHttpHookListener,过滤器按/index/hook前缀统一覆盖。UserSetting是@ConfigurationProperties,密钥只来自配置文件/环境变量,不落库,因此本次改动不需要数据库迁移。未验证项
hook-secret时,不带secret的 hook 请求与改动前一致(正常返回);hook-secret: testSecret并重启后:不带secret的/index/hook/on_server_keepalive→ 401;带?secret=testSecret→ 正常返回;wvp_cloud_record。兼容性提示
手工在媒体服务器上直接配过 hook URL(而不是由 wvp 下发)的部署,需要重新下发一次配置才会带上
secret;在重新下发之前,该媒体服务器的 hook 会被 401 拒绝。这是"安全优先"的代价,也是本 PR 选择"未配置即放行"默认值的原因。可复现命令块(静态核对)