DSH Web UI Session Auto-ReLogin Plugin

Preface

DSH Web sessions have a fixed expiration period. Once expired, the browser gets stuck on a 401 page and the user has no choice but to go back to the terminal to restart. This plugin installs a Service Worker on the browser side that intercepts top-level navigations receiving a 401, replaces the expired page with a confirmation page, uses DSH’s authorization flow to obtain a new signed Cookie, and then redirects back to the original workspace.

Plugin Overview

dsh-auth-refresh is a session auto-renewal plugin for the DSH Web UI, maintained by r56661828-cloud. The plugin does not touch, generate, or store any tokens. Signing is still performed by DSH’s authorizeIndex; the plugin only initiates a gated redirect on the loopback address.

Features

Two Modes

  • confirm (default) — The 401 navigation is replaced with a confirmation page; the user clicks “Reconnect” once.
  • auto — The session is renewed and reloaded in the background, with zero user interaction.

Loopback Gate

POST /__auth-refresh only accepts requests where the Host header is a local loopback address and Sec-Fetch-Site is same-origin or none. Cross-site navigations are always rejected with 403.

Tokens Never Appear on Screen

The redirect target is generated server-side via ctx.connection.authenticatedUrl(), so tokens never flash in the address bar. The confirmation page includes referrer-policy: no-referrer.

Self-Cleanup on Uninstall

After the plugin is removed, the page probe deregisters any lingering Service Worker, ensuring no orphan worker is left behind intercepting 401s.

Bilingual (English / Chinese)

Automatically switches based on the Accept-Language header.

Installation & Activation

Install from Gitee (requires DSH ≥ 0.2.2-rc.1):

dsh plugin --profile web add git+https://gitee.com/you-renjun/dsh-auth-refresh.git

After installation, restart dsh web once (or let the profile patch reload), then refresh the browser page. On page load, the plugin automatically registers the Service Worker.

This package contains no build scripts, and no client.js-type artifacts exist, so no allowBuilds authorization is required.

Configuration

The default mode is confirm. To switch to full auto, override the config line in your profile patch:

- id: dsh-auth-refresh
  name: '@you-renjun/dsh-auth-refresh'
  config:
    mode: auto

mode only accepts confirm and auto. Any other value falls back to confirm.

Uninstallation

dsh plugin --profile web remove @you-renjun/dsh-auth-refresh

After uninstalling, refresh the page once. The probe detects that /__dsh-auth/sw.js returns 404 and deregisters the worker.

How It Works

Path Purpose
GET /__auth-refresh Confirmation page (explanation + one button)
POST /__auth-refresh Validates the loopback gate, then 302-redirects to the current process’s authorization URL
GET /__dsh-auth/sw.js Service Worker; the mode is injected at serve time

webServer.tapIndex injects a single-line probe into every authenticated index.html: if the worker is available, register it; if not, deregister the old one.

Compatibility

  • Requires engines.dsh >= 0.2.2-rc.1.
  • Only meaningful under DSH Web (dsh web); it will not activate in headless profiles.
  • Service Worker requires a secure context: localhost / 127.0.0.1 satisfy this; addresses exposed to a LAN over plain HTTP do not.

Use Cases & Caveats

The plugin runs with the current dsh process’s privileges. Review the source code and license before installing. It is recommended for development or debugging scenarios where local access is required and the port is bound to localhost or 127.0.0.1.

Conclusion

This plugin eliminates the pain point of having to return to the terminal to restart after a DSH Web UI session expires. By intercepting 401 navigations on the browser side via a Service Worker and completing the authorization flow on the local loopback address, tokens never leave the machine. It is ideal for developers who need to keep the DSH Web UI running for extended periods.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye