@goodandready/dsh-cron 0.3.37 → 0.3.38

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/README.md CHANGED
@@ -728,3 +728,7 @@ Git-managed tasks are isolated with zero interference to manual GUI tasks.
728
728
  Control scheduled workflows directly within active DSH chat sessions (`conversation.session.header.actions`):
729
729
  - **Turn into Recurring Task (`+ Cron`)**: Turn any ongoing discussion or prompt into an automated recurring schedule with pre-populated parameters.
730
730
  - **Live Status & Run Now**: View associated task execution status directly in the conversation header and trigger immediate runs with a single click.
731
+
732
+ ### Security & Safe Execution
733
+ - **Hardened Path Validation**: Wake trigger markers and file watchers strictly disallow access to system directories (`/etc`, `/proc`, `/sys`, `C:\Windows`).
734
+ - **SSRF Guard**: Automated blocking of cloud metadata endpoints (`169.254.169.254`).
package/README.ru.md CHANGED
@@ -682,3 +682,7 @@ tasks:
682
682
  Управляйте регламентными задачами прямо из активного диалога DSH (`conversation.session.header.actions`):
683
683
  - **Превращение сессии в регламентную задачу (`+ В крон`)**: сохраняйте текущий диалог или промпт как регулярную задачу с предзаполненными параметрами в один клик.
684
684
  - **Индикация статуса и быстрый запуск**: отслеживайте статус выполнения привязанных к сессии фоновых задач и запускайте их немедленно прямо из заголовка чата.
685
+
686
+ ### Безопасность и защита системы
687
+ - **Строгая валидация путей**: Триггеры пробуждения блокируют доступ к системным директориям (`/etc`, `/proc`, `/sys`, `C:\Windows`).
688
+ - **Защита от SSRF**: Блокировка запросов к link-local адресам облачных метаданных (`169.254.169.254`).
package/README.zh.md CHANGED
@@ -675,3 +675,7 @@ Git 管理的任务具有隔离标识,绝不影响或覆盖 UI 手动创建的
675
675
  在 DSH 活跃聊天会话中直接管理定时任务(`conversation.session.header.actions`):
676
676
  - **一键转为定时任务(`+ 定时任务`)**:将当前对话或提示词一键转换为预填参数的定时周期任务。
677
677
  - **关联任务状态与即时触发**:在会话顶部直接显示关联后台任务的执行状态,并支持一键立即执行。
