mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
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 !
52 lines
2.5 KiB
JavaScript
52 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
// The release workflow must reject any stale version consumer before commit/push.
|
|
|
|
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 node = process.execPath;
|
|
const verifier = path.join(root, 'releases/verify-release-versions.mjs');
|
|
const workflow = fs.readFileSync(path.join(root, '.github/workflows/release-all.yml'), 'utf8');
|
|
const expected = fs.readFileSync(path.join(root, 'Dockerfile'), 'utf8')
|
|
.match(/^ARG VERSION=([^\s]+)$/m)[1];
|
|
const run = (cwd = root) => spawnSync(node, [verifier, expected], {
|
|
encoding: 'utf8', env: { ...process.env, WEKAN_VERSION_ROOT: cwd },
|
|
});
|
|
|
|
assert.equal(run().status, 0, run().stderr);
|
|
// The input reaches the script through env (tests/workflowHardening.test.cjs).
|
|
assert.match(workflow, /name: Verify every release version reference\n\s+env:\n\s+INPUT_NEW_VERSION: \$\{\{ inputs\.new_version \}\}\n\s+run: \|\n\s+node \.\/releases\/verify-release-versions\.mjs "\$\{INPUT_NEW_VERSION\}"/,
|
|
'release-all verifies the bumped checkout before committing it');
|
|
|
|
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'wekan-release-versions-'));
|
|
for (const file of [
|
|
'package.json', 'package-lock.json', 'Dockerfile', 'Stackerfile.yml',
|
|
'snapcraft.yaml', 'sandstorm-pkgdef.capnp', '.meteor/release',
|
|
]) {
|
|
const destination = path.join(temp, file);
|
|
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
fs.copyFileSync(path.join(root, file), destination);
|
|
}
|
|
fs.writeFileSync(path.join(temp, 'Dockerfile'),
|
|
fs.readFileSync(path.join(temp, 'Dockerfile'), 'utf8')
|
|
.replace(/METEOR_RELEASE=METEOR@[^\s\\]+/, 'METEOR_RELEASE=METEOR@0.0.0'));
|
|
const staleMeteor = run(temp);
|
|
assert.equal(staleMeteor.status, 1, 'stale Meteor metadata fails the release');
|
|
assert.match(staleMeteor.stderr, /Dockerfile: Meteor metadata is 0\.0\.0/);
|
|
|
|
fs.copyFileSync(path.join(root, 'Dockerfile'), path.join(temp, 'Dockerfile'));
|
|
fs.writeFileSync(path.join(temp, 'snapcraft.yaml'),
|
|
fs.readFileSync(path.join(temp, 'snapcraft.yaml'), 'utf8')
|
|
.replace(/^version:.*$/m, "version: '0.0'"));
|
|
const staleApp = run(temp);
|
|
assert.equal(staleApp.status, 1, 'any stale application version fails the release');
|
|
assert.match(staleApp.stderr, /snapcraft\.yaml: snap version is 0\.0/);
|
|
|
|
fs.rmSync(temp, { recursive: true, force: true });
|
|
console.log('releaseVersionConsistency: positive and stale-version checks passed');
|