@goodandready/dsh-cron 0.3.28 → 0.3.30

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.
@@ -227,6 +227,7 @@
227
227
  }
228
228
  try {
229
229
  const res = await fetch(url, {
230
+ credentials: 'same-origin',
230
231
  ...options,
231
232
  signal: controller ? controller.signal : (options ? options.signal : undefined),
232
233
  });
@@ -323,7 +323,7 @@
323
323
  });
324
324
  const data = await res.json();
325
325
  if (gen !== fetchGenRef.current) return;
326
- if (data && data.ok) {
326
+ if (data && data.ok !== false) {
327
327
  setTasks(data.tasks || []);
328
328
  setRecs(data.recommendations || []);
329
329
  setStats(data.stats || null);
package/lib/client.js CHANGED
@@ -769,6 +769,7 @@ options.signal.addEventListener('abort', () => controller.abort(), { once: true
769
769
  }
770
770
  try {
771
771
  const res = await fetch(url, {
772
+ credentials: 'same-origin',
772
773
  ...options,
773
774
  signal: controller ? controller.signal : (options ? options.signal : undefined),
774
775
  });
@@ -1829,7 +1830,7 @@ signal: controller ? controller.signal : undefined,
1829
1830
  });
1830
1831
  const data = await res.json();
1831
1832
  if (gen !== fetchGenRef.current) return;
1832
- if (data && data.ok) {
1833
+ if (data && data.ok !== false) {
1833
1834
  setTasks(data.tasks || []);
1834
1835
  setRecs(data.recommendations || []);
1835
1836
  setStats(data.stats || null);
package/lib/http-utils.js CHANGED
@@ -121,6 +121,70 @@ export function getDshConnection(req, options = {}) {
121
121
  * Requests with missing socket / missing remoteAddress and no token are rejected (401).
122
122
  * 5. Origin and Sec-Fetch-Site: cannot be null, Origin host must match Host, Sec-Fetch-Site must be same-origin or none.
123
123
  */
124
+
125
+ /**
126
+ * Check if request contains non-loopback forwarding headers (e.g. proxied from LAN/Tailscale) (#371, GH #20).
127
+ */
128
+ export function hasNonLoopbackForwarding(req) {
129
+ const xff = req?.headers?.['x-forwarded-for'];
130
+ if (xff && typeof xff === 'string') {
131
+ const ips = xff.split(',').map((s) => s.trim());
132
+ if (ips.some((ip) => ip && !isLoopbackAddress(ip))) return true;
133
+ }
134
+ const xRealIp = req?.headers?.['x-real-ip'];
135
+ if (xRealIp && typeof xRealIp === 'string' && !isLoopbackAddress(xRealIp.trim())) {
136
+ return true;
137
+ }
138
+ return false;
139
+ }
140
+
141
+ /**
142
+ * Check whether an incoming HTTP request carries a DeepSeek Harness session cookie (#295, GH #20).
143
+ * DSH core sets 'dsh-auth-<hash>=v1...' as a SameSite=Strict HttpOnly cookie.
144
+ */
145
+ export function hasDshAuthCookie(req) {
146
+ if (!req || !req.headers) return false;
147
+ const cookie = String(req.headers.cookie || '');
148
+ return cookie.includes('dsh-auth-');
149
+ }
150
+
151
+ /**
152
+ * Check whether an incoming HTTP request originates from an authentic local Desktop shell (GH #20).
153
+ * Verified against local loopback socket, absence of external proxy forwarding, and
154
+ * authentic Desktop shell signatures (UA @deepseek-ai/dsh-desktop/ or dsh-desktop,
155
+ * dsh-auth- cookie, host 'app', or internal auth headers).
156
+ */
157
+ export function isDesktopShellRequest(req) {
158
+ if (!req || !req.headers) return false;
159
+ if (hasNonLoopbackForwarding(req)) return false;
160
+
161
+ const remote = req.socket?.remoteAddress || req.connection?.remoteAddress || '';
162
+ if (!isLoopbackAddress(remote)) return false;
163
+
164
+ const agent = String(req.headers['user-agent'] || '');
165
+ const cookie = String(req.headers.cookie || '');
166
+ const host = String(req.headers.host || '').trim().toLowerCase().split(':')[0];
167
+
168
+ // 1. Desktop shell User-Agent and/or session cookie
169
+ if (agent.includes('@deepseek-ai/dsh-desktop/') || agent.includes('dsh-desktop') || agent.includes('electron')) {
170
+ return true;
171
+ }
172
+ if (hasDshAuthCookie(req)) {
173
+ return true;
174
+ }
175
+
176
+ // 2. Custom desktop scheme Host or explicit desktop internal auth headers
177
+ if (host === 'app') {
178
+ return true;
179
+ }
180
+ const internalAuth = req.headers['x-dsh-internal-auth'] || req.headers['x-dsh-desktop'];
181
+ if (internalAuth === 'true' || internalAuth === '1') {
182
+ return true;
183
+ }
184
+
185
+ return false;
186
+ }
187
+
124
188
  export function getRequestRejection(req, options = {}) {
125
189
  if (!req) return 403;
126
190
 
@@ -151,17 +215,23 @@ export function getRequestRejection(req, options = {}) {
151
215
 
152
216
  // 3. Validate Origin header if present: cannot be null, host must match Host (CSRF guard)
153
217
  if (origin !== undefined) {
154
- if (origin === 'null' || !origin) return 403;
155
- try {
156
- const parsed = new URL(origin);
157
- if (parsed.protocol === 'dsh-app:') {
158
- const appHost = parsed.host.toLowerCase();
159
- if (appHost && appHost !== 'app' && appHost !== 'localhost') return 403;
160
- } else {
161
- if (!parsed.host || !host || parsed.host.toLowerCase() !== host.toLowerCase()) return 403;
162
- }
163
- } catch {
218
+ if (origin === 'null') {
219
+ if (!isDesktopShellRequest(req)) return 403;
220
+ } else if (!origin) {
164
221
  return 403;
222
+ } else {
223
+ try {
224
+ const parsed = new URL(origin);
225
+ if (parsed.protocol === 'dsh-app:') {
226
+ const appHost = parsed.host.toLowerCase();
227
+ if (appHost && appHost !== 'app' && appHost !== 'localhost') return 403;
228
+ if (hasNonLoopbackForwarding(req)) return 403;
229
+ } else {
230
+ if (!parsed.host || !host || parsed.host.toLowerCase() !== host.toLowerCase()) return 403;
231
+ }
232
+ } catch {
233
+ return 403;
234
+ }
165
235
  }
166
236
  }
167
237
 
@@ -202,11 +272,15 @@ export function getRequestRejection(req, options = {}) {
202
272
  const isTasksRead = !isMutating && (urlStr === '/dsh-cron/tasks' || urlStr.startsWith('/dsh-cron/tasks?') || urlStr === '/tasks' || urlStr.startsWith('/tasks?'));
203
273
 
204
274
  const hostStr = host.toLowerCase().split(':')[0];
205
- const isLoopbackHost = hostStr === '' || hostStr === 'localhost' || hostStr === '127.0.0.1' || hostStr === '::1';
275
+ const isLoopbackHost = hostStr === '' || hostStr === 'localhost' || hostStr === '127.0.0.1' || hostStr === '::1' || hostStr === 'app';
206
276
  const requireSource = Boolean(options.requireSource || isMutating || (isTasksRead && !isLoopbackHost));
207
277
 
208
278
  if (requireSource) {
209
279
  if (!origin && !referer) {
280
+ // GH #20: Allow authentic local Desktop shell requests lacking Origin/Referer
281
+ if (isDesktopShellRequest(req)) {
282
+ return undefined; // Admitted Desktop shell
283
+ }
210
284
  return 403;
211
285
  }
212
286
  if (!origin && referer) {
@@ -215,6 +289,7 @@ export function getRequestRejection(req, options = {}) {
215
289
  if (parsedRef.protocol === 'dsh-app:') {
216
290
  const appHost = parsedRef.host.toLowerCase();
217
291
  if (appHost && appHost !== 'app' && appHost !== 'localhost') return 403;
292
+ if (hasNonLoopbackForwarding(req)) return 403;
218
293
  } else {
219
294
  if (!parsedRef.host || !host || parsedRef.host.toLowerCase() !== host.toLowerCase()) {
220
295
  return 403;
@@ -23,7 +23,7 @@ export async function getModelsHandler(ctx, req, res, sendJson) {
23
23
  const url = new URL(req.url, 'http://127.0.0.1');
24
24
  const wanted = url.searchParams.get('provider') || '';
25
25
  if (wanted === '') {
26
- sendJson(res, 200, { current, providers, models: [] });
26
+ sendJson(res, 200, { ok: true, current, providers, models: [] });
27
27
  return;
28
28
  }
29
29
 
@@ -34,11 +34,12 @@ export async function getModelsHandler(ctx, req, res, sendJson) {
34
34
  rows = await llm.listModels(wanted);
35
35
  }
36
36
  sendJson(res, 200, {
37
+ ok: true,
37
38
  current,
38
39
  providers,
39
40
  models: (rows ?? []).map((m) => ({ id: m.id, name: m.name ?? m.id })),
40
41
  });
41
42
  } catch {
42
- sendJson(res, 200, { current, providers, models: [] });
43
+ sendJson(res, 200, { ok: true, current, providers, models: [] });
43
44
  }
44
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-cron",
3
- "version": "0.3.28",
3
+ "version": "0.3.30",
4
4
  "description": "Background automation runner for DSH: isolated agent runs, script/HTTP/SSH/Docker runtimes, cost guard, notifications, heartbeats.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",