678
+
679
+ ### 安全性与安全执行
680
+ - **强化路径验证**:事件唤醒触发器严格禁止访问敏感系统路径(`/etc`、`/proc`、`/sys`、`C:\Windows`)。
681
+ - **SSRF 防护**:自动拦截对云平台元数据地址(`169.254.169.254`)的请求。
@@ -109,6 +109,9 @@ export function reconcileWorkspaceCronTasks(store, workspaceId, declaredTasks =
109
109
  const taskId = `cac_${workspaceId}_${rawId}`.replace(/[^a-zA-Z0-9_-]/g, '_');
110
110
  seenIds.add(taskId);
111
111
 
112
+ const taskType = decl.type || (decl.command ? 'script' : 'llm');
113
+ const taskPrompt = decl.prompt !== undefined ? decl.prompt : (decl.command || '');
114
+
112
115
  const taskRecord = {
113
116
  ...decl,
114
117
  id: taskId,
@@ -118,7 +121,8 @@ export function reconcileWorkspaceCronTasks(store, workspaceId, declaredTasks =
118
121
  workspaceId,
119
122
  managedBy: 'cron_as_code',
120
123
  origin: '.dsh/cron.yaml',
121
- type: decl.type || 'script',
124
+ type: taskType,
125
+ prompt: taskPrompt,
122
126
  };
123
127
 
124
128
  if (existingManaged.has(taskId)) {
@@ -100,6 +100,15 @@ export function buildHttpRequest(task) {
100
100
  } catch {
101
101
  throw new Error(`Invalid HTTP URL: ${raw}`);
102
102
  }
103
+ 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
+ ) {
110
+ throw new Error(`Access to cloud metadata endpoint "${hostname}" is restricted`);
111
+ }
103
112
  let headers = {};
104
113
  if (task.httpHeaders) {
105
114
  if (typeof task.httpHeaders === 'object') {
@@ -39,6 +39,15 @@ export async function executePreflight(task) {
39
39
  if (type === 'http') {
40
40
  let timeout;
41
41
  try {
42
+ try {
43
+ const u = new URL(target);
44
+ const host = u.hostname.toLowerCase();
45
+ if (host === '169.254.169.254' || host === 'metadata.google.internal' || host === 'metadata.azure.com') {
46
+ return { ok: false, reason: `HTTP check to cloud metadata endpoint "${host}" is restricted` };
47
+ }
48
+ } catch (_e) {
49
+ void _e;
50
+ }
42
51
  const controller = new AbortController();
43
52
  timeout = setTimeout(() => controller.abort(), 5000);
44
53
  const res = await fetch(target, { signal: controller.signal });
@@ -4,7 +4,6 @@ import { logger } from './logger.js';
4
4
  import { bestEffort } from './best-effort.js';
5
5
 
6
6
  const DISALLOWED_ROOTS = [
7
- '/',
8
7
  '/proc',
9
8
  '/sys',
10
9
  '/dev',
@@ -12,7 +11,6 @@ const DISALLOWED_ROOTS = [
12
11
  '/boot',
13
12
  '/run',
14
13
  '/var/run',
15
- 'c:\\',
16
14
  'c:\\windows',
17
15
  'c:\\windows\\system32',
18
16
  'c:\\program files',
@@ -27,22 +25,36 @@ export function isSafeWakePath(targetPath) {
27
25
  return { safe: false, error: 'Path must be a non-empty string' };
28
26
  }
29
27
  const trimmed = targetPath.trim();
30
- if (trimmed.includes('\0')) {
28
+ if (trimmed.indexOf('\0') !== -1) {
31
29
  return { safe: false, error: 'Path must not contain null bytes' };
32
30
  }
33
- const resolved = path.resolve(trimmed);
34
- const lower = resolved.toLowerCase();
35
-
36
- for (const root of DISALLOWED_ROOTS) {
37
- if (lower === root || lower === root.replace(/\\/g, '/')) {
38
- return { safe: false, error: `Path "${resolved}" targets a disallowed system root directory` };
39
- }
31
+ const rawLower = trimmed.toLowerCase().split('\\').join('/');
32
+ if (
33
+ rawLower === 'c:' ||
34
+ rawLower === 'c:/' ||
35
+ rawLower.startsWith('c:/windows') ||
36
+ rawLower.startsWith('c:/program files')
37
+ ) {
38
+ return { safe: false, error: `Path "${targetPath}" targets a disallowed system location` };
40
39
  }
41
40
 
41
+ const resolved = path.resolve(trimmed);
42
+
43
+ // Filesystem root check ('/' on POSIX, 'C:\' on Windows)
42
44
  if (resolved === path.parse(resolved).root) {
43
45
  return { safe: false, error: `Path "${resolved}" is a filesystem root` };
44
46
  }
45
47
 
48
+ const lower = resolved.toLowerCase().split('\\').join('/');
49
+
50
+ for (const root of DISALLOWED_ROOTS) {
51
+ const normRoot = root.toLowerCase().split('\\').join('/');
52
+ const rootWithSlash = normRoot.endsWith('/') ? normRoot : normRoot + '/';
53
+ if (lower === normRoot || lower.startsWith(rootWithSlash)) {
54
+ return { safe: false, error: `Path "${resolved}" targets a disallowed system location` };
55
+ }
56
+ }
57
+
46
58
  return { safe: true, resolved };
47
59
  }
48
60
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-cron",
3
- "version": "0.3.37",
3
+ "version": "0.3.38",
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",