@goodandready/dsh-cron 0.3.39 → 0.3.40

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.
@@ -109,7 +109,6 @@ export class LogStreamer extends EventEmitter {
109
109
  'Cache-Control': 'no-cache, no-transform',
110
110
  'Connection': 'keep-alive',
111
111
  'X-Accel-Buffering': 'no',
112
- 'Access-Control-Allow-Origin': '*',
113
112
  });
114
113
 
115
114
  const entry = this.streams.get(taskId);
@@ -38,7 +38,7 @@ export async function handleTaskCollection({ store, scheduler, collection, req,
38
38
  return;
39
39
  }
40
40
  if (req.method === 'POST') {
41
- await createOrUpdateTask({ store, scheduler, req, res, apiToken, ctx: undefined });
41
+ await createOrUpdateTask({ store, scheduler, req, res, apiToken, ctx });
42
42
  return;
43
43
  }
44
44
  sendJson(res, 405, NOT_ALLOWED);
@@ -21,12 +21,12 @@ export async function handleTaskItem({ store, scheduler, req, res, url, id, acti
21
21
  }
22
22
 
23
23
  if (req.method === 'GET') {
24
- // Both /dsh-cron/tasks/:id/stream and /dsh-cron/tasks/:id/logs/stream (#392)
24
+ if (rejectCrossOrigin(req, res, { apiToken, ctx })) return;
25
+ // Both /dsh-cron/tasks/:id/stream and /dsh-cron/tasks/:id/logs/stream (#392, #424)
25
26
  if (action === 'stream' || (action === 'logs' && subAction === 'stream')) {
26
27
  logStreamer.handleSseRequest(id, req, res);
27
28
  return;
28
29
  }
29
- if (rejectCrossOrigin(req, res, { apiToken, ctx })) return;
30
30
  if (action === 'archive') {
31
31
  const limit = parseInt(url.searchParams.get('limit') || '50', 10);
32
32
  const offset = parseInt(url.searchParams.get('offset') || '0', 10);
@@ -33,6 +33,9 @@ export function registerRoutes(ctx, { store, scheduler, recommendations }) {
33
33
  res.end('GET only');
34
34
  return;
35
35
  }
36
+ const settings = store && typeof store.getSettings === 'function' ? store.getSettings() : {};
37
+ const apiToken = settings.apiToken;
38
+ if (rejectCrossOrigin(req, res, { apiToken, ctx })) return;
36
39
  res.writeHead(200, {
37
40
  'content-type': 'application/json; charset=utf-8',
38
41
  'cache-control': 'no-store',
@@ -52,6 +55,9 @@ export function registerRoutes(ctx, { store, scheduler, recommendations }) {
52
55
  res.end('GET only');
53
56
  return;
54
57
  }
58
+ const settings = store && typeof store.getSettings === 'function' ? store.getSettings() : {};
59
+ const apiToken = settings.apiToken;
60
+ if (rejectCrossOrigin(req, res, { apiToken, ctx })) return;
55
61
  const url = new URL(req.url, 'http://127.0.0.1');
56
62
  const month = url.pathname.replace(/^\/dsh-cron\/history\/archive\//, '').replace(/\/$/, '');
57
63
  if (!/^\d{4}-\d{2}$/.test(month)) {
@@ -67,7 +73,7 @@ export function registerRoutes(ctx, { store, scheduler, recommendations }) {
67
73
  }
68
74
  res.writeHead(200, {
69
75
  'content-type': 'application/json; charset=utf-8',
70
- 'cache-control': 'public, max-age=3600',
76
+ 'cache-control': 'no-store',
71
77
  });
72
78
  res.end(JSON.stringify({ ok: true, month, archive }));
73
79
  }
@@ -90,6 +90,24 @@ export function buildPythonInvocation(task, cwd) {
90
90
  return { file: interpreter, args: ['-c', String(task.prompt || '')] };
91
91
  }
92
92
 
93
+ /** #427: Validate hostnames against cloud provider metadata and link-local IP addresses. */
94
+ export function isCloudMetadataHost(hostname) {
95
+ if (!hostname || typeof hostname !== 'string') return false;
96
+ const h = hostname.toLowerCase().replace(/^\[|\]$/g, '');
97
+ if (
98
+ h === '169.254.169.254' ||
99
+ h.startsWith('169.254.') ||
100
+ h === '100.100.100.200' ||
101
+ h === 'fd00:ec2::254' ||
102
+ h === 'metadata.google.internal' ||
103
+ h === 'metadata.azure.com' ||
104
+ h.endsWith('.internal.cloudapp.net')
105
+ ) {
106
+ return true;
107
+ }
108
+ return false;
109
+ }
110
+
93
111
  /** #7: build the HTTP trigger request description. */
94
112
  export function buildHttpRequest(task) {
95
113
  const raw = String(task.httpUrl || task.prompt || '').trim();
@@ -101,12 +119,7 @@ export function buildHttpRequest(task) {
101
119
  throw new Error(`Invalid HTTP URL: ${raw}`);
102
120
  }
103
121
  const hostname = url.hostname.toLowerCase();
104
- if (
105
- hostname === '169.254.169.254' ||
106
- hostname === 'metadata.google.internal' ||
107
- hostname === 'metadata.azure.com' ||
108
- hostname.endsWith('.internal.cloudapp.net')
109
- ) {
122
+ if (isCloudMetadataHost(hostname)) {
110
123
  throw new Error(`Access to cloud metadata endpoint "${hostname}" is restricted`);
111
124
  }
112
125
  let headers = {};
@@ -1,3 +1,4 @@
1
+ import { isCloudMetadataHost } from '../runtimes/runtimes.js';
1
2
  import { collectDigestMetrics, formatDigestReport } from '../digest.js';
2
3
  import { exec } from 'node:child_process';
3
4
  import fs from 'node:fs';
@@ -42,7 +43,7 @@ export async function executePreflight(task) {
42
43
  try {
43
44
  const u = new URL(target);
44
45
  const host = u.hostname.toLowerCase();
45
- if (host === '169.254.169.254' || host === 'metadata.google.internal' || host === 'metadata.azure.com') {
46
+ if (isCloudMetadataHost(host)) {
46
47
  return { ok: false, reason: `HTTP check to cloud metadata endpoint "${host}" is restricted` };
47
48
  }
48
49
  } catch (_e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-cron",
3
- "version": "0.3.39",
3
+ "version": "0.3.40",
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",