CI: eslint-plugin-security and zizmor; harden the workflow #65

Merged
jared merged 2 commits from more-scanners into main 2026-11-23 00:22:41 -05:00
11 changed files with 105 additions and 21 deletions

No files matched your search

+18 -2
View File
@@ -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"
}
}
]
}
+32 -13
View File
@@ -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: |
@@ -129,20 +138,23 @@ jobs:
tar -xzf gitleaks.tgz -C /usr/local/bin gitleaks
tar -xzf actionlint.tgz -C /usr/local/bin actionlint
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends shellcheck >/dev/null
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends shellcheck python3-venv >/dev/null # venv: zizmor and semgrep
- name: Secrets in code and history (gitleaks)
run: gitleaks git --no-banner --redact --exit-code 1 .
- name: Workflow files (actionlint, with shellcheck on run scripts)
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)
# Rule packs come from the semgrep registry, so new rules can surface new
# findings: fix them, or suppress one line with `nosemgrep: <rule id>` and a reason.
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
@@ -158,7 +170,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 +179,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 +207,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 +218,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 +305,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 +329,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
+3 -3
View File
@@ -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: <rule id>` 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: <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 |
@@ -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
+8 -3
View File
@@ -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 === '"') {
+1
View File
@@ -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;
}
+1
View File
@@ -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.
+37
View File
@@ -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",
+1
View File
@@ -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": {
+1
View File
@@ -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`]
: [],
+2
View File
@@ -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')",
+1
View File
@@ -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 */ }