Files
wekan/tests/releaseNotesNoShellInjection.test.cjs
T
Lauri Ojansivu ac02941663 v10.92 could not start bash: the release notes outgrew an environment variable.
The release job failed before running a line of its script:

  ##[error]An error occurred trying to start process /usr/bin/bash with
  working directory /home/runner/work/wekan/wekan. Argument list too long

Nothing in the step was wrong. The notes are the whole newest CHANGELOG
section - prepare measured them at 172,458 characters - and they reached
the step as env: CHANGELOG. Linux caps a SINGLE argv/envp string at
MAX_ARG_STRLEN, 128 KiB, so execve refused to start the shell at all. Both
bundles had built and verified; the release, and every job that needs it -
snap, docker, AppImage, the Windows and macOS bundles - never happened.

The environment was itself the fix for the previous failure: interpolated
inline as ${{ }} the notes become part of the shell SOURCE, so a backtick
in any `code` span runs as a command, which is how v10.59 published nothing
and printed "Incorrect: command not found". One shape is unsafe, the other
does not scale, and this release was big enough to find the second wall.

So the notes stop being a shell value at all. releases/release-notes.sh
prints the CHANGELOG section for a version, reading the file itself and
taking its arguments from the environment inside a QUOTED heredoc; the jobs
append its stdout to release-notes.md. Only file paths are passed around,
which has no size limit and leaves the text as data no shell ever parses.

prepare keeps the validation - a missing section is still cheap to fix
there - but no longer publishes the text as a job output, because an output
nobody can safely consume is a trap for the next person. The release job
and the notes-rewrite job check out ref: main, the same ref prepare read.

The guard test is rewritten around the new shape: no changelog job output,
no CHANGELOG in an env:, no interpolation into a script, and the extraction
script is what all three consumers run. It kept passing through this
failure, because it only knew about the injection.

Thanks to xet7 !
2026-08-15 21:46:00 +03:00

141 lines
5.7 KiB
JavaScript

'use strict';
// Plain-Node guard on HOW the release notes reach the release job.
// Run: node tests/releaseNotesNoShellInjection.test.cjs
//
// release-all.yml builds the GitHub Release body from the newest CHANGELOG.md
// section. That text is arbitrary markdown, it is enormous, and each of the two
// obvious ways to hand it to a shell step has already broken a release:
//
// 1. INLINE `${{ needs.prepare.outputs.changelog }}` in a `run:` block.
// GitHub substitutes it into the shell SOURCE before bash parses it, so
// every `code` span's backtick runs as a command. v10.59 died with
// "Incorrect: command not found", "loginFailureDecision.js: Permission
// denied", … and published nothing.
//
// 2. THROUGH THE ENVIRONMENT - `env: CHANGELOG: ${{ … }}` then "$CHANGELOG".
// That fixed the backticks and hit a harder wall: Linux caps a SINGLE
// argv/envp string at MAX_ARG_STRLEN, 128 KiB, and the v10.92 notes were
// 172,458 characters. execve refused to start bash at all - "An error
// occurred trying to start process '/usr/bin/bash' … Argument list too
// long" - before a line of the step ran.
//
// The shape that has neither problem is FILE TO FILE: each job that needs the
// notes extracts them from its own checkout of CHANGELOG.md with
// releases/release-notes.sh, straight into release-notes.md. Only file paths are
// passed around, so there is no size limit and no shell ever parses the text.
//
// This pins that shape: no changelog job output, no changelog in an env:, no
// changelog interpolated into a script, and the extraction script is the thing
// every consumer uses.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const repoRoot = path.resolve(__dirname, '..');
const wfDir = path.join(repoRoot, '.github/workflows');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
const files = fs
.readdirSync(wfDir)
.filter((f) => /\.ya?ml$/.test(f))
.map((f) => path.join('.github/workflows', f));
const read = (rel) => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
test('a release workflow exists to check', () => {
assert.ok(
files.some((f) => /release-all/.test(f)),
'expected a release-all workflow',
);
});
test('the notes are never carried as a job output', () => {
// 128 KiB is the ceiling for one environment string, and the notes are past
// it, so an output nobody can safely consume is a trap for the next person.
const offenders = [];
for (const rel of files) {
read(rel).split('\n').forEach((line, i) => {
if (/\.outputs\.changelog/.test(line)) offenders.push(`${rel}:${i + 1}: ${line.trim()}`);
if (/^\s*changelog:\s*\$\{\{/.test(line)) offenders.push(`${rel}:${i + 1}: ${line.trim()}`);
});
}
assert.deepStrictEqual(
offenders,
[],
`the release notes are passed as a job output again:\n${offenders.join('\n')}`,
);
});
test('no step puts a whole CHANGELOG section into an environment variable', () => {
// env: CHANGELOG: ${{ … }} is what made execve fail with E2BIG in v10.92.
const offenders = [];
for (const rel of files) {
read(rel).split('\n').forEach((line, i) => {
if (/^\s*CHANGELOG:\s*\$\{\{/.test(line)) offenders.push(`${rel}:${i + 1}: ${line.trim()}`);
});
}
assert.deepStrictEqual(
offenders,
[],
`a whole CHANGELOG section is back in env:, which execve refuses over 128 KiB:\n${offenders.join('\n')}`,
);
});
test('the extraction script exists, and is what every consumer runs', () => {
const script = path.join(repoRoot, 'releases/release-notes.sh');
assert.ok(fs.existsSync(script), 'expected releases/release-notes.sh');
const text = read('.github/workflows/release-all.yml');
const uses = text.match(/releases\/release-notes\.sh/g) || [];
// prepare validates, the release job composes, the rewrite job recomposes.
assert.ok(
uses.length >= 3,
`expected release-notes.sh to be used by prepare, release and the notes rewrite; found ${uses.length}`,
);
});
test('every step that writes the notes into release-notes.md reads them from the file', () => {
const text = read('.github/workflows/release-all.yml');
// The old shapes, in the exact forms that broke: a printf of the variable, and
// an inline interpolation into the script.
assert.ok(
!/printf[^\n]*"\$CHANGELOG"/.test(text),
'a step still pipes "$CHANGELOG" into the notes; read CHANGELOG.md with release-notes.sh instead',
);
assert.ok(
!/>>\s*release-notes\.md[^\n]*\$\{\{/.test(text),
'a step interpolates ${{ }} into the notes, where a backtick runs as a command',
);
// and what must be there instead
assert.ok(
/release-notes\.sh "\$VERSION" >> release-notes\.md/.test(text),
'expected the notes to be appended from releases/release-notes.sh',
);
});
test('release-notes.sh keeps the text out of the shell and fails loudly when there is none', () => {
const sh = fs.readFileSync(path.join(repoRoot, 'releases/release-notes.sh'), 'utf8');
assert.ok(/set -euo pipefail/.test(sh), 'expected set -euo pipefail');
// The python must read the file itself and take its arguments from the
// environment; a `version = "$VERSION"` substitution would put CHANGELOG-
// adjacent text back into the heredoc the shell expands.
assert.ok(/<<'PYEOF'/.test(sh), "expected a QUOTED heredoc, so the shell does not expand it");
assert.ok(
/os\.environ\["VERSION"\]/.test(sh) && /os\.environ\["CHANGELOG_FILE"\]/.test(sh),
'expected the python to read VERSION and CHANGELOG_FILE from the environment',
);
assert.ok(
/::error::release-notes:/.test(sh),
'expected an ::error:: when the CHANGELOG has no section for this release',
);
});
console.log(`\nreleaseNotesNoShellInjection: all ${passed} tests passed`);