From 235d9240c097b20e3d7b1749461ac25d28343ef7 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 22 Nov 2026 23:45:35 -0500 Subject: [PATCH] CI: eslint-plugin-security and zizmor; harden the workflow - eslint-plugin-security 4.2.1 (recommended-legacy) with detect-object-injection off (it flags every obj[key]) and file/regex rules off for CI scripts and tests. The remaining hits were false positives with a one-line reason each (fixed page names, the worker's own directory, a null check), plus one real tidy-up: the condition tokenizer's number regex is now two flat patterns with no backtracking, and malformed numbers like 1.2.3 are refused. - zizmor 1.32.0 in the Scan job. Its findings are fixed: persist-credentials: false on every checkout (no job pushes), container images pinned by digest (tag kept in the reference), and the deploy tag step takes github.* values through env instead of template expansion. Left as is: secrets-outside-env (auditor persona; Gitea has no deployment environments). Co-Authored-By: Claude Opus 5.5 --- .eslintrc.json | 20 ++++++++++++++++++-- .gitea/workflows/ci.yml | 42 ++++++++++++++++++++++++++++++----------- README.md | 6 +++--- lib/condition.js | 11 ++++++++--- lib/render.js | 1 + lib/wsauth.js | 1 + package-lock.json | 37 ++++++++++++++++++++++++++++++++++++ package.json | 1 + server.js | 1 + tests/condition.test.js | 2 ++ worker/worker.js | 1 + 11 files changed, 104 insertions(+), 19 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index dcf0938..1d5c919 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,7 +3,10 @@ "node": true, "es2021": true }, - "extends": "eslint:recommended", + "extends": [ + "eslint:recommended", + "plugin:security/recommended-legacy" + ], "parserOptions": { "ecmaVersion": 2021, "sourceType": "commonjs" @@ -64,7 +67,8 @@ "allowShortCircuit": true, "allowTernary": true } - ] + ], + "security/detect-object-injection": "off" }, "overrides": [ { @@ -75,6 +79,18 @@ "browser": true, "node": true } + }, + { + "files": [ + "scripts/**/*.js", + "tests/**/*.js" + ], + "rules": { + "security/detect-non-literal-fs-filename": "off", + "security/detect-non-literal-regexp": "off", + "security/detect-unsafe-regex": "off", + "security/detect-child-process": "off" + } } ] } diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index e249a10..6b76935 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -28,9 +28,11 @@ jobs: name: Lint (eslint) runs-on: ubuntu-latest timeout-minutes: 20 # a hung step fails instead of blocking main - container: node:20-bookworm + container: node:20-bookworm@sha256:8f693eaa7e0a8e71560c9a82b55fd54c2ae920a2ba5d2cde28bac7d1c01c9ba5 steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false # no job pushes; keep the token out of .git/config - name: Install dependencies (lockfile only) run: npm ci - name: Run ESLint @@ -48,9 +50,11 @@ jobs: name: Test (jest) runs-on: ubuntu-latest timeout-minutes: 20 - container: node:20-bookworm + container: node:20-bookworm@sha256:8f693eaa7e0a8e71560c9a82b55fd54c2ae920a2ba5d2cde28bac7d1c01c9ba5 steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false # no job pushes; keep the token out of .git/config - name: Install dependencies (lockfile only) run: npm ci - name: Run jest with coverage @@ -60,9 +64,11 @@ jobs: name: Security (npm audit) runs-on: ubuntu-latest timeout-minutes: 10 - container: node:20-bookworm + container: node:20-bookworm@sha256:8f693eaa7e0a8e71560c9a82b55fd54c2ae920a2ba5d2cde28bac7d1c01c9ba5 steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false # no job pushes; keep the token out of .git/config - name: Audit production and dev dependencies run: | # Retry only when the registry itself fails (it has returned spurious 400s); @@ -89,7 +95,7 @@ jobs: name: Integration (api) runs-on: ubuntu-latest timeout-minutes: 25 - container: node:20-bookworm # the server and workers on production's Node + container: node:20-bookworm@sha256:8f693eaa7e0a8e71560c9a82b55fd54c2ae920a2ba5d2cde28bac7d1c01c9ba5 # the server and workers on production's Node env: DB_HOST: 127.0.0.1 DB_PORT: '3306' @@ -98,6 +104,8 @@ jobs: DB_PASSWORD: ci-only # throwaway database inside the job container steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false # no job pushes; keep the token out of .git/config - name: Install dependencies (lockfile only) run: npm ci - name: Start MariaDB @@ -114,10 +122,11 @@ jobs: name: Scan (secrets, workflows, shell) runs-on: ubuntu-latest timeout-minutes: 20 - container: node:20-bookworm + container: node:20-bookworm@sha256:8f693eaa7e0a8e71560c9a82b55fd54c2ae920a2ba5d2cde28bac7d1c01c9ba5 steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: + persist-credentials: false # no job pushes; keep the token out of .git/config fetch-depth: 0 # gitleaks scans the whole history, not just this commit - name: Install scanners (pinned versions, verified checksums) run: | @@ -136,6 +145,10 @@ jobs: run: actionlint .gitea/workflows/*.yml - name: Shell scripts (shellcheck) run: git ls-files -z '*.sh' | xargs -0 shellcheck + - name: Workflow security (zizmor) + run: | + python3 -m venv /tmp/zizmor && /tmp/zizmor/bin/pip install -q zizmor==1.32.0 + /tmp/zizmor/bin/zizmor --offline --format plain .gitea/workflows/*.yml - name: Vendored design system matches upstream run: scripts/ci/check-web-template.sh - name: Code patterns (semgrep) @@ -158,7 +171,7 @@ jobs: timeout-minutes: 30 # Official image with Chromium and its system libraries; its version must match # @playwright/test in package.json. - container: mcr.microsoft.com/playwright:v1.64.1-noble + container: mcr.microsoft.com/playwright:v1.64.1-noble@sha256:2f05f8a734509a7b3f26a912639488ee08f58a7b292d14d62271bcff9038768f env: DB_HOST: 127.0.0.1 DB_PORT: '3306' @@ -167,6 +180,8 @@ jobs: DB_PASSWORD: ci-only # throwaway database inside the job container steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false # no job pushes; keep the token out of .git/config - name: Install dependencies (lockfile only) run: npm ci - name: Start MariaDB @@ -193,7 +208,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 30 if: github.event_name == 'pull_request' - container: mcr.microsoft.com/playwright:v1.64.1-noble + container: mcr.microsoft.com/playwright:v1.64.1-noble@sha256:2f05f8a734509a7b3f26a912639488ee08f58a7b292d14d62271bcff9038768f env: DB_HOST: 127.0.0.1 DB_PORT: '3306' @@ -204,6 +219,7 @@ jobs: steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: + persist-credentials: false # no job pushes; keep the token out of .git/config fetch-depth: 0 - name: Did this PR change the UI? id: ui @@ -290,19 +306,22 @@ jobs: - name: Tag deployed commit env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RUN_NUMBER: ${{ github.run_number }} + GIT_SHA: ${{ github.sha }} + REPO: ${{ github.repository }} run: | - TAG="deploy-$(date -u +%Y.%m.%d)-${{ github.run_number }}" + TAG="deploy-$(date -u +%Y.%m.%d)-${RUN_NUMBER}" curl -sf -X POST \ -H "Authorization: token $GITHUB_TOKEN" \ -H "Content-Type: application/json" \ - -d "{\"tag_name\":\"${TAG}\",\"target\":\"${{ github.sha }}\",\"message\":\"Deployed to production\"}" \ - "https://code.lotusguild.org/api/v1/repos/${{ github.repository }}/tags" + -d "{\"tag_name\":\"${TAG}\",\"target\":\"${GIT_SHA}\",\"message\":\"Deployed to production\"}" \ + "https://code.lotusguild.org/api/v1/repos/${REPO}/tags" deploy-worker: name: Deploy worker runs-on: ubuntu-latest timeout-minutes: 15 - container: node:20-bookworm + container: node:20-bookworm@sha256:8f693eaa7e0a8e71560c9a82b55fd54c2ae920a2ba5d2cde28bac7d1c01c9ba5 needs: [deploy] # the server first: it must understand anything new the worker sends if: github.event_name == 'push' && github.ref == 'refs/heads/main' concurrency: @@ -311,6 +330,7 @@ jobs: steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: + persist-credentials: false # no job pushes; keep the token out of .git/config fetch-depth: 0 # to compare against the commit the worker runs now - name: Did the worker change since the running version? id: changed diff --git a/README.md b/README.md index 8a64a4e..b71d985 100644 --- a/README.md +++ b/README.md @@ -586,10 +586,10 @@ Everything runs from `.gitea/workflows/ci.yml`: | Job | What it does | When | |---|---|---| -| `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 | +| `Lint (eslint)` | `npm run lint` (errors on bugs-in-waiting such as `==`, shadowed or unused variables and `eval`, plus eslint-plugin-security's recommended rules except object-injection; 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, 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: ` and a comment saying why | Every push and PR | +| `Scan (secrets, workflows, shell)` | gitleaks over the whole git history, actionlint and zizmor on the workflow files (shellcheck on their scripts; zizmor for injection, credential persistence and unpinned images), 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: ` 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 | @@ -599,7 +599,7 @@ Everything runs from `.gitea/workflows/ci.yml`: Branch protection on `main` requires `CI / Lint (eslint) (push)`, `CI / Test (jest) (push)`, `CI / Security (npm audit) (push)`, `CI / Scan (secrets, workflows, shell) (push)`, `CI / Integration (api) (push)` and `CI / UI (playwright) (push)`. Actions are pinned to commit -SHAs and builds use `npm ci`. The plan for the rest of the pipeline is tracked in #45. +SHAs, container images to digests, checkouts don't keep the token, and builds use `npm ci`. The plan for the rest of the pipeline is tracked in #45. ### Integration tests diff --git a/lib/condition.js b/lib/condition.js index 2c5e670..d290d0a 100644 --- a/lib/condition.js +++ b/lib/condition.js @@ -38,9 +38,14 @@ function tokenize(src) { const c = src[i]; if (/\s/.test(c)) { i++; continue; } if (/[0-9]/.test(c) || (c === '.' && /[0-9]/.test(src[i + 1] || ''))) { - const m = /^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(src.slice(i)); - tokens.push({ t: 'num', v: Number(m[0]) }); - i += m[0].length; + // Digits and dots, then an optional exponent: two flat patterns, no backtracking. + let text = /^[0-9.]+/.exec(src.slice(i))[0]; + const exp = /^[eE][+-]?[0-9]+/.exec(src.slice(i + text.length)); + if (exp) text += exp[0]; + const v = Number(text); + if (Number.isNaN(v)) throw new ConditionError(`invalid number ${JSON.stringify(text)}`); + tokens.push({ t: 'num', v }); + i += text.length; continue; } if (c === '\'' || c === '"') { diff --git a/lib/render.js b/lib/render.js index b405ef2..a2f3726 100644 --- a/lib/render.js +++ b/lib/render.js @@ -33,6 +33,7 @@ const APP_SUBTITLE = process.env.APP_SUBTITLE || 'Worker Orchestration // LotusG function viewPath(view) { const file = path.join(PAGES_DIR, `${view}.ejs`); + // eslint-disable-next-line security/detect-non-literal-fs-filename -- view names come from the fixed page list return fs.existsSync(file) ? file : STUB; } diff --git a/lib/wsauth.js b/lib/wsauth.js index 511d4be..46dd741 100644 --- a/lib/wsauth.js +++ b/lib/wsauth.js @@ -41,6 +41,7 @@ function classifyUpgrade(req, opts = {}) { const enforce = 'enforce' in opts ? opts.enforce : workerAuthEnforced(); const token = bearerToken(req); + // eslint-disable-next-line security/detect-possible-timing-attacks -- a null check; keys are compared with safeEqual if (token !== null) { // A wrong key is never downgraded to pending: it is either a misconfigured // worker or an attacker, and both should see the refusal. diff --git a/package-lock.json b/package-lock.json index cb66077..f20c975 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "devDependencies": { "@playwright/test": "1.64.1", "eslint": "^8.57.1", + "eslint-plugin-security": "4.2.1", "jest": "^30.5.2" }, "engines": { @@ -3174,6 +3175,22 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-plugin-security": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-security/-/eslint-plugin-security-4.2.1.tgz", + "integrity": "sha512-iF95SSqdSUVTvB7srNXoNeTQIqwfALTn9nmoqJyixSIKqEydlW01Cqb7xNveqE4Zd6YWBoQICQ4FH9NkR1byDg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "safe-regex": "^2.1.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, "node_modules/eslint-scope": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", @@ -5847,6 +5864,16 @@ "node": ">= 0.10" } }, + "node_modules/regexp-tree": { + "version": "0.1.27", + "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.27.tgz", + "integrity": "sha512-iETxpjK6YoRWJG5o6hXLwvjYAoW+FEZn9os0PD/b6AP6xQwsa/Y7lCVgIixBbUPMfhu+i2LtdeAqVTgGlQarfA==", + "dev": true, + "license": "MIT", + "bin": { + "regexp-tree": "bin/regexp-tree" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -5954,6 +5981,16 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/safe-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-2.1.1.tgz", + "integrity": "sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==", + "dev": true, + "license": "MIT", + "dependencies": { + "regexp-tree": "~0.1.1" + } + }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", diff --git a/package.json b/package.json index 400c93b..ded136f 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "devDependencies": { "@playwright/test": "1.64.1", "eslint": "^8.57.1", + "eslint-plugin-security": "4.2.1", "jest": "^30.5.2" }, "jest": { diff --git a/server.js b/server.js index 348453a..a0a6495 100644 --- a/server.js +++ b/server.js @@ -1379,6 +1379,7 @@ PAGES.forEach((p) => { pageTitle: p.title, activeNav: p.key, pageScripts: [`/assets/pages/${p.view}.js`], + // eslint-disable-next-line security/detect-non-literal-fs-filename -- p.view comes from the fixed PAGES list pageStyles: fs.existsSync(path.join(__dirname, `public/assets/pages/${p.view}.css`)) ? [`/assets/pages/${p.view}.css`] : [], diff --git a/tests/condition.test.js b/tests/condition.test.js index 851077e..3dea7d1 100644 --- a/tests/condition.test.js +++ b/tests/condition.test.js @@ -70,6 +70,7 @@ describe('the language', () => { expect(ev('1 == "1" && 1 != 2')).toBe(true); expect(ev("state.x === undefined", {})).toBe(true); expect(ev("'it\\'s' === \"it's\"")).toBe(true); + expect(ev('1.5e2 === 150 && .5 === 0.5 && 2E-1 === 0.2 && 3. === 3')).toBe(true); }); test('functions and string methods', () => { expect(ev("parseInt('42px') === 42 && parseFloat('-3.5') === -3.5")).toBe(true); @@ -96,6 +97,7 @@ describe('a condition can only read the workflow data', () => { '(() => 1)()', '`template`', '1; 2', + '1.2.3 === 1', "state.x.toString()", "'a'.constructor", "parseInt.call(null, '1')", diff --git a/worker/worker.js b/worker/worker.js index 764e26e..ed55d06 100644 --- a/worker/worker.js +++ b/worker/worker.js @@ -14,6 +14,7 @@ function detectVersion(dir = __dirname) { const fs = require('fs'); const path = require('path'); try { + // eslint-disable-next-line security/detect-non-literal-fs-filename -- the worker's own directory const v = fs.readFileSync(path.join(dir, 'VERSION'), 'utf8').trim(); if (/^[0-9a-f]{40}$/.test(v)) return v; } catch { /* no VERSION file */ }