From ac02941663a1a9917896f790a6ab83b8ba9cd15a Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Sat, 15 Aug 2026 21:33:50 +0300 Subject: [PATCH] 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 ! --- .github/workflows/release-all.yml | 91 ++++++-------- releases/release-notes.sh | 76 ++++++++++++ tests/buildScriptParity.test.cjs | 5 + tests/releaseNotesNoShellInjection.test.cjs | 125 ++++++++++++++------ 4 files changed, 208 insertions(+), 89 deletions(-) create mode 100755 releases/release-notes.sh diff --git a/.github/workflows/release-all.yml b/.github/workflows/release-all.yml index cc90207194..aacf5c04f0 100644 --- a/.github/workflows/release-all.yml +++ b/.github/workflows/release-all.yml @@ -226,7 +226,11 @@ jobs: runs-on: ubuntu-latest outputs: version: ${{ steps.version.outputs.version }} - changelog: ${{ steps.changelog.outputs.content }} + # No `changelog:` output. The notes are 170 KB and more, which is past the + # 128 KiB MAX_ARG_STRLEN a single environment variable may hold, so any job + # consuming them through `env:` fails to start its shell. Jobs read + # CHANGELOG.md from their own checkout instead - see + # "Check the release notes exist in CHANGELOG.md" below. steps: - uses: actions/checkout@v7 with: @@ -252,47 +256,20 @@ jobs: git push origin "v$VERSION" fi - - name: Extract release notes from CHANGELOG.md - id: changelog + # The notes are validated HERE, where a missing CHANGELOG section is still + # cheap to fix, but they are NOT carried to the release job as a job + # output. They were, and it broke v10.92: 172,458 characters reached the + # release step as `env: CHANGELOG:`, and Linux caps a single argv/envp + # string at MAX_ARG_STRLEN - 128 KiB - so execve refused to start bash at + # all ("Argument list too long") before a line of the step ran. Each job + # that needs the notes now extracts them from its own checkout of + # CHANGELOG.md with the same script, straight into a file. + - name: Check the release notes exist in CHANGELOG.md run: | + set -euo pipefail VERSION="${{ steps.version.outputs.version }}" - # Prefer a version-specific "# v ..." section, otherwise fall - # back to the topmost "# Upcoming/Upcomig WeKan ® release" section. - NOTES=$(python3 - <" is the fallback the script above prints when it finds - # NEITHER a "# v" section nor an "# Upcoming" one - i.e. the - # release would be published with no notes at all. Say so here, where the - # cause is still obvious, instead of shipping an empty release page. - if [ -z "${NOTES//[[:space:]]/}" ]; then - echo "::error::prepare: the release notes came out EMPTY. CHANGELOG.md must have a '# v$VERSION ...' section, or an '# Upcoming WeKan (R) release' section to use." - exit 1 - fi - if [ "$NOTES" = "WeKan v$VERSION" ]; then - echo "::error::prepare: CHANGELOG.md has no section for v$VERSION and no '# Upcoming WeKan (R) release' section, so the release would have no notes. Add the section and re-run." - exit 1 - fi - echo "OK: release notes are $(printf '%s' "$NOTES" | wc -l) lines / $(printf '%s' "$NOTES" | wc -c) characters." - { - echo "content<> "$GITHUB_OUTPUT" + bash releases/release-notes.sh "$VERSION" > release-notes-body.md + echo "OK: release notes are $(wc -l < release-notes-body.md) lines / $(wc -c < release-notes-body.md) characters." # Always, as the last step: the run summary then answers "what worked and what # did not" for the whole release at a glance, instead of eighteen job logs. A @@ -990,7 +967,12 @@ jobs: # 404'd on wekan--amd64.zip - v10.63 and v10.64 both. Checking out # first, then downloading on top, keeps the bundles. (The checkout is here # for the provenance script under releases/.) + # ref: main, the same ref `prepare` read CHANGELOG.md from, so the notes + # composed below are the ones prepare validated. (bump pushes to main and + # prepare tags it; nothing else pushes during a release.) - uses: actions/checkout@v7 + with: + ref: main - name: Download all bundles uses: actions/download-artifact@v8 @@ -1007,19 +989,17 @@ jobs: merge-multiple: true - name: Compose the release notes, provenance first - # CHANGELOG goes through the environment, NOT inline `${{ }}` in the - # script. Interpolated into the run: text it becomes part of the shell - # source, so a backtick in an entry (every `code` span - and this release - # is full of them) runs as a command: the v10.59 notes turned into - # "Incorrect: command not found", "loginFailureDecision.js: Permission - # denied", and the release job failed. As "$CHANGELOG", the value is - # data the shell never parses, so backticks, $(), quotes stay literal. - env: - CHANGELOG: ${{ needs.prepare.outputs.changelog }} + # The notes go from FILE to FILE and never become a shell value. Two + # earlier shapes each broke a release: inline `${{ … }}` put them in the + # shell SOURCE, so a backtick in any `code` span ran as a command (v10.59 + # published nothing, "Incorrect: command not found"); and `env:` put a + # 172 KB string in envp, past the 128 KiB MAX_ARG_STRLEN, so execve + # refused to start bash at all (v10.92, "Argument list too long"). Read + # from CHANGELOG.md, appended with cat, the text is data all the way. run: | set -euo pipefail bash releases/provenance-table.sh > release-notes.md || true - printf '%s\n' "$CHANGELOG" >> release-notes.md + bash releases/release-notes.sh "$VERSION" >> release-notes.md echo "----- release notes -----" head -40 release-notes.md @@ -5020,7 +5000,10 @@ jobs: if: ${{ always() && needs.release.result == 'success' }} runs-on: ubuntu-24.04 steps: + # ref: main, so this job reads the same CHANGELOG.md the release job did. - uses: actions/checkout@v7 + with: + ref: main - uses: actions/download-artifact@v8 continue-on-error: true @@ -5030,19 +5013,17 @@ jobs: merge-multiple: true - name: Rewrite the notes with every bundle in the table - # CHANGELOG through the environment, not inline `${{ }}`: interpolated - # into the script a backtick in an entry runs as a command. See the - # "Compose the release notes" step for the full story. + # File to file, never a shell value: see the "Compose the release notes" + # step for the two ways that broke a release. env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ needs.prepare.outputs.version }} - CHANGELOG: ${{ needs.prepare.outputs.changelog }} run: | set -euo pipefail rows=$(find provenance -name '*.tsv' 2>/dev/null | wc -l) echo "Provenance files collected: $rows" bash releases/provenance-table.sh > release-notes.md || true - printf '%s\n' "$CHANGELOG" >> release-notes.md + bash releases/release-notes.sh "$VERSION" >> release-notes.md gh release edit --repo "${GITHUB_REPOSITORY:-wekan/wekan}" "v${VERSION}" --notes-file release-notes.md echo "Release notes updated with the provenance of every bundle built." head -40 release-notes.md diff --git a/releases/release-notes.sh b/releases/release-notes.sh new file mode 100755 index 0000000000..b10c0f68c1 --- /dev/null +++ b/releases/release-notes.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +# Print the CHANGELOG.md section that is this release's notes, to stdout. +# +# Usage: releases/release-notes.sh [changelog-file] +# +# WHY THIS IS A FILE-TO-FILE PATH AND NEVER A VARIABLE +# +# The notes are the whole newest CHANGELOG section - 172,458 characters for +# v10.92 - and there are two ways to hand a string that size to a shell step, +# both of which have already broken a release: +# +# * Inline `${{ needs.prepare.outputs.changelog }}` inside 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" and published nothing. +# +# * Through the ENVIRONMENT - `env: CHANGELOG: ${{ … }}` then "$CHANGELOG" - +# which fixed the backticks and then hit a harder wall. Linux caps a SINGLE +# argv/envp string at MAX_ARG_STRLEN, 128 KiB, and the notes passed it: +# v10.92's release job failed before running a line of the script, with +# "An error occurred trying to start process '/usr/bin/bash' … Argument list +# too long". Nothing in the step is wrong; execve refuses to start it. +# +# So the notes never become an argument, an environment variable or a job +# output. They are read from CHANGELOG.md in the workspace and written to a +# file, and only file PATHS are passed around - which has no size limit, and +# leaves the text as data that no shell ever parses. +set -euo pipefail + +VERSION="${1:-}" +CHANGELOG_FILE="${2:-CHANGELOG.md}" + +if [ -z "$VERSION" ]; then + echo "usage: releases/release-notes.sh [changelog-file]" >&2 + exit 2 +fi +if [ ! -r "$CHANGELOG_FILE" ]; then + echo "::error::release-notes: cannot read $CHANGELOG_FILE" >&2 + exit 1 +fi + +# Prefer a version-specific "# v …" section; otherwise the topmost +# "# Upcoming/Upcomig WeKan ® release" one. The python reads the file itself and +# writes to stdout, so the notes never pass through the shell. +NOTES_FILE="$(mktemp)" +trap 'rm -f "$NOTES_FILE"' EXIT + +VERSION="$VERSION" CHANGELOG_FILE="$CHANGELOG_FILE" python3 - > "$NOTES_FILE" <<'PYEOF' +import os +import re +import sys + +version = os.environ["VERSION"] +with open(os.environ["CHANGELOG_FILE"], encoding="utf-8") as f: + content = f.read() + +patterns = [ + rf"(# v{re.escape(version)} .*?)(?=\n# v[0-9]|\Z)", + r"(# Upcom\w* WeKan.*?)(?=\n# v[0-9]|\Z)", +] +for pat in patterns: + m = re.search(pat, content, re.DOTALL) + if m: + print(m.group(1).strip()) + sys.exit(0) +# Neither section exists. Print nothing; the caller turns that into an error +# with a message that says what to add, rather than publishing an empty release. +sys.exit(0) +PYEOF + +if [ ! -s "$NOTES_FILE" ] || [ -z "$(tr -d '[:space:]' < "$NOTES_FILE")" ]; then + echo "::error::release-notes: $CHANGELOG_FILE has no '# v$VERSION …' section and no '# Upcoming WeKan (R) release' section, so the release would have no notes. Add the section and re-run." >&2 + exit 1 +fi + +cat "$NOTES_FILE" diff --git a/tests/buildScriptParity.test.cjs b/tests/buildScriptParity.test.cjs index 23038b00ef..495e0b32b4 100644 --- a/tests/buildScriptParity.test.cjs +++ b/tests/buildScriptParity.test.cjs @@ -222,6 +222,11 @@ test('every script in releases/ is reachable from BOTH menus', () => { 'fetch.sh': 'release-workflow: the downloader every build job, and the\n preflight, and the Dockerfile use - it waits out a 503 and tells that\n apart from a 404, and has no release step of its own', 'npm-retry.sh': 'release-workflow: the wrapper the build jobs run their\n npm installs through, inside the container as well as on the runner -\n it retries a 503 and runs no release step of its own', 'provenance-table.sh': 'release-workflow: called by the release job', + 'release-notes.sh': 'release-workflow: prints the CHANGELOG section that is\n' + + ' a release\'s notes, called by prepare, the release job and the notes\n' + + ' rewrite. It exists so the text goes file-to-file and never becomes an\n' + + ' argument or an environment variable - 172 KB of notes is past the\n' + + ' 128 KiB MAX_ARG_STRLEN, and v10.92 failed to start bash at all', 'ferretdb-latest-tag.sh': 'release-workflow: a lookup the build jobs call so\n the provenance table can name the version `latest` resolved to - it prints\n a tag and downloads nothing', 'repack-bundle-for-arch.sh': 'release-workflow: needs ./bundle, docker and ' + 'QEMU already set up by the build job around it', diff --git a/tests/releaseNotesNoShellInjection.test.cjs b/tests/releaseNotesNoShellInjection.test.cjs index 67441e2bb3..7ec51db10d 100644 --- a/tests/releaseNotesNoShellInjection.test.cjs +++ b/tests/releaseNotesNoShellInjection.test.cjs @@ -1,21 +1,33 @@ 'use strict'; -// Plain-Node guard against shell injection when composing release notes. +// 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 (`needs.prepare.outputs.changelog`). That text is arbitrary markdown — -// every `code` span is a backtick. If it is interpolated into a `run:` script as -// inline `${{ needs.prepare.outputs.changelog }}`, GitHub substitutes it into the -// shell SOURCE before bash parses it, so a backtick runs as a command: the v10.59 -// release job died with "Incorrect: command not found", -// "loginFailureDecision.js: Permission denied", … and published nothing. The -// value must instead reach the script through the ENVIRONMENT (`env: CHANGELOG: -// ${{ … }}` then `"$CHANGELOG"`), where the shell treats it as data and never -// parses its backticks, `$( )`, or quotes. +// 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: // -// This pins that `outputs.changelog` is only ever consumed as an `env:` -// assignment, never inline inside a run: script. +// 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'); @@ -36,11 +48,7 @@ const files = fs .filter((f) => /\.ya?ml$/.test(f)) .map((f) => path.join('.github/workflows', f)); -// The only safe shape for consuming the changelog output: an env assignment, -// e.g. ` CHANGELOG: ${{ needs.prepare.outputs.changelog }}`. Anything -// else - printf, echo, a bare line inside a run: block - is the injection. -const ENV_ASSIGN = /^\s*[A-Za-z_][A-Za-z0-9_]*:\s*\$\{\{[^}]*\.outputs\.changelog[^}]*\}\}\s*$/; -const USES_CHANGELOG = /\.outputs\.changelog/; +const read = (rel) => fs.readFileSync(path.join(repoRoot, rel), 'utf8'); test('a release workflow exists to check', () => { assert.ok( @@ -49,35 +57,84 @@ test('a release workflow exists to check', () => { ); }); -test('outputs.changelog is only ever consumed through env:, never inline in a script', () => { +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) { - const lines = fs.readFileSync(path.join(repoRoot, rel), 'utf8').split('\n'); - lines.forEach((line, i) => { - if (!USES_CHANGELOG.test(line)) return; - if (ENV_ASSIGN.test(line)) return; // the safe form - offenders.push(`${rel}:${i + 1}: ${line.trim()}`); + 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, [], - `changelog interpolated where a backtick would run as a command:\n${offenders.join('\n')}`, + `the release notes are passed as a job output again:\n${offenders.join('\n')}`, ); }); -test('every step that reads the changelog into a script uses "$CHANGELOG", not ${{ }}', () => { - // Wherever a script writes the changelog into release-notes.md, it must - // reference the environment variable, so the safe env: path is actually used. +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) { - const text = fs.readFileSync(path.join(repoRoot, rel), 'utf8'); - // A printf/echo that pipes the changelog into the notes must use "$CHANGELOG". - const badPrintf = /printf[^\n]*\$\{\{[^}]*\.outputs\.changelog/; - assert.ok( - !badPrintf.test(text), - `${rel}: a printf feeds \${{ …changelog }} straight into the shell; use "$CHANGELOG" from env instead`, - ); + 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`);