Skip to content

qBittorrent 5.x 登录失败:Unable to authenticate with Web Api,cookie 名格式变化未兼容 #238

Description

@wc279956766
 `composer/bittorrent-client/src/Driver/qBittorrent/Client.php` 的 `login()` 方法使用:

 ```php
 preg_match('/SID=(\S[^;]+)/', $header, $matches)
 ```

 这个正则在 qb 5.x 的 `QBT_SID_8088=...` 中匹配不到 `SID=`(`SID` 后面是 `_` 不是 `=`),结果 `login()` 永远 return
 false,触发上面的 RuntimeException。

 ## 复现

 1. qBittorrent 5.20
 2. 在 IYUUPlus dev 后台添加下载器:URL `http://host:port`,正确的 admin 用户名密码
 3. 保存即报错

 ## 建议修复

 把 regex 改成同时兼容新旧两种格式:

 ```diff
 - if (preg_match('/SID=(\S[^;]+)/', $header, $matches)) {
 + if (preg_match('/(?:QBT_)?SID(?:_\d+)?=(\S[^;]+)/', $header, $matches)) {
 ```

 新 regex 解读:可选的 `QBT_` 前缀 + `SID` + 可选的 `_<数字端口>` 后缀 + `=value`。两种格式都覆盖。

 ## 验证

 容器内热打补丁后,立即可以正常添加 qb 5.2 下载器,session cookie 正确传递。

 ## 环境

 - IYUUPlus dev 镜像:`iyuucn/iyuuplus-dev:latest`(2026-05-01 build)
 - qBittorrent: 5.2.0 (LinuxServer image, libtorrent v1.2.x)
 - Docker: 29.x,host 网络模式

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions