mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -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 !
92 lines
5.1 KiB
JavaScript
92 lines
5.1 KiB
JavaScript
'use strict';
|
|
// Execute the affected workflow boundaries without Docker, credentials or uploads.
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { spawnSync } = require('node:child_process');
|
|
const { pathToFileURL } = require('node:url');
|
|
const root = path.resolve(__dirname, '..');
|
|
const tmp = fs.mkdtempSync(path.join(root, '.tools/tmp/build-log-tests-'));
|
|
const read = file => fs.readFileSync(path.join(root, file), 'utf8');
|
|
function step(file, title) {
|
|
const body = read(file).split(` - name: ${title}\n`)[1].split('\n - ')[0];
|
|
return body.split(' run: |\n')[1].split('\n').map(l => l.slice(10)).join('\n');
|
|
}
|
|
function executable(file, source) {
|
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
fs.writeFileSync(file, source, { mode: 0o755 });
|
|
}
|
|
const env = { ...process.env, PATH: path.join(tmp, 'bin') + path.delimiter + process.env.PATH,
|
|
GITHUB_ENV: path.join(tmp, 'github-env'), TARGET: 'android-arm64', TARGET_PLATFORM: 'android',
|
|
TARGET_ARCH: 'arm64', RELEASE_TAG: 'v12.37', TERMUX_ARCH: 'aarch64' };
|
|
try {
|
|
fs.mkdirSync(path.join(tmp, 'bundle'));
|
|
// Mirror Termux's env -i at its privilege boundary; no real container is run.
|
|
executable(path.join(tmp, 'bin/docker'), `#!/usr/bin/env python3
|
|
import os, subprocess, sys
|
|
args = sys.argv[1:]
|
|
index = next(i for i, arg in enumerate(args) if arg.startswith('termux/termux-docker:'))
|
|
sys.exit(subprocess.run(args[index+1:], env={'PATH': os.environ['PATH']}).returncode)
|
|
`);
|
|
executable(path.join(tmp, 'bin/apt-get'), '#!/bin/sh\nexit 0\n');
|
|
executable(path.join(tmp, 'releases/bun/build-target.sh'), `#!/bin/bash
|
|
set -eu
|
|
[ "$TARGET" = android-arm64 ]
|
|
[ "$TARGET_PLATFORM" = android ]
|
|
[ "$TARGET_ARCH" = arm64 ]
|
|
[ "$RELEASE_TAG" = v12.37 ]
|
|
[ "$DO_NOT_TRACK" = 1 ]
|
|
echo metadata-preserved
|
|
`);
|
|
const android = step('.github/workflows/bun.yml', 'Native Android Bionic build and smoke tests');
|
|
const runAndroid = code => spawnSync('bash', ['-ec', code], { cwd: tmp, env, encoding: 'utf8' });
|
|
const positive = runAndroid(android);
|
|
assert.equal(positive.status, 0, positive.stdout + positive.stderr);
|
|
assert.match(positive.stdout, /metadata-preserved/);
|
|
const control = android.replace(/ env \\\n[\s\S]*?DO_NOT_TRACK=1 bash -ec/, ' bash -ec');
|
|
assert.notEqual(control, android);
|
|
assert.notEqual(runAndroid(control).status, 0, 'Docker -e alone must reproduce the lost environment');
|
|
|
|
// The i386 bundle was attached 13 minutes before AppImage incorrectly skipped it.
|
|
executable(path.join(tmp, 'bin/gh'), `#!/usr/bin/env python3
|
|
import os, sys
|
|
assert sys.argv.count('--repo') == 1
|
|
if os.environ['ASSET_CASE'] == 'error': sys.exit(9)
|
|
if os.environ['ASSET_CASE'] == 'present': print('wekan-12.37-i386.zip', flush=True)
|
|
# Large multi-write response catches early-closing grep/pipefail regressions.
|
|
for i in range(20000): print('other-asset-' + str(i))
|
|
`);
|
|
const gate = step('.github/workflows/AppImage.yml', 'Skip this arch if its release bundle is not published yet');
|
|
// The step's env: block, as the runner would set it (the values reach the
|
|
// script through env since the workflow hardening).
|
|
const gateEnv = { NEEDS_RELEASE_VERSION: '12.37', NEEDS_RELEASE_TAG: 'v12.37',
|
|
MATRIX_BUNDLE_ARCH: 'i386', GITHUB_CTX_REPOSITORY: 'wekan/wekan' };
|
|
for (const kind of ['present', 'missing', 'error']) {
|
|
fs.writeFileSync(env.GITHUB_ENV, '');
|
|
const result = spawnSync('bash', ['-ec', gate], { cwd: tmp, env: { ...env, ...gateEnv, ASSET_CASE: kind }, encoding: 'utf8' });
|
|
assert.equal(result.status === 0, kind !== 'error', result.stdout + result.stderr);
|
|
assert.equal(fs.readFileSync(env.GITHUB_ENV, 'utf8').includes('BUILD_THIS=false'), kind === 'missing');
|
|
}
|
|
|
|
// Probes must exit after a successful require, rebuild on load errors and
|
|
// terminate an addon stuck inside native initialization (no event-loop timer).
|
|
const probeTest = path.join(tmp, 'probe.mjs');
|
|
fs.writeFileSync(path.join(tmp, 'ok.cjs'), 'setInterval(() => {}, 1000);');
|
|
fs.writeFileSync(path.join(tmp, 'bad.cjs'), 'throw new Error("bad native addon");');
|
|
fs.writeFileSync(path.join(tmp, 'hung.cjs'), 'while (true) {}');
|
|
fs.writeFileSync(probeTest, `import { probeAddon, run } from ${JSON.stringify(pathToFileURL(path.join(root, 'releases/bun/rebuild.mjs')).href)};
|
|
import assert from 'node:assert/strict';
|
|
assert.equal(probeAddon(process.execPath, './ok.cjs', process.cwd(), 2000), true);
|
|
assert.equal(probeAddon(process.execPath, './bad.cjs', process.cwd(), 2000), false);
|
|
assert.equal(probeAddon(process.execPath, './hung.cjs', process.cwd(), 200), false);
|
|
assert.throws(() => run(process.execPath, ['-e', 'while(true) {}'], process.cwd(), {}, 200), /ETIMEDOUT/);
|
|
`);
|
|
const probes = spawnSync(process.execPath, [probeTest], { cwd: tmp, encoding: 'utf8', timeout: 8000 });
|
|
assert.equal(probes.status, 0, probes.stdout + probes.stderr);
|
|
assert.match(read('releases/bun/build-target.sh'), /node releases\/bun\/run-native-check.mjs/);
|
|
assert.match(read('releases/bun/run-native-check.mjs'), /180000/);
|
|
console.log('Android env reset, AppImage asset detection, and hung addon regression tests passed.');
|
|
} finally {
|
|
fs.rmSync(tmp, { recursive: true, force: true });
|
|
}
|