Safer workflow conditions; Pulse is admin-only
CI / UI screenshots (before/after) (push) Skipped
CI / Lint (eslint) (push) Successful in 25s
CI / Test (jest) (push) Successful in 25s
CI / Security (npm audit) (push) Successful in 21s
CI / Scan (secrets, workflows, shell) (push) Successful in 2m0s
CI / Integration (api) (push) Successful in 2m23s
CI / Lint (eslint) (pull_request) Successful in 24s
CI / Test (jest) (pull_request) Successful in 32s
CI / Security (npm audit) (pull_request) Successful in 39s
CI / UI (playwright) (push) Successful in 2m6s
CI / Deploy (push) Skipped
CI / Deploy worker (push) Skipped
CI / Notify (push) Skipped
CI / Integration (api) (pull_request) Successful in 2m13s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 2m46s
CI / UI screenshots (before/after) (pull_request) Successful in 27s
CI / UI (playwright) (pull_request) Successful in 3m5s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped

- Workflow conditions (step.condition and route `if`) are now parsed and
  interpreted by lib/condition.js instead of being run with Node's vm
  module. The language covers what workflows use: state/params lookups,
  parseInt/parseFloat/Number/String/Boolean, a few string methods, the
  usual operators with JavaScript semantics. Conditions can only read the
  workflow's own data. Every condition in the production workflows gives
  the same result as before (differential test, 150 random states each).
- Creating and updating a workflow rejects conditions that don't parse
  (400 with the step and the error).
- Creating a workflow requires admin, like editing already did.
- Only the admin group may use Pulse (pages, API and live WebSocket);
  employees get 403. Gandalf and workers use API keys and are unaffected.
- The live-update UI test finds its execution's row by id instead of
  counting rows (the list is capped at 50).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-22 22:05:42 -05:00
1 parent f5a4333a8e
commit 040ad028c0
10 files changed
+453 -20

No files matched your search

+31 -6
View File
@@ -1,4 +1,5 @@
'use strict';
const { evaluateCondition, checkCondition } = require('./condition');
/**
* Validate a webhook URL.
@@ -43,20 +44,44 @@ function applyParams(command, params) {
}
/**
* Evaluate a condition expression safely using vm.runInNewContext.
* Returns boolean (false on error).
* Evaluate a workflow condition with the safe interpreter in lib/condition.js (no vm,
* no JavaScript engine). Returns a boolean; a condition that can't be parsed or
* evaluated counts as false.
*/
function evalCondition(condition, state, params) {
const vm = require('vm');
try {
const context = vm.createContext({ state, params, promptResponse: state.promptResponse });
return !!vm.runInNewContext(condition, context, { timeout: 100 });
return evaluateCondition(condition, state, params);
} catch (e) {
console.warn(`[Workflow] evalCondition error (treated as false): ${e.message} (condition: ${condition})`);
return false;
}
}
/**
* Every condition in a workflow definition that doesn't parse, as
* [{ step, condition, error }]. Used to reject bad definitions when they are saved.
*/
function conditionErrors(definition) {
const problems = [];
let def = definition;
if (typeof def === 'string') {
try { def = JSON.parse(def); } catch { return problems; } // JSON errors are reported elsewhere
}
const steps = (def && Array.isArray(def.steps)) ? def.steps : [];
steps.forEach((step, i) => {
const label = (step && (step.id || step.name)) || `step ${i + 1}`;
const exprs = [];
if (step && step.condition) exprs.push(step.condition);
for (const c of (step && Array.isArray(step.conditions) ? step.conditions : [])) {
if (c && !c.default && c.if) exprs.push(c.if);
}
for (const expr of exprs) {
try { checkCondition(expr); } catch (e) { problems.push({ step: label, condition: expr, error: e.message }); }
}
});
return problems;
}
/**
* Calculate the next run date for a scheduled command.
*/
@@ -87,4 +112,4 @@ function calculateNextRun(scheduleType, scheduleValue) {
throw new Error(`Unknown schedule type: ${scheduleType}`);
}
module.exports = { validateWebhookUrl, applyParams, evalCondition, calculateNextRun };
module.exports = { validateWebhookUrl, applyParams, evalCondition, conditionErrors, calculateNextRun };