@riceawa/dsh-lan-gateway 0.4.0 → 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/lib/index.d.ts CHANGED
@@ -16,9 +16,15 @@ interface WebServerSurface {
16
16
  handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
17
17
  }): () => void;
18
18
  }
19
+ /** Minimal surface of the dsh client-connection service (session-capable bases). */
20
+ interface UpstreamConnectionSurface {
21
+ /** A root URL for the upstream origin carrying the process launch token. */
22
+ authenticatedUrl(baseUrl: string): string;
23
+ }
19
24
  declare module '@deepseek-ai/cordis' {
20
25
  interface Context {
21
26
  webServer: WebServerSurface;
27
+ connection: UpstreamConnectionSurface;
22
28
  }
23
29
  }
24
30
  /** One command result returned to the model. */
@@ -31,7 +37,7 @@ interface GatewayController {
31
37
  status(): ToolResult;
32
38
  enable(): Promise<ToolResult>;
33
39
  disable(): Promise<ToolResult>;
34
- setPassword(password: string | undefined): ToolResult;
40
+ setPassword(password: string | undefined): Promise<ToolResult>;
35
41
  rotateSecret(): ToolResult;
36
42
  regenerateTls(): Promise<ToolResult>;
37
43
  }
@@ -43,10 +49,20 @@ interface Config {
43
49
  gatewayPort: number;
44
50
  /** Explicit dsh target port; defaults to the live `ctx.webServer.port`. */
45
51
  dshTargetPort?: number;
46
- /** LAN CIDRs treated as password-free. */
52
+ /** LAN CIDRs that may be treated as trusted when `lanPasswordless` is on. */
47
53
  lanCidrs: string[];
48
- /** Whether non-LAN sources must authenticate. */
49
- authRequired: boolean;
54
+ /**
55
+ * Opt-in (default false): let LAN/loopback sources skip the gateway login.
56
+ * Only allowed against a session-capable dsh base, where upstream auth still
57
+ * gates every request via the relayed shared session.
58
+ */
59
+ lanPasswordless: boolean;
60
+ /**
61
+ * Removed capability: authentication is always required. Retained only so an
62
+ * explicit legacy `authRequired: false` is rejected loudly instead of
63
+ * silently ignored.
64
+ */
65
+ authRequired?: boolean;
50
66
  /** Session cookie lifetime in days. */
51
67
  cookieMaxAgeDays: number;
52
68
  /** Cookie name. */
@@ -63,9 +79,40 @@ interface Config {
63
79
  tlsSelfSignedHosts?: string;
64
80
  /** Self-signed certificate validity in days (default 825 ≈ 27 months). */
65
81
  tlsCertMaxAgeDays: number;
82
+ /**
83
+ * Escape hatch (default false): permit plaintext HTTP. Never derived from
84
+ * `X-Forwarded-Proto` — the operator declares it.
85
+ */
86
+ allowInsecurePlaintext: boolean;
87
+ /**
88
+ * An identifier for a trusted TLS-terminating proxy in front of the gateway.
89
+ * Declaring one marks the ingress encrypted (Secure cookies, passes the
90
+ * encrypted-ingress gate) without this listener sending HSTS.
91
+ */
92
+ trustedTerminator?: string;
66
93
  }
67
94
  /** Schemastery configuration validated by the Loader. */
68
95
  declare const Config: z<Config>;
96
+ /** Facts the fail-closed start guard needs to judge a config. */
97
+ interface StartFacts {
98
+ /** Whether the dsh base enforces browser-session auth (auto-detected). */
99
+ upstreamSessionAvailable: boolean;
100
+ }
101
+ /**
102
+ * The fail-closed problems that prevent a config from enabling the listener.
103
+ * Returns every problem (not just the first) so the operator sees the full
104
+ * migration at once. Exported for tests.
105
+ */
106
+ declare function gatewayStartProblems(cfg: Config, facts: StartFacts): string[];
107
+ /**
108
+ * Same-origin loopback fence for the native `/lan-gateway/config` route. The
109
+ * gateway refuses to relay this prefix, so the only way in is the native
110
+ * loopback listener itself (a genuine local user, or a local process that could
111
+ * already read `~/.dsh`). Host must be loopback (also blocks DNS rebinding),
112
+ * cross-site fetches are refused, an Origin must match the Host the browser
113
+ * used, and a state-changing method must carry that Origin. Exported for tests.
114
+ */
115
+ declare function isTrustedConfigRequest(req: IncomingMessage): boolean;
69
116
  declare function apply(ctx: Context, config: Config): void;
70
117
  //#endregion
71
- export { Config, GatewayController, ToolResult, WebServerSurface, apply, inject, name };
118
+ export { Config, GatewayController, StartFacts, ToolResult, UpstreamConnectionSurface, WebServerSurface, apply, gatewayStartProblems, inject, isTrustedConfigRequest, name };