DSH HUB
HomePlugin StorePlugin PacksCommunityRankingsResourcesPublish Guide
Plugin source
Back to catalog

youkucola /

youkucola/dsh-web-auto-auth

Verified

DSH Desktop plugin: open the web UI without the launch-URL token

★ 0 Stars0 Forks0 IssuesN/A Community rating0 Confirmed installs
View on GitHub
READMESource: main@8272534b

dsh-web-auto-auth

让浏览器直接打开 DSH 的 Web UI,不必再手工粘贴带 token 的启动 URL。

它能解决什么

DSH Desktop(DeepSeek Harness)默认要求用启动时打印的带 ?token= 的 URL 打开 Web 端。直接访问 http://127.0.0.1:<port>/ 会得到:

401 dsh web authentication required

本插件接住未认证的首页访问,把它交给 DSH 自己的 token → cookie 兑换流程,浏览器随后带着正常的 dsh-auth-* cookie 回到页面。

工作原理

没有绕过认证。 这是设计核心:会话 cookie 始终由 DSH 官方代码签发,插件只是替浏览器发出那一次登录请求。

  • 插件覆写 ctx.connection.authorizeIndex。
  • 先构造一个「探针」响应对象,调用一次官方实现拿到判定结果,不复刻鉴权逻辑。
  • 官方返回非 401(例如 token 兑换的 303 + Set-Cookie)时逐字重放,保证桌面宿主依赖的 status === 303 与 set-cookie 都不受影响。
  • 官方返回 401 且这次请求的 Host 在白名单内时,改写为 303 跳转到 ctx.connection.authenticatedUrl(...)。浏览器跟随该 URL 后由官方签发 dsh-auth-* cookie,此后 /、/api/*、WebSocket 全部正常工作。
flowchart TD
    A[浏览器 GET /] --> B[插件 → 官方 authorizeIndex]
    B --> C{返回 401?}
    C -- 否: 原样重放 --> D[官方 303 + Set-Cookie]
    C -- 是 --> E{Host 在白名单?}
    E -- 否: 原样重放 --> F[浏览器看到官方 401]
    E -- 是 --> G[303 到 ?token= URL]
    G --> D
    D --> H[官方签发 dsh-auth-* cookie]
    H --> I[GET / → 200]

安装

推荐方式:在 DSH 桌面端的「插件市场 / 添加插件」里填本仓库地址。

手工方式(本机已验证的做法):

  1. git clone 到任意目录。

  2. 在该目录与 profile 的 node_modules 之间建立目录链接。Windows 下用 mklink /J,或用 fs.symlinkSync(target, path, 'junction')。

  3. 把包名 dsh-web-auto-auth 加入 <profile>/package.json 的 dsh.profile.bundles 数组,并在 dependencies 里加一条指向本地的链接依赖(注意用正斜杠):

    {
      "dependencies": {
        "dsh-web-auto-auth": "link:<绝对路径>"
      },
      "dsh": {
        "profile": {
          "bundles": ["dsh-web-auto-auth"]
        }
      }
    }
    

    这一段只是形状示例,不要整体替换。真实 profile 的 dependencies 与 dsh.profile.bundles 通常已经有多项(本机是 11 项 + 15 项),只能往已有的这两处里各追加一项,整体覆盖会丢掉既有插件配置。追加后需保证仍是合法 JSON。

  4. 完全退出 DSH 再启动。

profile 目录通常是 ~/.dsh/profiles/desktop。

包内 cordis.patch.yml 里是 required: false:插件出错时宿主会跳过它,DSH 照常启动(仍然要求启动 URL),不会因为插件失败而启动不起来。

配置

插件行来自包内自带的 cordis.patch.yml:本包 package.json 的 dsh.bundle.patch = ./cordis.patch.yml 把这个文件作为 bundle 补丁层载入,profile 的补丁层里并没有 web-auto-auth 条目。插件从这个条目的 config 读取配置,只有两个键。

键 默认值 说明
enabled true 设为 false 等同禁用插件,未认证首页仍返回官方 401。
extraHosts [] 额外允许的主机名数组。

包内 cordis.patch.yml 的内容(extraHosts 已填示例值):

- insert:
    - id: web-auto-auth
      name: dsh-web-auto-auth
      required: false
      config:
        enabled: true
        extraHosts:
          - dsh.example
          - <your-lan-host>

要改配置(enabled / extraHosts),最直接的做法是改包内 cordis.patch.yml 的 config。也可以不动包内文件,在 profile 的 cordis.patch.yml 补丁层里补一项同一个 id: web-auto-auth 的条目来覆盖 config:cordis 的补丁按 id 覆盖整份 config,所以这一项里最好把 enabled 与 extraHosts 都写全。

extraHosts 只匹配主机名,不能带端口。写 dsh.example:8443 会静默不生效,应写 dsh.example。

默认只对 loopback 生效:127.x.x.x、localhost、[::1] / ::1。如果 DSH 绑定到局域网 IP,把该主机名加进 extraHosts 才会自动跳转。

安全说明

  • 插件没有关闭认证,也没有放宽 /api 的信任栅栏。它只是让浏览器替你去完成官方的一次性兑换。
  • 代价:任何能访问该回环端口的本机进程都能自动换到 owner 级 cookie。装上它就是选择接受这个本机访问门槛。
  • 白名单是必需的。authorizeIndex 本身不做 Host 信任校验,若直接拿 Host 头拼跳转 URL,Host: evil.example 会把 launch token 送到攻击者域名(DNS rebinding)。插件因此只对 loopback(或显式 extraHosts)下发 303,其它 Host 一律重放官方 401。
  • 含 @ 的 Host(userinfo 形态)被显式拒绝。evil.example@127.0.0.1:<port> 会被解析成 loopback,所以这类输入直接判定为不可信。
  • 跳转目标若不携带 token 参数则放弃跳转、退回官方 401,防止重定向死循环。

验证方法

<port> 换成 DSH 实际监听端口。

下面这三条命令要在 Git Bash 里执行,或在 PowerShell 里改用 curl.exe:Windows PowerShell 5.1 里 curl 是 Invoke-WebRequest 的别名,直接写 curl -si 会报参数错误。

# 期望: 303 + location: http://127.0.0.1:<port>/?token=..., 且无 set-cookie
curl.exe -si -H 'Host: 127.0.0.1:<port>' http://127.0.0.1:<port>/

# 期望: 401 + "dsh web authentication required"
curl.exe -si -H 'Host: evil.example:<port>' http://127.0.0.1:<port>/

# 期望: 401(token 错误时官方不签发 cookie)
curl.exe -si 'http://127.0.0.1:<port>/?token=WRONG'

卸载 / 回滚

  1. 删掉 node_modules 里的目录链接。
  2. 从 dsh.profile.bundles 和 dependencies 里去掉 dsh-web-auto-auth。
  3. 完全退出 DSH 再启动。

兼容性

已在 DSH Desktop 0.2.2-rc.3、Node 24 上实测通过。

若宿主升级后 authorizeIndex 的签名变化,插件会在 typeof raw.authorizeIndex !== 'function' 时静默退出:不报错,也不拖垮宿主(此时未认证首页恢复官方 401),需要针对新版本适配。

开发

npm test

即 node --test,共 17 条用例覆盖跳转、拒绝、重放、还原与重复安装等分支。零运行时依赖。

License

MIT

—/ 5

No ratings yet

Verified DSH bundle

Commit 8272534b8752

Community comments

No comments yet. Be the first to write one.

DSH HUB

A community index for DSH plugins. Not an official GitHub or DeepSeek AI product.

CommunityResourcesAPIAbout