Files
wekan/tests/websiteVersionInfo.test.cjs
T
Lauri Ojansivu 7f7cc63cde GitHub Actions: no expressions in scripts, actions pinned, least privilege.
Qlty (zizmor) security findings in the workflows that build and publish
every release:

- template-injection (128): ${{ ... }} pasted into a run: script is expanded
  before the shell sees it, so a crafted workflow_dispatch input, tag or step
  output becomes shell code. 251 expressions in 13 workflows now reach their
  scripts through the step's env: and are used as quoted shell variables
  ($env:NAME in the PowerShell steps); ${{ env.X }} is plain $X. Where a
  value sat in single quotes it is double-quoted now, and six unquoted ones
  are quoted.
- unpinned-uses (20 in Qlty, 160 with current zizmor): every action is
  pinned to a commit, with its version as a comment for Dependabot.
  actions/dependency-review-action@v5 was a branch; it is v5.0.0.
- excessive-permissions (8): AppImage, Flatpak, mac, windows,
  release-all and release-all-missing grant contents: read at the workflow
  level, and each job that writes (a release asset, a git push, the docker
  push, gh run rerun) is granted that on the job. Nothing used actions:
  write except recover, which keeps it.
- artipacked (47 -> 13): actions/checkout gets persist-credentials: false,
  except in the jobs that push with the checkout's credentials, directly or
  through releases/version.sh, release-website.sh, release-charts.sh and
  backfill-charts.sh.

actionlint with shellcheck reports 50 notes, the 56 before minus the six
quoted. Every PowerShell step parses (pwsh 7.6.7). Not run on GitHub.

tests/workflowHardening.test.cjs fails on an expression in a run script,
an unpinned action, a workflow-level write grant in a multi-job workflow,
or a checkout keeping credentials outside the pushing jobs, and runs
zizmor when it is installed. Eleven guards that pinned the old text, or ran
the extracted scripts with the expressions substituted, now pin the env
form and pass the values as the step's environment.

Thanks to Qlty and xet7 !
2026-10-15 23:19:50 +03:00

90 lines
4.3 KiB
JavaScript

'use strict';
// The website version manifest is both the Admin Panel's release source and the
// human-readable version block on /install/. This runs the real release helper
// against a temporary website without network access.
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const root = path.resolve(__dirname, '..');
const helper = path.join(root, 'releases/update-website-version-info.sh');
const dockerfile = fs.readFileSync(path.join(root, 'Dockerfile'), 'utf8');
const pin = pattern => {
const match = dockerfile.match(pattern);
assert.ok(match, `Dockerfile is missing version pin ${pattern}`);
return match[1];
};
const wekanVersion = pin(/^ARG VERSION=([^\s]+)$/m);
const meteorVersion = fs.readFileSync(path.join(root, '.meteor/release'), 'utf8')
.trim().replace(/^METEOR@/, '');
const nodeVersion = pin(/^\s*NODE_VERSION=v([^\s\\]+).*$/m);
const npmVersion = pin(/^\s*NPM_VERSION=([^\s\\]+).*$/m);
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'wekan-version-info-'));
const fixtureRepo = path.join(temp, 'wekan');
fs.mkdirSync(path.join(temp, 'install'));
fs.mkdirSync(path.join(fixtureRepo, '.meteor'), { recursive: true });
fs.writeFileSync(path.join(fixtureRepo, 'Dockerfile'), dockerfile.replace(
/METEOR_RELEASE=METEOR@[^\s\\]+/,
'METEOR_RELEASE=METEOR@3.5.2-beta.0'));
fs.copyFileSync(path.join(root, '.meteor/release'),
path.join(fixtureRepo, '.meteor/release'));
fs.writeFileSync(path.join(temp, 'install/index.html'),
'<main><h2>Install <span class="version-number">v11.29</span></h2></main>\n');
const run = version => spawnSync('bash', [helper, temp, fixtureRepo, wekanVersion], {
cwd: root,
encoding: 'utf8',
env: { ...process.env, FERRETDB_VERSION: version },
});
assert.notEqual(meteorVersion, '3.5.2-beta.0',
'fixture must catch the stale prerelease that was published for v11.50');
const expected = [
`WeKan ${wekanVersion}`,
'FerretDB 1.64.0',
`Meteor ${meteorVersion}`,
`Node ${nodeVersion}`,
`NPM ${npmVersion}`,
].join('\n');
const result = run('v1.64.0');
assert.equal(result.status, 0, result.stderr);
assert.equal(fs.readFileSync(path.join(temp, 'version.txt'), 'utf8'), `${expected}\n`);
// A current Meteor prerelease is valid; reject the specific stale fixture version.
assert.ok(!fs.readFileSync(path.join(temp, 'version.txt'), 'utf8').includes('Meteor 3.5.2-beta.0\n'),
'stale Docker metadata cannot override the canonical .meteor/release pin');
const installPage = fs.readFileSync(path.join(temp, 'install/index.html'), 'utf8');
assert.ok(installPage.includes(`<pre id="version-info">${expected}</pre>`),
'the install page contains the exact version manifest as literal text');
const before = fs.readFileSync(path.join(temp, 'version.txt'), 'utf8');
const rejected = run('<script>1.64.0</script>');
assert.notEqual(rejected.status, 0, 'a non-version FerretDB response must fail');
assert.equal(fs.readFileSync(path.join(temp, 'version.txt'), 'utf8'), before,
'invalid input cannot overwrite the last valid manifest');
const releaseWebsite = fs.readFileSync(
path.join(root, 'releases/release-website.sh'), 'utf8');
const localRelease = fs.readFileSync(path.join(root, 'releases/version.sh'), 'utf8');
const workflow = fs.readFileSync(
path.join(root, '.github/workflows/release-all.yml'), 'utf8');
assert.match(releaseWebsite, /update-website-version-info\.sh/);
assert.match(localRelease, /update-website-version-info\.sh/);
assert.match(localRelease,
/METEOR_RELEASE=\$\(tr -d '[^']*' < \.meteor\/release \| head -1\)/,
'release bump synchronizes Docker metadata from the canonical Meteor pin');
assert.match(localRelease, /METEOR_RELEASE=\$\{METEOR_RELEASE\}/,
'the synchronized prerelease is written to Dockerfile');
assert.ok(fs.readFileSync(path.join(root, 'Dockerfile'), 'utf8')
.includes(`METEOR_RELEASE=METEOR@${meteorVersion}`),
'Docker metadata currently matches .meteor/release');
assert.match(workflow, /INPUT_OLD_VERSION: \$\{\{ inputs\.old_version \}\}[\s\S]*?release-website\.sh "\$\{INPUT_OLD_VERSION\}" "\$\{INPUT_NEW_VERSION\}"/,
'release-all website job runs the script that generates both destinations');
fs.rmSync(temp, { recursive: true, force: true });
console.log('websiteVersionInfo: manifest, install page and release wiring passed');