diff --git a/app/api/endpoints/site.py b/app/api/endpoints/site.py index 3bfaa18bd..ec4b7e3f3 100644 --- a/app/api/endpoints/site.py +++ b/app/api/endpoints/site.py @@ -863,6 +863,8 @@ def auth_site( auth_info.params, sites_helper.get_authsites(), ) + if not auth_params: + return _SchemaResponse(success=False, message="请输入认证站点和认证参数") status, msg = sites_helper.check_user(auth_info.site, auth_params) if status: get_configured_system_config().set( diff --git a/docs/mcp-api.md b/docs/mcp-api.md index d89010c13..df67badb4 100644 --- a/docs/mcp-api.md +++ b/docs/mcp-api.md @@ -255,6 +255,7 @@ Web 影视精确与标题 SSE 的 `manual_paging=true` 模式在最终 `done` 网页和 Cookie,成功说明不代表「用户认证」中的 UID、Passkey 等凭据有效;API 站点使用 各自已适配的登录接口。独立的用户认证仍通过 `POST /api/v1/site/auth` 执行,成功保存时清除 切换站点遗留的其他已知站点前缀字段;启动认证也会过滤这些字段,未知扩展参数继续兼容。 +过滤后参数为空时直接拒绝请求,避免资源改为读取环境变量并认证其他站点。 认证资源 `3.0.7` 起区分超时、DNS、代理、TLS、HTTP 状态及接口内容异常;请求日志记录 脱敏主机、耗时、HTTP 状态和安全调用位置,不输出请求参数、完整 URL 或原始异常字符串。 diff --git a/tests/test_site_auth.py b/tests/test_site_auth.py index 74c53c936..6ff7762e4 100644 --- a/tests/test_site_auth.py +++ b/tests/test_site_auth.py @@ -145,6 +145,26 @@ def test_auth_site_does_not_persist_failed_parameters(monkeypatch) -> None: config.set.assert_not_called() +def test_auth_site_rejects_parameters_belonging_only_to_another_site(monkeypatch) -> None: + """ + 过滤后为空时直接拒绝,避免资源把空参数误当成改用环境变量认证。 + """ + helper = Mock() + helper.get_authsites.return_value = AUTH_SITES + config = Mock() + _patch_auth_endpoint(monkeypatch, helper, config) + + response = site_endpoint.auth_site( + SiteAuth(site="haidan", params={"HDKYL_UID": 456, "HDKYL_PASSKEY": "old"}), + SimpleNamespace(), + ) + + assert response.success is False + assert response.message == "请输入认证站点和认证参数" + helper.check_user.assert_not_called() + config.set.assert_not_called() + + @pytest.mark.parametrize("locale,message,expected", [ ("en-US", "请求超时", "Request timed out"), ("en-US", "认证接口返回 HTTP 403", "Authentication endpoint returned HTTP 403"),