@gitsang/dsh-gateway 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +421 -2
- package/cordis.patch.yml +15 -0
- package/package.json +63 -4
- package/src/client.js +469 -0
- package/src/index.js +582 -0
- package/src/pages.js +149 -0
- package/src/proxy.js +599 -0
- package/src/pwa.js +271 -0
- package/src/settings-store.js +95 -0
- package/src/stores.js +51 -0
- package/src/token-store.js +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,422 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-gateway
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An installable gateway for the
|
|
4
|
+
[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) web UI.
|
|
5
|
+
|
|
6
|
+
The dsh web server itself is left untouched. This bundle adds **one** row to
|
|
7
|
+
the `web` profile: a gateway that starts beside `dsh web`, reverse proxies HTTP
|
|
8
|
+
and WebSocket traffic to it, relays dsh's own token authentication, and can
|
|
9
|
+
deliver the page as an installable PWA.
|
|
10
|
+
|
|
11
|
+
Authentication is **dsh's**, not the gateway's. The gateway owns no password
|
|
12
|
+
and no session store: it forwards the signed cookie dsh minted and lets dsh
|
|
13
|
+
decide. Its one credential-related job is keeping the sign-in token stable
|
|
14
|
+
across restarts (see [Long-lived sign-in token](#long-lived-sign-in-token)).
|
|
15
|
+
|
|
16
|
+
## Why "gateway"
|
|
17
|
+
|
|
18
|
+
The bundle owns the browser-facing access layer — reverse proxying, loopback
|
|
19
|
+
identity for upstream plugins, credential relay, PWA assets, service-worker
|
|
20
|
+
caching, and Host-mode injection — while dsh keeps owning identity. A gateway
|
|
21
|
+
describes that boundary.
|
|
22
|
+
|
|
23
|
+
The package, bundle row, environment prefix and data directory all use
|
|
24
|
+
`dsh-gateway` / `gateway`.
|
|
25
|
+
|
|
26
|
+
## How authentication works
|
|
27
|
+
|
|
28
|
+
dsh mints one random launch token per process and prints (and usually opens) its
|
|
29
|
+
application URL with `?token=…` (the gateway replaces that per-process token
|
|
30
|
+
with a persistent one; see below). `GET /?token=…` exchanges the token for a
|
|
31
|
+
signed browser cookie and redirects to the clean `./`. The cookie is:
|
|
32
|
+
|
|
33
|
+
- named `dsh-auth-<base64url sha256 of the request authority>`,
|
|
34
|
+
- bound to the authority (hostname + port, plus scheme on TLS) it was minted for,
|
|
35
|
+
- `HttpOnly; SameSite=Strict; Path=/`, valid 30 days by default,
|
|
36
|
+
- `Secure` only when the listener that received the request serves TLS.
|
|
37
|
+
|
|
38
|
+
The gateway relays that exchange instead of replacing it:
|
|
39
|
+
|
|
40
|
+
1. A browser opens the **gateway** URL printed at startup
|
|
41
|
+
(`http://127.0.0.1:3081/?token=…`).
|
|
42
|
+
2. The gateway forwards the request to dsh with `Host` rewritten to the
|
|
43
|
+
loopback upstream, so dsh mints the cookie for `127.0.0.1:<dsh port>` — the
|
|
44
|
+
same authority every later proxied request presents.
|
|
45
|
+
3. dsh answers `303` with `Set-Cookie: dsh-auth-…`; the gateway relays it,
|
|
46
|
+
adding `Secure` when the browser-facing hop is HTTPS (see below).
|
|
47
|
+
4. Every subsequent HTTP request and WebSocket upgrade carries that cookie.
|
|
48
|
+
The gateway forwards it **unchanged** to dsh, which accepts or rejects it.
|
|
49
|
+
|
|
50
|
+
There is no gateway login page and no gateway session. If a browser shows up
|
|
51
|
+
without a valid cookie, dsh answers `401`, and the gateway turns that into a
|
|
52
|
+
short explanation page for top-level navigations instead of relaying dsh's
|
|
53
|
+
bare one-line text. API traffic keeps dsh's own `401`/`403`.
|
|
54
|
+
|
|
55
|
+

|
|
56
|
+
|
|
57
|
+
### Signing in
|
|
58
|
+
|
|
59
|
+
Opening the plain gateway origin does nothing useful until a browser holds a
|
|
60
|
+
cookie. Sign in with the URL the gateway prints:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
dsh-gateway: http://127.0.0.1:3081 -> http://127.0.0.1:3080
|
|
64
|
+
dsh-gateway: sign in with http://127.0.0.1:3081/?token=… (stable across restarts)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Long-lived sign-in token
|
|
68
|
+
|
|
69
|
+
dsh itself mints a fresh random launch token per process, which would force
|
|
70
|
+
every new browser to fetch the new startup URL after each restart. The gateway
|
|
71
|
+
installs a **persistent token** instead, so the sign-in URL above never changes
|
|
72
|
+
and can be bookmarked or stored in a password manager:
|
|
73
|
+
|
|
74
|
+
- By default the gateway generates one random 256-bit token on first run and
|
|
75
|
+
persists it to `~/.dsh/gateway/token.txt` (owner-only permissions,
|
|
76
|
+
git-ignored).
|
|
77
|
+
- `DSH_GATEWAY_TOKEN` overrides it with a token you choose (at least 22
|
|
78
|
+
base64url characters, `[A-Za-z0-9_-]`). The env value is never written to
|
|
79
|
+
disk; removing the env falls back to the persisted/generated token.
|
|
80
|
+
- **Rotate** by deleting `token.txt` (or changing the env value) and restarting
|
|
81
|
+
`dsh web`. The old URL stops working; browsers that already hold a cookie
|
|
82
|
+
keep working, because cookies are signed with dsh's separate persistent
|
|
83
|
+
secret, not the launch token.
|
|
84
|
+
- Revoking every *cookie* is still dsh's operation: delete the
|
|
85
|
+
`client-connection/browser-session` record from `$DSH_HOME/.credentials.yaml`
|
|
86
|
+
and restart.
|
|
87
|
+
|
|
88
|
+
Implementation note: dsh exposes no configuration for a stable token, so the
|
|
89
|
+
gateway assigns its token to the Connection service's
|
|
90
|
+
`browserAuth.launchToken` at boot and verifies through the public
|
|
91
|
+
`authenticatedUrl()` that the assignment took effect. This is a deliberate
|
|
92
|
+
dependency on a dsh internal. If a future dsh version moves that field, the
|
|
93
|
+
gateway logs a warning and falls back to the stock behavior (a fresh token per
|
|
94
|
+
restart, printed in the startup line) — sign-in keeps working either way. The
|
|
95
|
+
configuration page shows which mode is active (**登录 Token**: 长期有效 /
|
|
96
|
+
每次重启更换).
|
|
97
|
+
|
|
98
|
+
### Signing out
|
|
99
|
+
|
|
100
|
+
dsh documents no logout operation — "clearing the browser cookie ends one
|
|
101
|
+
browser session". Because dsh's cookie is `HttpOnly`, page JavaScript cannot
|
|
102
|
+
clear it, so the gateway's configuration page offers **退出登录**: it writes an
|
|
103
|
+
expired `Max-Age=0` copy of the exact cookie name for the forwarded authority,
|
|
104
|
+
drops the offline caches, and reloads.
|
|
105
|
+
|
|
106
|
+
Revoking *every* session is dsh's own operation, not the gateway's:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# delete the owner-scoped browser-session grant from $DSH_HOME/.credentials.yaml
|
|
110
|
+
# (or replace it), then restart dsh
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## How it works
|
|
114
|
+
|
|
115
|
+
- Once a request reaches the gateway, it is proxied to dsh's loopback port.
|
|
116
|
+
`Host` and `Origin` are rewritten to `http://127.0.0.1:<dsh web port>`, and
|
|
117
|
+
`Referer` is translated to match, so dsh and plugins that require a local
|
|
118
|
+
host treat traffic through this gateway as local without any
|
|
119
|
+
Traefik/nginx header middleware. `Sec-Fetch-Site` is left untouched so
|
|
120
|
+
cross-site requests are still rejected by dsh's CSRF fence.
|
|
121
|
+
- The browser's `Cookie` header is forwarded as-is, minus the obsolete
|
|
122
|
+
`dsh_gateway_session` cookie from the removed password gate. Every
|
|
123
|
+
`dsh-auth-*` cookie the browser holds reaches dsh untouched, including the
|
|
124
|
+
one minted for the loopback authority.
|
|
125
|
+
- Response cookies are relayed as dsh sent them. The only edit is adding
|
|
126
|
+
`Secure` to the `dsh-auth-*` cookie when the browser-facing hop is HTTPS: dsh
|
|
127
|
+
marks that cookie `Secure` only when *its own* listener terminates TLS, and a
|
|
128
|
+
gateway behind a TLS proxy speaks plain HTTP upstream. Without this the
|
|
129
|
+
browser would hold a non-`Secure` bearer cookie on an HTTPS origin.
|
|
130
|
+
- Absolute `Location` headers pointing at the loopback upstream are translated
|
|
131
|
+
back to the public origin.
|
|
132
|
+
- By default the gateway also serves PWA assets (`/manifest.webmanifest`,
|
|
133
|
+
`/sw.js`, `/favicon.svg`) and injects the manifest link plus a caching
|
|
134
|
+
service-worker registration into HTML pages. The service worker keeps a
|
|
135
|
+
network-first app shell and a cache-first store for content-addressed
|
|
136
|
+
`/assets/*` and `/plugins/*?rev=…` bundles, so repeat and weak-network loads
|
|
137
|
+
do not refetch unchanged JavaScript and CSS. API traffic, the gateway's own
|
|
138
|
+
settings API, dsh's token exchange and WebSocket upgrades are never cached,
|
|
139
|
+
and a navigation that comes back `401` drops the cached shell so signing out
|
|
140
|
+
does not leave the authenticated document available offline. The manifest
|
|
141
|
+
references the SVG icon only. This makes the gateway origin installable as a
|
|
142
|
+
standalone web app on `localhost`/HTTPS.
|
|
143
|
+
|
|
144
|
+
Gateway data is split by scope:
|
|
145
|
+
|
|
146
|
+
- **`token.txt`** (credential) lives in the home-level data directory
|
|
147
|
+
**`~/.dsh/gateway`**, beside `profiles/` — not inside it. `profiles/` is
|
|
148
|
+
reserved for bootable dsh profiles. On first run the gateway creates a
|
|
149
|
+
`~/.dsh/gateway/.gitignore` keeping the token out of git.
|
|
150
|
+
- **`settings.json`** (the PWA / Host-mode toggles) is profile-scoped
|
|
151
|
+
configuration and lives at **`<profile dir>/gateway/settings.json`**
|
|
152
|
+
(e.g. `~/.dsh/profiles/web/gateway/settings.json`), so a dotfiles-style
|
|
153
|
+
config repository can track it and carry it to another machine.
|
|
154
|
+
|
|
155
|
+
Versions before 0.5 kept both files in `~/.dsh/profiles/gateway`. On the first
|
|
156
|
+
boot after upgrading, the token is copied to `~/.dsh/gateway/` and the settings
|
|
157
|
+
file is moved into the running profile's `gateway/` directory automatically
|
|
158
|
+
(the current file always wins; stale copies are left in place and can be
|
|
159
|
+
deleted — if that directory was also booted as a real `gateway` profile,
|
|
160
|
+
remove the profile itself separately).
|
|
161
|
+
|
|
162
|
+
## Gateway configuration page
|
|
163
|
+
|
|
164
|
+
The bundle keeps **one row** for the whole gateway. PWA and Host mode are not
|
|
165
|
+
qol-style independently loadable components: they share the proxy lifecycle,
|
|
166
|
+
and forwarding must never become an independently switchable item. Instead,
|
|
167
|
+
the features and their status live on the row's own page under
|
|
168
|
+
**Plugins → @gitsang/dsh-gateway → Gateway → Configure**. Nothing is injected
|
|
169
|
+
into Settings.
|
|
170
|
+
|
|
171
|
+
The page contains:
|
|
172
|
+
|
|
173
|
+
- **浏览器体验** — PWA switch and a button that clears the gateway's offline
|
|
174
|
+
caches.
|
|
175
|
+
- **兼容性** — Host mode switch, with the security warning and restart
|
|
176
|
+
requirement stated inline.
|
|
177
|
+
- **访问控制** — the authentication provider, whether the sign-in token is
|
|
178
|
+
persistent, the exact cookie name, the sign-in hint, and a **退出登录**
|
|
179
|
+
button that expires this browser's cookie.
|
|
180
|
+
- **运行状态** — listen address, upstream dsh, uptime, version and data
|
|
181
|
+
directory.
|
|
182
|
+
|
|
183
|
+

|
|
184
|
+
|
|
185
|
+
Saving the form stages both switches and writes on **Save**. PWA changes take
|
|
186
|
+
effect on the next page request. Host mode requires a restart of `dsh web`,
|
|
187
|
+
because dsh's index injection is composed during boot. Settings saved on this
|
|
188
|
+
page live in `<profile dir>/gateway/settings.json`; they deliberately do not
|
|
189
|
+
use dsh's own settings store, because turning Host mode off removes the
|
|
190
|
+
browser's Host-settings transport and the gateway page must still be able to
|
|
191
|
+
turn it back on.
|
|
192
|
+
|
|
193
|
+
Environment variables win over the configuration page. When a toggle is managed
|
|
194
|
+
by an environment variable, the page shows it as read-only.
|
|
195
|
+
|
|
196
|
+
The settings API (`/__dsh_gateway/*`) is authenticated by the very cookie dsh
|
|
197
|
+
minted: the gateway validates the caller with one loopback `HEAD /` carrying the
|
|
198
|
+
browser's cookie, and dsh answers `200` only for an unexpired, correctly signed
|
|
199
|
+
cookie for the forwarded authority. Mutating requests additionally require a
|
|
200
|
+
same-origin `x-dsh-gateway: 1` header.
|
|
201
|
+
|
|
202
|
+
## Install
|
|
203
|
+
|
|
204
|
+
Add the bundle to the existing `web` profile:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
dsh plugin --profile web add github:gitsang/dsh-gateway
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Then start dsh web as usual:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
dsh web
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The dsh web server still listens on `127.0.0.1:3080`; the gateway listens
|
|
217
|
+
on the dsh web port plus one (`127.0.0.1:3081` for the default dsh web port).
|
|
218
|
+
Open the sign-in URL the gateway prints, not the bare origin.
|
|
219
|
+
|
|
220
|
+
### Upgrading from 0.2 (password gate)
|
|
221
|
+
|
|
222
|
+
Version 0.3 removes the password gate. There is nothing to migrate:
|
|
223
|
+
|
|
224
|
+
- `auth.json` and `session.json` in the data directory are no longer read. Delete
|
|
225
|
+
them if you like; they contain a now-unused bcrypt hash and dead session
|
|
226
|
+
tokens.
|
|
227
|
+
- Any browser holding the old `dsh_gateway_session` cookie is signed out by
|
|
228
|
+
that change; the gateway also strips that cookie instead of forwarding it.
|
|
229
|
+
- `DSH_GATEWAY_TTL_MS` is gone (the session lifetime is dsh's
|
|
230
|
+
`cookieMaxAgeDays`, 30 days).
|
|
231
|
+
- Open the sign-in URL printed at the next `dsh web` startup to sign in again.
|
|
232
|
+
|
|
233
|
+
## Configuration
|
|
234
|
+
|
|
235
|
+
All configuration is optional and read from environment variables at boot.
|
|
236
|
+
|
|
237
|
+
| Variable | Default | Meaning |
|
|
238
|
+
| ----------------------- | ------------------------- | ----------------------------------------------------- |
|
|
239
|
+
| `DSH_GATEWAY_HOST` | `127.0.0.1` | Gateway bind host |
|
|
240
|
+
| `DSH_GATEWAY_PORT` | `dsh web port + 1` | Gateway listen port (overrides the default) |
|
|
241
|
+
| `DSH_GATEWAY_DATA_DIR` | `~/.dsh/gateway` | Directory for gateway settings and token |
|
|
242
|
+
| `DSH_GATEWAY_PWA` | `1` | Serve PWA assets and inject PWA tags into HTML |
|
|
243
|
+
| `DSH_GATEWAY_HOST_MODE` | `1` | Declare the page a host-owning page (Host settings) |
|
|
244
|
+
| `DSH_GATEWAY_TOKEN` | generated, persisted | Fixed sign-in token (≥22 base64url chars); see above |
|
|
245
|
+
| `DSH_HOME` | `~/.dsh` | dsh home (used when `DSH_GATEWAY_DATA_DIR` is unset) |
|
|
246
|
+
|
|
247
|
+
### PWA (installable web app)
|
|
248
|
+
|
|
249
|
+
PWA injection is enabled by default. The gateway serves the manifest, service
|
|
250
|
+
worker and `/favicon.svg` itself, and injects the required tags into the 401
|
|
251
|
+
page and proxied HTML responses. Toggle it on the gateway's **Configure** page, or set
|
|
252
|
+
`DSH_GATEWAY_PWA=0` to lock it off from the environment.
|
|
253
|
+
|
|
254
|
+
The service worker uses two caches:
|
|
255
|
+
|
|
256
|
+
- `dsh-gateway-shell-v1` holds the last authenticated HTML document plus the
|
|
257
|
+
manifest and icon. A navigation is network-first; when the network is slower
|
|
258
|
+
than three seconds or unavailable, the cached shell is shown. A successful
|
|
259
|
+
navigation replaces it, so a changed deployment is picked up on the next
|
|
260
|
+
load. A `401` navigation clears the cache.
|
|
261
|
+
- `dsh-gateway-assets-v1` is cache-first for immutable resources:
|
|
262
|
+
Vite's hashed `/assets/*` files and dsh's `/plugins/*?rev=…` bundles. A
|
|
263
|
+
new build produces a new URL, so unchanged resources stay cached while
|
|
264
|
+
changed resources are fetched once. The cache is trimmed to the newest 300
|
|
265
|
+
entries.
|
|
266
|
+
|
|
267
|
+
`/api/*`, `/__dsh_gateway/*`, `/sw.js`, range requests and non-GET requests
|
|
268
|
+
bypass the service worker. Responses that redirect (for example dsh's token
|
|
269
|
+
exchange), fail, or carry `Cache-Control: no-store` are not stored.
|
|
270
|
+
|
|
271
|
+
When PWA is disabled, `/sw.js` serves a cleanup worker that deletes the
|
|
272
|
+
gateway caches and unregisters itself, so an already-installed worker does not
|
|
273
|
+
keep serving an old offline shell.
|
|
274
|
+
|
|
275
|
+
The gateway also adds HTTP cache headers for clients that do not run a service
|
|
276
|
+
worker: hashed assets are
|
|
277
|
+
`Cache-Control: public, max-age=31536000, immutable`, HTML is
|
|
278
|
+
`private, no-cache` (plus `Vary: Cookie`), and `/api/*` is `no-store`.
|
|
279
|
+
|
|
280
|
+
Browser install prompts require a secure context. `http://127.0.0.1:3081` and
|
|
281
|
+
`http://localhost:3081` qualify; an exposed `http://192.168.x.x:3081` LAN URL
|
|
282
|
+
does **not**. For LAN installability, terminate HTTPS in front of the gateway
|
|
283
|
+
with a certificate the browser trusts.
|
|
284
|
+
|
|
285
|
+
### Host mode (settings, Models page)
|
|
286
|
+
|
|
287
|
+
dsh only lets a page read and write Host settings when it believes it is the
|
|
288
|
+
owning host. Its client decides that with
|
|
289
|
+
`ctx.remote.$host.isLoopback`, which is true for a loopback hostname, or when
|
|
290
|
+
the page declares `globalThis.__DSH_TRANSPORT__ = { ownsHost: true }` — the
|
|
291
|
+
same flag the Desktop shell sets.
|
|
292
|
+
|
|
293
|
+
A page served through this gateway is never on a loopback hostname, so without
|
|
294
|
+
that flag dsh falls back to its process-local `memory` settings transport. The
|
|
295
|
+
visible symptom is **Settings → Models: "Loading the provider directory
|
|
296
|
+
failed: settings are unavailable in this browser"**, and no settings change
|
|
297
|
+
survives a reload.
|
|
298
|
+
|
|
299
|
+
Host mode carries the flag two ways:
|
|
300
|
+
|
|
301
|
+
1. **Primary — native index injection.** The plugin pushes a
|
|
302
|
+
`webserver/index-inject` row, so dsh itself renders
|
|
303
|
+
|
|
304
|
+
```html
|
|
305
|
+
<script>globalThis["__DSH_TRANSPORT__"] = {"ownsHost":true}</script>
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
into its own `index.html`. This survives gzip, caching reverse proxies and
|
|
309
|
+
any hop that rewrites or re-serves our responses.
|
|
310
|
+
|
|
311
|
+
2. **Fallback — head rewrite.** The gateway also patches the tag into HTML it
|
|
312
|
+
relays, which keeps working if some deployment serves the page from
|
|
313
|
+
somewhere else.
|
|
314
|
+
|
|
315
|
+
It is **on by default**, because a remote dsh web UI is otherwise unable to
|
|
316
|
+
edit providers. Toggle it on the gateway's **Configure** page, or set
|
|
317
|
+
`DSH_GATEWAY_HOST_MODE=0`. A change requires restarting `dsh web`.
|
|
318
|
+
|
|
319
|
+
Injection needs the upstream HTML uncompressed, so for HTML navigation
|
|
320
|
+
requests only (`Accept: text/html`) the gateway drops `Accept-Encoding`; scripts,
|
|
321
|
+
styles and API payloads keep their compression. The same rewrite path is what
|
|
322
|
+
makes the PWA tags work in a real browser.
|
|
323
|
+
|
|
324
|
+
### Loopback identity for upstream plugins
|
|
325
|
+
|
|
326
|
+
The gateway presents every request to dsh as a local request. This is
|
|
327
|
+
deliberate: dsh's `/api` trust fence and many plugins special-case loopback
|
|
328
|
+
hosts, and a remote HTTPS reverse proxy would otherwise make them reject an
|
|
329
|
+
otherwise valid request.
|
|
330
|
+
|
|
331
|
+
The translation applies to ordinary HTTP and WebSocket upgrades:
|
|
332
|
+
|
|
333
|
+
| Browser sends | Upstream receives |
|
|
334
|
+
| -------------------------------------- | ----------------------------------------- |
|
|
335
|
+
| `Host: dsh.example.com` | `Host: 127.0.0.1:3080` |
|
|
336
|
+
| `Origin: https://dsh.example.com` | `Origin: http://127.0.0.1:3080` |
|
|
337
|
+
| `Referer: https://dsh.example.com/...` | `Referer: http://127.0.0.1:3080/...` |
|
|
338
|
+
|
|
339
|
+
The dsh session cookie is bound to that same rewritten authority, so `/api` RPC
|
|
340
|
+
and WebSocket streams work through the proxy without any extra header
|
|
341
|
+
middleware.
|
|
342
|
+
|
|
343
|
+
This assumes the gateway-to-dsh hop is plain HTTP on loopback, which is what
|
|
344
|
+
`dsh web` serves by default. If you run `dsh web --tls-cert … --tls-key …`, dsh
|
|
345
|
+
binds its cookie to the `https:` audience and a plain-HTTP upstream request
|
|
346
|
+
cannot satisfy it; terminate TLS at the gateway/front proxy instead and leave
|
|
347
|
+
dsh's own listener on HTTP.
|
|
348
|
+
|
|
349
|
+
Because of this, reverse-proxy header middleware is no longer needed. For
|
|
350
|
+
example, a Traefik router can point straight at the gateway and omit the old
|
|
351
|
+
`Host`/`Origin` injection:
|
|
352
|
+
|
|
353
|
+
```yaml
|
|
354
|
+
http:
|
|
355
|
+
routers:
|
|
356
|
+
to-dsh:
|
|
357
|
+
rule: Host(`dsh.example.com`)
|
|
358
|
+
tls:
|
|
359
|
+
certResolver: aliResolver
|
|
360
|
+
service: dsh
|
|
361
|
+
|
|
362
|
+
services:
|
|
363
|
+
dsh:
|
|
364
|
+
loadBalancer:
|
|
365
|
+
servers:
|
|
366
|
+
- url: "http://127.0.0.1:3081"
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
Do **not** apply this translation to a route that bypasses dsh-gateway (for
|
|
370
|
+
example a raw `:3080` route): that would hand any traffic the same local
|
|
371
|
+
identity and skip the cookie check the gateway relies on dsh to perform. Keep
|
|
372
|
+
dsh web bound to loopback and route external traffic only through the gateway.
|
|
373
|
+
|
|
374
|
+
### Exposing through the gateway
|
|
375
|
+
|
|
376
|
+
The dsh web server itself is loopback-only (`--host 0.0.0.0` is rejected by
|
|
377
|
+
dsh web). To expose the UI on the LAN through this gateway, run:
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
DSH_GATEWAY_HOST=0.0.0.0 dsh web
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
No `--trusted-host` flag is needed for proxied requests: the gateway rewrites
|
|
384
|
+
`Host`/`Origin` to the loopback upstream before dsh's Host/Origin fence sees
|
|
385
|
+
them. Keep `--trusted-host` only if something else still reaches dsh directly
|
|
386
|
+
under a non-loopback authority.
|
|
387
|
+
|
|
388
|
+
## Security notes
|
|
389
|
+
|
|
390
|
+
This is intentionally minimal. Understand what the removed password gate used
|
|
391
|
+
to provide:
|
|
392
|
+
|
|
393
|
+
- **The session cookie is a bearer credential, not a per-user account.** Any
|
|
394
|
+
browser holding `dsh-auth-…` is the owner. There is no password, no rate
|
|
395
|
+
limit, and no per-device revocation; revoking means deleting dsh's
|
|
396
|
+
`client-connection/browser-session` credential record and restarting dsh,
|
|
397
|
+
which signs out everyone.
|
|
398
|
+
- **The sign-in token is a long-lived credential in a URL.** Treat the printed
|
|
399
|
+
sign-in URL like a password: keep it out of logs and screenshots, and remember
|
|
400
|
+
that query strings can land in reverse-proxy access logs. Unlike dsh's stock
|
|
401
|
+
per-process token, the gateway's persistent token does **not** rotate on
|
|
402
|
+
restart — a leaked URL stays valid until you rotate it (delete `token.txt` or
|
|
403
|
+
change `DSH_GATEWAY_TOKEN`, then restart). `token.txt` is written with
|
|
404
|
+
owner-only permissions.
|
|
405
|
+
- **Cookies last 30 days.** dsh's `connection.cookieMaxAgeDays` controls that.
|
|
406
|
+
- **Plain HTTP leaks the cookie in transit.** dsh sets `Secure` only on a TLS
|
|
407
|
+
listener; behind a TLS proxy the gateway adds it, but the gateway-to-dsh hop
|
|
408
|
+
is plain HTTP on loopback, so keep it there.
|
|
409
|
+
|
|
410
|
+
**Loopback identity widens the gate.** Every request reaches dsh as if it came
|
|
411
|
+
from the local machine. Only dsh's cookie separates a remote browser from
|
|
412
|
+
host-local plugin surfaces, so keep the gateway itself behind HTTPS and do not
|
|
413
|
+
expose dsh's raw port.
|
|
414
|
+
|
|
415
|
+
**Host mode widens that gate.** `ownsHost: true` gives every signed-in browser
|
|
416
|
+
the same configuration surface the Desktop shell has: editing settings (which
|
|
417
|
+
writes `cordis.patch.yml`), the "open configuration file" action, and
|
|
418
|
+
installing or enabling plugin bundles. Since a plugin bundle is code the Host
|
|
419
|
+
loads, anyone who can sign in can effectively run code on this machine. Keep
|
|
420
|
+
Host mode on only where everyone who can obtain the sign-in URL is trusted to
|
|
421
|
+
do that, and turn it off on the gateway's **Configure** page (or with
|
|
422
|
+
`DSH_GATEWAY_HOST_MODE=0`) otherwise.
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# yaml-language-server: $schema=../../schemas/cordis-patch.schema.json
|
|
2
|
+
|
|
3
|
+
# dsh-gateway bundle patch.
|
|
4
|
+
#
|
|
5
|
+
# Adds one gateway row beside the dsh web server: a reverse proxy that relays
|
|
6
|
+
# dsh's own token authentication and also delivers the installable PWA shell and
|
|
7
|
+
# Host-mode transport declaration. One row means one lifecycle and one switch on
|
|
8
|
+
# the Plugins page.
|
|
9
|
+
#
|
|
10
|
+
# `connection` is optional: without the browser transport the gateway still
|
|
11
|
+
# proxies, it just cannot print a tokenized sign-in URL.
|
|
12
|
+
- insert:
|
|
13
|
+
- id: gateway
|
|
14
|
+
name: '@gitsang/dsh-gateway'
|
|
15
|
+
inject: [webServer]
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitsang/dsh-gateway",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "An installable gateway for the dsh web UI: reverse proxy on dsh token authentication, PWA delivery and Host-mode injection.",
|
|
4
|
+
"version": "0.5.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node --test"
|
|
8
|
+
},
|
|
9
|
+
"main": "src/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.js",
|
|
12
|
+
"./client": "./src/client.js",
|
|
13
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src",
|
|
18
|
+
"cordis.patch.yml",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"dsh",
|
|
25
|
+
"deepseek-harness",
|
|
26
|
+
"dsh-plugin",
|
|
27
|
+
"gateway",
|
|
28
|
+
"reverse-proxy",
|
|
29
|
+
"pwa"
|
|
30
|
+
],
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/gitsang/dsh-gateway.git"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/gitsang/dsh-gateway#readme",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/gitsang/dsh-gateway/issues"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"dsh": {
|
|
43
|
+
"bundle": {
|
|
44
|
+
"patch": "./cordis.patch.yml"
|
|
45
|
+
},
|
|
46
|
+
"client": {
|
|
47
|
+
"platform": "web",
|
|
48
|
+
"inject": [
|
|
49
|
+
"@deepseek-ai/dsh-client-locale",
|
|
50
|
+
"@deepseek-ai/dsh-client-ui-primitives",
|
|
51
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
58
|
+
"@deepseek-ai/schemastery": "^3.18.1",
|
|
59
|
+
"react": "^18.2.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
63
|
+
"@deepseek-ai/schemastery": "^3.18.1"
|
|
64
|
+
}
|
|
65
|
+
}
|