Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d96028070 | ||
|
|
c890d5c078 | ||
|
|
72933df47a | ||
|
|
bf7e91cc57 |
No files matched your search
@@ -144,10 +144,13 @@ jobs:
|
||||
run: |
|
||||
apt-get install -y -qq --no-install-recommends python3-venv >/dev/null
|
||||
python3 -m venv /tmp/semgrep && /tmp/semgrep/bin/pip install -q semgrep==1.184.0
|
||||
# Pulse's own rules must still catch their test cases before they're trusted.
|
||||
/tmp/semgrep/bin/semgrep --metrics=off --test --config .semgrep/pulse.yml .semgrep/pulse.js
|
||||
/tmp/semgrep/bin/semgrep scan --metrics=off --error \
|
||||
--config .semgrep/pulse.yml \
|
||||
--config p/javascript --config p/nodejs --config p/expressjs \
|
||||
--config p/secrets --config p/security-audit \
|
||||
--exclude public/web_template --exclude node_modules
|
||||
--exclude public/web_template --exclude node_modules --exclude .semgrep/pulse.js
|
||||
|
||||
ui:
|
||||
name: UI (playwright)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/* Test cases for .semgrep/pulse.yml (semgrep --test .semgrep). Not loaded by Pulse. */
|
||||
/* eslint-disable */
|
||||
|
||||
function render(el, w, rows, keep) {
|
||||
// ruleid: pulse-innerhtml-unescaped
|
||||
el.innerHTML = '<b>' + w.name + '</b>';
|
||||
// ruleid: pulse-innerhtml-unescaped
|
||||
el.innerHTML = rows.map(r => '<td>' + r.host + '</td>').join('');
|
||||
// ruleid: pulse-innerhtml-unescaped
|
||||
el.innerHTML += `<i>${w.note}</i>`;
|
||||
// ok: pulse-innerhtml-unescaped
|
||||
el.innerHTML = '<b>' + esc(w.name) + '</b>';
|
||||
// ok: pulse-innerhtml-unescaped
|
||||
el.innerHTML = '<b>' + Pulse.esc(w.name) + '</b>';
|
||||
// ok: pulse-innerhtml-unescaped
|
||||
el.innerHTML = '<a href="/x?id=' + encodeURIComponent(w.id) + '">x</a>';
|
||||
// ok: pulse-innerhtml-unescaped
|
||||
el.innerHTML = '<span class="' + Pulse.fmt.status(w.status) + '">' + (w.status === 'online' ? 'on' : 'off') + '</span>';
|
||||
// ok: pulse-innerhtml-unescaped
|
||||
el.innerHTML = rows.map(r => (keep.has(r.id) ? 'x' : '') + esc(r.name)).join('');
|
||||
}
|
||||
|
||||
function server() {
|
||||
// ruleid: pulse-no-shell-in-server
|
||||
require('child_process').execSync('ls ' + dir);
|
||||
// ok: pulse-no-shell-in-server
|
||||
require('child_process').execFileSync('git', ['rev-parse', 'HEAD']);
|
||||
// ruleid: pulse-no-vm
|
||||
const vm = require('vm');
|
||||
// ruleid: pulse-no-vm
|
||||
return eval(input);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
# Pulse's own semgrep rules, run by the Scan job. Test cases: .semgrep/pulse.js
|
||||
# (semgrep --test --config .semgrep/pulse.yml .semgrep/pulse.js).
|
||||
# The innerHTML rule checks member accesses (w.name, r.host); a value first copied into
|
||||
# a plain variable is not caught, so keep escaping at the point of insertion.
|
||||
rules:
|
||||
- id: pulse-no-vm
|
||||
message: >-
|
||||
Node's vm module is not a sandbox: code it runs can reach the server process.
|
||||
Workflow conditions go through lib/condition.js; don't evaluate user input with vm.
|
||||
severity: ERROR
|
||||
languages: [javascript]
|
||||
paths:
|
||||
exclude: [tests/]
|
||||
pattern-either:
|
||||
- pattern: require('vm')
|
||||
- pattern: new Function(...)
|
||||
- pattern: eval(...)
|
||||
|
||||
- id: pulse-no-shell-in-server
|
||||
message: >-
|
||||
The server must not run shell commands: use execFile/execFileSync with an argument
|
||||
list. (Running commands is the worker's job, over the authenticated WebSocket.)
|
||||
severity: ERROR
|
||||
languages: [javascript]
|
||||
paths:
|
||||
include: [server.js, lib/]
|
||||
pattern-either:
|
||||
- pattern: require('child_process').exec(...)
|
||||
- pattern: require('child_process').execSync(...)
|
||||
- pattern: "require('child_process').spawn(..., {..., shell: true, ...})"
|
||||
- pattern: |
|
||||
const { ..., exec, ... } = require('child_process');
|
||||
- pattern: |
|
||||
const { ..., execSync, ... } = require('child_process');
|
||||
|
||||
- id: pulse-innerhtml-unescaped
|
||||
message: >-
|
||||
Value inserted into innerHTML without escaping. Wrap it in esc() / Pulse.esc(), or
|
||||
build the element with textContent.
|
||||
severity: ERROR
|
||||
languages: [javascript]
|
||||
paths:
|
||||
include: [public/assets/]
|
||||
patterns:
|
||||
- pattern-either:
|
||||
- pattern-inside: $EL.innerHTML = $RHS
|
||||
- pattern-inside: $EL.innerHTML += $RHS
|
||||
- pattern: $OBJ.$PROP
|
||||
- pattern-not: $X.innerHTML
|
||||
- pattern-not-inside: esc(...)
|
||||
- pattern-not-inside: $NS.esc(...)
|
||||
- pattern-not-inside: escHtml(...)
|
||||
- pattern-not-inside: $NS.escHtml(...)
|
||||
- pattern-not-inside: encodeURIComponent(...)
|
||||
- pattern-not-inside: String(...)
|
||||
# The member as a method name (rows.map(...), Pulse.fmt.status(...)): not a value.
|
||||
- pattern-not-inside: $OBJ.$PROP(...)
|
||||
# Inputs to helpers whose result is not the raw value: Set.has() gives a boolean,
|
||||
# the Pulse.fmt formatters give class names or formatted dates.
|
||||
- pattern-not-inside: $SET.has(...)
|
||||
- pattern-not-inside: $NS.fmt.$FN(...)
|
||||
- pattern-not-inside: fmt.$FN(...)
|
||||
# Values only compared (to pick a class or a symbol) are not inserted.
|
||||
- pattern-not-inside: $A === $B
|
||||
- pattern-not-inside: $A !== $B
|
||||
- pattern-not-inside: $A == $B
|
||||
- pattern-not-inside: $A != $B
|
||||
@@ -589,7 +589,7 @@ Everything runs from `.gitea/workflows/ci.yml`:
|
||||
| `Lint (eslint)` | `npm run lint` (errors on bugs-in-waiting such as `==`, shadowed or unused variables and `eval`; no warnings allowed), plus a check that fails on em or en dashes anywhere in the repo, including the vendored design system | Every push and PR |
|
||||
| `Test (jest)` | `npm test`: unit tests for `lib/` and the worker, and the deploy-script sandbox tests. Fails if coverage drops below the floors in `package.json` (`lib/` 90% lines, `worker/` 40%) | Every push and PR |
|
||||
| `Security (npm audit)` | `npm audit --audit-level=high`, plus a CycloneDX SBOM of production dependencies (kept 90 days as the `sbom-cyclonedx` artifact of each `main` build) | Every push and PR, and weekly (Monday 06:00) |
|
||||
| `Scan (secrets, workflows, shell)` | gitleaks over the whole git history, actionlint on the workflow files (with shellcheck on their scripts), shellcheck on every `*.sh`, a check that `public/web_template` is byte-identical to upstream at the commit in its `VERSION`, and semgrep (JavaScript, Node.js, Express, secrets and security-audit rule packs). Suppress a reviewed false positive on its line with `nosemgrep: <rule id>` and a comment saying why | Every push and PR |
|
||||
| `Scan (secrets, workflows, shell)` | gitleaks over the whole git history, actionlint on the workflow files (with shellcheck on their scripts), shellcheck on every `*.sh`, a check that `public/web_template` is byte-identical to upstream at the commit in its `VERSION`, and semgrep (JavaScript, Node.js, Express, secrets and security-audit rule packs, plus Pulse's own rules in `.semgrep/pulse.yml`: no `vm`/`eval`, no shell commands in the server, no unescaped values in `innerHTML`; their test cases in `.semgrep/pulse.js` run first). Suppress a reviewed false positive on its line with `nosemgrep: <rule id>` and a comment saying why | Every push and PR |
|
||||
| `Integration (api)` | Starts the real server and three workers on Node 20 against MariaDB, then runs `tests/integration/` over HTTP and WebSocket: the Gandalf API contract, HTTP and WebSocket auth, and execution reliability (worker crash, capacity, abort) | Every push and PR |
|
||||
| `UI (playwright)` | Starts the real server and three workers against a MariaDB service container, then runs the Playwright tests in `tests/ui/` (desktop and phone) | Every push and PR |
|
||||
| `UI screenshots (before/after)` | On PRs that touch `public/`, `views/` or the render/nav code: runs the base branch and the PR side by side with the same seeded data and uploads a `ui-screenshots` artifact with one before/after image per page (desktop and phone). Pages that came out identical are listed in `unchanged.txt`. Not a required check; attach the relevant images to the PR for review | Pull requests |
|
||||
|
||||
@@ -26,6 +26,14 @@
|
||||
return meta.loadavg.map(l => Number(l).toFixed(2)).join(', ');
|
||||
}
|
||||
|
||||
// The commit the worker runs (#40): a short sha linked to the commit, or "unknown".
|
||||
function versionHtml(meta) {
|
||||
const v = meta && meta.version;
|
||||
if (typeof v !== 'string' || !/^[0-9a-f]{40}$/.test(v)) return esc('unknown');
|
||||
return '<a class="wk-version" href="https://code.lotusguild.org/LotusGuild/pulse/commit/' + esc(v) +
|
||||
'" target="_blank" rel="noopener" title="' + esc(v) + '">' + esc(v.slice(0, 7)) + '</a>';
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
Card construction
|
||||
------------------------------------------------------------------- */
|
||||
@@ -66,6 +74,8 @@
|
||||
'<div class="lt-kv-val" data-wk-uptime>' + esc(fmt.uptime(meta && meta.uptime)) + '</div>' +
|
||||
'<div class="lt-kv-key">Active Tasks</div>' +
|
||||
'<div class="lt-kv-val" data-wk-tasks>' + esc((meta && meta.activeTasks || 0) + ' / ' + (meta && meta.maxConcurrentTasks || 0)) + '</div>' +
|
||||
'<div class="lt-kv-key">Version</div>' +
|
||||
'<div class="lt-kv-val" data-wk-version>' + versionHtml(meta) + '</div>' +
|
||||
'</div>' +
|
||||
footerHtml(worker)
|
||||
);
|
||||
@@ -132,6 +142,9 @@
|
||||
const tasks = card.querySelector('[data-wk-tasks]');
|
||||
if (tasks) tasks.textContent = (meta && meta.activeTasks || 0) + ' / ' + (meta && meta.maxConcurrentTasks || 0);
|
||||
|
||||
const version = card.querySelector('[data-wk-version]');
|
||||
if (version) version.innerHTML = versionHtml(meta);
|
||||
|
||||
// Admin footer can appear/disappear if isAdmin changes mid-session (rare,
|
||||
// but keep it correct rather than assuming it's static).
|
||||
const hasFooter = !!card.querySelector('.lt-card-footer');
|
||||
|
||||
@@ -39,6 +39,17 @@ test('workers page lists each worker as online', async ({ page }) => {
|
||||
await expect(grid.getByText(/^online$/i)).toHaveCount(3);
|
||||
});
|
||||
|
||||
test('workers page shows the commit each worker runs (#40)', async ({ page }) => {
|
||||
const head = require('child_process').execFileSync('git', ['rev-parse', 'HEAD']).toString().trim();
|
||||
await page.goto('/workers');
|
||||
const versions = page.locator('#wk-grid [data-wk-version] a.wk-version');
|
||||
await expect(versions).toHaveCount(3);
|
||||
for (const v of await versions.all()) {
|
||||
await expect(v).toHaveText(head.slice(0, 7));
|
||||
await expect(v).toHaveAttribute('href', `https://code.lotusguild.org/LotusGuild/pulse/commit/${head}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('quick command offers every online worker', async ({ page }) => {
|
||||
await page.goto('/quick');
|
||||
await expect(page.locator('#qc-worker option', { hasText: 'online' })).toHaveCount(3);
|
||||
|
||||
Reference in new issue
Block a user