dsh-totp-proxy: A Reverse Proxy Adding TOTP and Revocable Sessions to DSH

Preface

DeepSeek Harness (DSH) typically holds a self-contained bearer cookie issued by the core, dsh-auth-*, on the browser side. Once this cookie is leaked, the caller may still access the API directly before it expires, and it is difficult to “immediately invalidate” the credentials in the browser from the server side. If you want to place the Web interface behind Nginx while adding an extra layer of login verification, the common approach is to layer another gateway or modify the core authentication flow, requiring you to sort out the operational and security boundaries yourself.

Below is an introduction to the community plugin dsh-totp-proxy (maintained by realjhen123): It serves as both a DSH/Cordis plugin and a reverse proxy for the DSH upstream. It features built-in TOTP and static token login. The browser only holds a revocable dsg_session, while the original dsh-auth-* remains on the proxy server side.

What is this

dsh-totp-proxy is positioned as: a standalone DSH/Cordis plugin + reverse proxy; with zero additional runtime dependencies, requiring Node.js 22+ (the implementation only uses node:http / node:https). The current package version is 0.2.0, licensed under MIT.

The typical chain is as follows (excerpted from the README architecture description):

Browser --dsg_session--> Nginx :80/:443 --> dsh-totp-proxy 127.0.0.1:3090 --dsh-auth cookie--> DSH 127.0.0.1:3080

The proxy validates TOTP / static tokens itself, reads DSH’s browser-session signing key, and signs cookies recognized by the DSH core; every HTTP request and WebSocket upgrade is validated by the proxy, and deleting the server-side session allows for immediate revocation.

Core Features

Authentication Methods

Controlled via authMode (or environment variable DSH_TOTP_PROXY_AUTH_MODE):

authMode Behavior
totp Only accepts 6-digit verification codes
token Only accepts static token
both Either one (Default)

Credentials are automatically generated upon first run and saved in ~/.dsh/dsh-totp-proxy/:

  • totp.json — Base32 TOTP secret
  • token.json — Static access token

Consecutive failures reaching the limit (default 10 times) will trigger an IP lock (default 60 seconds). TOTP can be used with common authenticators like Apple Passwords and 1Password.

Differences from Native DSH Cookies

DSH core’s dsh-auth-* is a self-contained bearer cookie; if the browser already holds it, it may call the API directly before expiration even if a verification code prompt appears again. This proxy keeps the original cookie on the server side; the browser only receives a random session (default cookie name dsg_session), architecturally reducing the surface area of high-privilege credentials visible to the browser.

Security Boundaries (Author’s Note)

What it can do: The browser cannot see dsh-auth-*; deleting the server-side session revokes access immediately; all API / WebSocket requests undergo unified validation.

Still need to note: dsg_session is still a bearer credential; if stolen, it can be replayed within its TTL. HTTPS, HttpOnly, SameSite=Strict, and a short TTL are required; sessions are in memory, requiring re-login after a proxy restart.

The project NOTICE also emphasizes: While this is a design concept for public network environments, do not deploy this solution directly on the real public internet; if using the plugin, ensure that Nginx (or any reverse proxy) can only proxy to 3090, and 3080 must not be externally accessible.

Installation and Activation

As a DSH Plugin

Example command from the README (replace the path with the plugin directory after cloning or downloading on your machine):

dsh plugin --profile web add /home/coder/project/dsh-totp-proxy -w

Configuration can be overridden using cordis.patch.yml, for example:

- id: dsh-totp-proxy
  config:
    host: 127.0.0.1
    port: 3090
    target: http://127.0.0.1:3080
    cookieSecure: true
    authMode: both

Standalone Run

When not mounted via Cordis, you can start the entry script directly:

node totp-proxy.mjs

Local Validation

npm run check   # Syntax check + node --test

Typical Usage and Configuration

Common Environment Variables

For full default values, refer to DEFAULTS in src/server.mjs in the repository. Common items are as follows:

Variable Default Description
DSH_TOTP_PROXY_HOST 127.0.0.1 Listening address
DSH_TOTP_PROXY_PORT 3090 Listening port
DSH_TOTP_PROXY_TARGET http://127.0.0.1:3080 DSH upstream
DSH_TOTP_PROXY_AUTH_MODE both totp / token / both
DSH_TOTP_PROXY_TOTP_SECRET Empty Directly specify Base32 secret
DSH_TOTP_PROXY_TOKEN Empty Directly specify static token
DSH_TOTP_PROXY_SESSION_TTL_MS 1800000 Proxy session TTL
DSH_TOTP_PROXY_COOKIE_NAME dsg_session Browser cookie name
DSH_TOTP_PROXY_COOKIE_SECURE false Set to 1 when behind HTTPS
DSH_TOTP_PROXY_BROWSER_SESSION_SECRET Empty DSH cookie signing key
DSH_TOTP_PROXY_CREDENTIALS_FILE ~/.dsh/.credentials.yaml File to read signing keys
DSH_TOTP_PROXY_UPSTREAM_SESSION_PATH /api Upstream session validation path

When setting DSH_TOTP_PROXY_COOKIE_SECURE=1, it must be paired with HTTPS; neither DSH’s 3080 nor the proxy’s 3090 should be exposed directly to the public network.

Binding TOTP without a GUI Environment

The configuration page requires access via the local machine. If DSH is running in a virtual machine without a graphical interface, and for the first time or if the TOTP is forgotten, the README suggests using SSH local port forwarding:

ssh dsh@dsh -NL 3080:127.0.0.1:3080

Then open 127.0.0.1:3080 in a local browser to view the QR code and complete TOTP binding.

When modifying proxy-related configurations:

ssh dsh@dsh -NL 3090:127.0.0.1:3090

Manage dsh-totp-proxy configuration at 127.0.0.1:3090.

Deployment Key Points

  1. Only expose Nginx (:80 / :443) to the outside, reverse proxy to 127.0.0.1:3090, and forward Upgrade / Connection to support WebSocket.
  2. DSH only listens on 127.0.0.1:3080.
  3. Set DSH_TOTP_PROXY_COOKIE_SECURE=1 in production environments.
  4. Keep permissions for ~/.dsh/.credentials.yaml (containing client-connection / browser-session keys) at 0600.

Use Cases and Precautions

Suitable for: Already using Nginx to expose DSH Web within an intranet or controlled boundary, hoping to add a layer of TOTP or static token, and requiring server-side revocable browser sessions instead of handing the full dsh-auth-* to the browser.

Before installation: The plugin runs with the permissions of the current DSH process; review the source code and MIT license yourself before installation. The DSH ecosystem emphasizes “everything is a plugin”; the community directory SkillHub Plugin Page is an independent site and has no official affiliation with DeepSeek / High-Flyer.

Through the steps above, you can centrally perform TOTP/token validation behind a reverse proxy and control the revocation surface using dsg_session; details and updates are subject to the repository README.

  • Directory Page: https://www.skillhub.cn/plugins/realjhen123/dsh-totp-proxy
  • GitHub: https://github.com/realjhen123/dsh-totp-proxy
羽毛球分组比赛记分
小程序二维码

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

Xiaoye