diff --git a/.github/actions/standalone-release/action.yml b/.github/actions/standalone-release/action.yml index 52e3436..9785904 100644 --- a/.github/actions/standalone-release/action.yml +++ b/.github/actions/standalone-release/action.yml @@ -9,7 +9,7 @@ inputs: required: false default: 'false' verify-only: - description: Check the existing SDK manifest before notes repair without uploading assets. + description: Verify the tagged SDK build and any legacy checksum asset before notes repair. required: false default: 'false' outputs: @@ -117,7 +117,7 @@ runs: any(.assets[]; .name == $name and .state == "uploaded" and .digest == $digest)' echo "digest=$digest" >> "$GITHUB_OUTPUT" - - name: Attach the verified SDK manifest for SDK-capable tags + - name: Check the SDK manifest against any existing release asset id: manifest if: >- success() && steps.build.outcome == 'success' && hashFiles('released-source/scripts/build-sdk.mjs') != '' && @@ -128,18 +128,11 @@ runs: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} RELEASE_TAG: ${{ inputs.tag }} - VERIFY_ONLY: ${{ inputs.verify-only }} run: | manifest="dist/sdk/v1/${RELEASE_TAG#v}/SHA256SUMS" asset="DecodeBox-SDK-$RELEASE_TAG-SHA256SUMS" test -s "$manifest" names=$(gh release view "$RELEASE_TAG" --json assets --jq '.assets[].name') - if ! grep -Fxq "$asset" <<< "$names"; then - if [[ "$VERIFY_ONLY" == true ]]; then - echo "::error::Missing SDK manifest. Run the release_tag rebuild first." - exit 1 - fi - cp "$manifest" "$RUNNER_TEMP/$asset" - gh release upload "$RELEASE_TAG" "$RUNNER_TEMP/$asset" + if grep -Fxq "$asset" <<< "$names"; then + gh release download "$RELEASE_TAG" --pattern "$asset" --output - | cmp - "$manifest" fi - gh release download "$RELEASE_TAG" --pattern "$asset" --output - | cmp - "$manifest" diff --git a/.github/scripts/fixtures/fake-gh.py b/.github/scripts/fixtures/fake-gh.py index e3c5d29..4abb473 100644 --- a/.github/scripts/fixtures/fake-gh.py +++ b/.github/scripts/fixtures/fake-gh.py @@ -38,10 +38,6 @@ def finish(value="", code=0): manifest = f"DecodeBox-SDK-{tag}-SHA256SUMS" if args == ["release", "view", tag, "--json", "assets", "--jq", ".assets[].name"]: finish(manifest if "manifest" in state else "") -if args == ["release", "upload", tag, str(file.parent / manifest)]: - assert "manifest" not in state - state["manifest"] = (file.parent / manifest).read_text() - finish() if args == ["release", "download", tag, "--pattern", manifest, "--output", "-"]: finish(state["manifest"].encode()) if args[:2] == ["release", "upload"]: @@ -80,9 +76,11 @@ def finish(value="", code=0): finish(code=1) line = "* @alice made their first contribution in https://github.com/OWASP/DecodeBox/pull/31" finish({"body": "## New Contributors\n" + line + "\n" + line}) -if method == "GET" and route == "pulls/31": - finish(dict(number=31, merge_commit_sha="a" * 40, user=dict(login="alice"), base=dict(ref="main", repo=dict(full_name="OWASP/DecodeBox")), - merged_at="2026-11-20T00:00:00Z")) +if method == "GET" and route == "commits/" + "a" * 40 + "/pulls?per_page=100&page=1": + if state.get("fault") == "PR lookup": + finish(code=1) + finish([dict(number=31, merge_commit_sha="a" * 40, user=dict(login="alice", html_url="https://github.com/alice"), + base=dict(ref="main", repo=dict(full_name="OWASP/DecodeBox")), merged_at="2026-11-20T00:00:00Z")]) if method == "GET" and route == f"compare/v0.1.1...{tag}?per_page=100&page=1": finish(dict(status="ahead", total_commits=1, commits=[dict(sha="a" * 40)])) if method == "PATCH" and route == f"releases/{release['id']}": diff --git a/.github/scripts/publish-release-notes.cjs b/.github/scripts/publish-release-notes.cjs index 5a6d707..11bec48 100644 --- a/.github/scripts/publish-release-notes.cjs +++ b/.github/scripts/publish-release-notes.cjs @@ -2,9 +2,59 @@ const { execFileSync, spawn } = require('node:child_process'); const { createHash } = require('node:crypto'); const { once } = require('node:events'); +// Use the tagged commit range, including PRs whose commit type is hidden in the changelog. +async function releasePulls(repository, previousTag, tag, api, warn) { + const pulls = new Map(); + for (let page = 1; ; page++) { + const range = await api('GET', `compare/${previousTag}...${tag}?per_page=100&page=${page}`); + const remaining = range.total_commits - (page - 1) * 100; + if (range.status !== 'ahead' || !Number.isSafeInteger(range.total_commits) || + remaining < 1 || range.commits?.length !== Math.min(remaining, 100)) { + throw new Error('Incomplete release comparison.'); + } + for (const { sha } of range.commits) { + if (!/^[a-f0-9]{40}$/.test(sha)) throw new Error('Invalid release commit.'); + for (let batch = 1; ; batch++) { + const associated = await api('GET', `commits/${sha}/pulls?per_page=100&page=${batch}`); + if (!Array.isArray(associated)) throw new Error('Invalid GitHub pull request response.'); + for (const pr of associated) { + if (pr.merge_commit_sha !== sha || !Number.isFinite(Date.parse(pr.merged_at)) || + pr.base?.ref !== 'main' || pr.base.repo?.full_name !== repository || + !Number.isSafeInteger(pr.number) || pr.number < 1) continue; + const { login, html_url: profile } = pr.user ?? {}; + if (typeof login !== 'string' || !/^[a-z\d][a-z\d_-]*(?:\[bot\])?$/i.test(login) || + typeof profile !== 'string' || !/^https:\/\/github\.com\/(?:apps\/)?[a-z\d][a-z\d_-]*$/i.test(profile)) { + warn(`No verified GitHub profile for PR #${pr.number}. Omitting its byline.`); + continue; + } + pulls.set(pr.number, { login, byline: `[@${login}](${profile})` }); + } + if (associated.length < 100) break; + } + } + if (remaining <= 100) return pulls; + } +} + +function creditChanges(changes, repository, pulls) { + const cited = new Set(); + const url = `https://github.com/${repository}/pull/`; + const annotated = changes.replace(/\[#(\d+)\]\((https:\/\/github\.com\/[^)\s]+)\)/g, (link, id, target) => { + const number = Number(id); + if (target !== url + number || !pulls.has(number) || cited.has(number)) return link; + cited.add(number); + return `${link} by ${pulls.get(number).byline}`; + }); + const other = []; + for (const [number, author] of pulls) { + if (!cited.has(number)) other.push(`- [#${number}](${url}${number}) by ${author.byline}`); + } + return other.length ? [annotated, '### Other merged pull requests', other.join('\n')].join('\n\n') : annotated; +} + // GitHub supplies first-time status in generated Markdown, not in a structured field. // Accept its contributor records only, then confirm the PR author and merge via the pulls API. -async function newContributors(repository, previousTag, tag, api, warn) { +async function newContributors(repository, previousTag, tag, pulls, api, warn) { let lines; try { const { body } = await api('POST', 'releases/generate-notes', { @@ -12,7 +62,7 @@ async function newContributors(repository, previousTag, tag, api, warn) { }); lines = body.split(/\r?\n/); } catch { - warn('GitHub contributor metadata is unavailable. Omitting credits.'); + warn('First-time contributor metadata is unavailable. Omitting the New Contributors section.'); return []; } const heading = lines.indexOf('## New Contributors'); @@ -45,46 +95,17 @@ async function newContributors(repository, previousTag, tag, api, warn) { authors.set(number, author); } - const candidates = new Map(); + const credits = []; for (const [login, number] of records) { if (ambiguous.has(login)) continue; - let pr; - try { - pr = await api('GET', `pulls/${number}`); - } catch { - warn(`Contributor metadata for PR #${number} is unavailable. Skipping it.`); - continue; - } - if (!Number.isFinite(Date.parse(pr?.merged_at)) || !/^[a-f0-9]{40}$/.test(pr?.merge_commit_sha) || - pr.base?.ref !== 'main' || pr.base.repo?.full_name !== repository || - typeof pr.user?.login !== 'string' || pr.user.login.toLowerCase() !== login || String(pr.number) !== number) { + const author = pulls.get(Number(number)); + if (author?.login.toLowerCase() !== login) { warn(`Could not confirm the contributor on PR #${number}. Skipping it.`); continue; } - candidates.set(number, pr); - } - if (!candidates.size) return []; - - // A real merged PR for this repository may still belong to a different release. - const shas = new Set(); - const wanted = new Set([...candidates.values()].map(pr => pr.merge_commit_sha)); - try { - for (let page = 1; ; page++) { - const range = await api('GET', `compare/${previousTag}...${tag}?per_page=100&page=${page}`); - const remaining = range.total_commits - (page - 1) * 100; - if (range.status !== 'ahead' || !Number.isSafeInteger(range.total_commits) || - remaining < 1 || range.commits?.length !== Math.min(remaining, 100)) { - throw new Error('Incomplete release comparison.'); - } - for (const commit of range.commits) if (wanted.has(commit.sha)) shas.add(commit.sha); - if (shas.size === wanted.size || remaining <= 100) break; - } - } catch { - warn('Could not verify the release commit range. Omitting credits.'); - return []; + credits.push(`- ${author.byline} made their first contribution in [#${number}](https://github.com/${repository}/pull/${number}).`); } - return [...candidates.values()].filter(pr => shas.has(pr.merge_commit_sha)).map(pr => - `- @${pr.user.login} made their first contribution in [#${pr.number}](https://github.com/${repository}/pull/${pr.number}).`); + return credits; } async function formatNotes(original, tag, repository, api, warn) { @@ -108,13 +129,14 @@ async function formatNotes(original, tag, repository, api, warn) { const current = parts(tag); const difference = current.findIndex((v, i) => v !== previous[i]); if (difference < 0 || current[difference] < previous[difference]) throw new Error('Invalid release version order.'); - const credits = await newContributors(repository, previousTag, tag, api, warn); + const pulls = await releasePulls(repository, previousTag, tag, api, warn); + const credits = await newContributors(repository, previousTag, tag, pulls, api, warn); const title = `OWASP DecodeBox ${tag}`; return [ `# ${title}`, `Changes since [${previousTag}](${comparison}) ยท ${date}`, "## What's Changed", - changes, + creditChanges(changes, repository, pulls), ...(credits.length ? ['## New Contributors', credits.join('\n')] : []), '## Standalone Edition', `Download \`OWASP-DecodeBox-Standalone-${tag}.html\` from the release assets and open it in your browser.`, diff --git a/.github/scripts/verify-release-cli.cjs b/.github/scripts/verify-release-cli.cjs index d3d12e4..11edfcb 100644 --- a/.github/scripts/verify-release-cli.cjs +++ b/.github/scripts/verify-release-cli.cjs @@ -41,7 +41,7 @@ function fixture(t) { fs.mkdirSync(config, { mode: 0o700 }); const env = { PATH: bin, HOME: dir, GH_CONFIG_DIR: config, FAKE_GH_STATE: file, RUNNER_TEMP: dir, GITHUB_OUTPUT: path.join(dir, 'output'), GITHUB_REPOSITORY: 'OWASP/DecodeBox', - REPLACE_STANDALONE: 'false', VERIFY_ONLY: 'false', RELEASE_TAG: tag, RELEASE_ID: '901', RELEASE_VERSION: '0.1.2', + REPLACE_STANDALONE: 'false', RELEASE_TAG: tag, RELEASE_ID: '901', RELEASE_VERSION: '0.1.2', ORIGINAL_TITLE: title, ORIGINAL_NOTES: notes }; function check(r, success) { assert.ifError(r.error); @@ -121,7 +121,8 @@ test('normal release records an idempotent baseline, verifies the build digest, const release = f.read().release; assert.equal(release.name, 'OWASP DecodeBox ' + tag); assert.equal(release.body.split('## Standalone Edition').length, 2); - assert.equal(release.body.split('@alice made their first contribution').length, 2); + assert(release.body.includes('by [@alice](https://github.com/alice)')); + assert.equal(release.body.split('[@alice](https://github.com/alice) made their first contribution').length, 2); assert.match(release.body, /$/)[1]; assert.deepEqual(JSON.parse(Buffer.from(archive, 'base64')), [title, notes]); @@ -253,6 +254,20 @@ test('baseline rechecks the creation response before PATCH', t => { assert.equal(f.read().release.body, 'Maintainer edit before baseline.'); }); +test('an interrupted PR lookup leaves the baseline available for a retry', t => { + const f = fixture(t); + f.cli('baseline'); + f.standalone(); + const baseline = f.read().release.body; + f.fault('PR lookup'); + f.cli('format', false); + assert.equal(f.read().release.body, baseline); + assert.equal(f.patchCount(), 1); + f.fault(); + f.cli('repair'); + assert(f.read().release.body.includes('by [@alice](https://github.com/alice)')); +}); + test('invalid repository and protected tags make no CLI calls', t => { const f = fixture(t); for (const repo of ['', 'OWASP/..', 'a/b/c', 'OWASP/DecodeBox?other']) @@ -264,7 +279,7 @@ test('invalid repository and protected tags make no CLI calls', t => { assert.deepEqual(f.read().calls, []); }); -test('SDK manifest is immutable and repair can only verify it', t => { +test('the release uploads only HTML and still verifies local and legacy SDK manifests', t => { const f = fixture(t); const step = action.find(s => s.id === 'manifest'); const node = action.find(s => s.uses?.startsWith('actions/setup-node@')); @@ -272,18 +287,17 @@ test('SDK manifest is immutable and repair can only verify it', t => { assert.match(action.find(s => s.id === 'build').run, /npm run check:sdk-dist/); const directory = path.join(f.dir, 'dist/sdk/v1/0.1.2'); fs.mkdirSync(directory, { recursive: true }); - fs.writeFileSync(path.join(directory, 'SHA256SUMS'), 'checksums\\n'); - f.env.VERIFY_ONLY = 'true'; - f.shell(step, false); - assert.equal(f.read().manifest, undefined); - f.env.VERIFY_ONLY = 'false'; - f.shell(step); - f.env.VERIFY_ONLY = 'true'; - f.shell(step); + const manifest = 'checksums\n'; + f.shell(step, false); // Missing local manifest. + fs.writeFileSync(path.join(directory, 'SHA256SUMS'), manifest); + f.standalone(); + f.shell(step); // Future releases have no checksum asset. + assert.deepEqual(f.read().calls.filter(([args]) => args[0] === 'release' && args[1] === 'upload'), + [[['release', 'upload', tag, path.join(f.dir, name)], null]]); + f.change(s => { s.manifest = manifest; }); + f.shell(step); // Older releases can already have the matching asset. f.change(s => { s.manifest = 'different bytes'; }); f.shell(step, false); - f.env.VERIFY_ONLY = 'false'; - f.shell(step, false); assert.equal(f.read().manifest, 'different bytes'); }); diff --git a/.github/scripts/verify-release-notes.cjs b/.github/scripts/verify-release-notes.cjs index 0619adf..36f6eba 100644 --- a/.github/scripts/verify-release-notes.cjs +++ b/.github/scripts/verify-release-notes.cjs @@ -60,15 +60,22 @@ async function testPublication(options) { if (generated instanceof Error) throw generated; return { body: generated }; } - if (method === 'GET' && path.startsWith('pulls/')) { - const number = Number(path.slice(6)); - if (number === 38) throw new Error('unavailable'); - const login = { 31: 'regular', 32: 'new-user', 34: 'another-user' }[number]; - assert(login, 'unexpected PR lookup'); - return { number, merge_commit_sha: String(number).padStart(40, '0'), merged_at: '2026-11-20', base: { ref: 'main', repo: { full_name: repository } }, user: { login } }; - } + const included = tag === 'v0.2.0' ? [31, 32, 33, 34, 35, 36] : [31]; if (method === 'GET' && path === `compare/v0.1.1...${tag}?per_page=100&page=1`) - return { status: 'ahead', total_commits: 2, commits: [32, 34].map(n => ({ sha: String(n).padStart(40, '0') })) }; + return { status: 'ahead', total_commits: included.length, commits: included.map(n => ({ sha: mergeShas[n] })) }; + const association = /^commits\/([a-f0-9]{40})\/pulls\?per_page=100&page=1$/.exec(path); + if (method === 'GET' && association) { + const number = included.find(n => mergeShas[n] === association[1]); + assert(number, 'unexpected commit lookup'); + const login = { 31: 'regular', 32: 'new-user', 33: 'regular', 34: 'another-user', + 35: 'dependabot[bot]', 36: 'docs-author' }[number]; + const pr = { ...pull(number), user: { login, html_url: 'https://github.com/' + + (number === 35 ? 'apps/dependabot' : login) } }; + return [pr, pr, { ...pr, number: 37, merge_commit_sha: '9'.repeat(40) }, + { ...pr, number: 38, merged_at: null }, { ...pr, number: 40, base: { ref: 'other' } }, + { ...pr, number: 41, base: { ref: 'main', repo: { full_name: 'another/project' } } }, + { ...pr, number: 42, user: null }, { ...pr, number: 43, user: { login, html_url: 'https://example.org/' } }]; + } assert.equal(path, 'releases/901'); if (method === 'GET') return { ...release }; assert.equal(method, 'PATCH'); @@ -89,18 +96,24 @@ async function testPublication(options) { assert.equal(main.split(url + '/pull/31)').length - 1, 1, 'one PR link for two distinct fixes'); assert.equal((main.match(/\[#33\]/g) || []).length, 1, 'squash title already references its PR'); assert(main.includes('[#33](' + url + '/pull/33)')); - assert(credits.includes('@new-user made their first contribution in [#32](' + url + '/pull/32)')); + assert(main.includes('[#31](' + url + '/pull/31) by [@regular](https://github.com/regular)')); + assert(main.includes('[#33](' + url + '/pull/33) by [@regular](https://github.com/regular)')); + assert(main.includes('by [@dependabot[bot]](https://github.com/apps/dependabot)')); + assert(main.includes('### Other merged pull requests\n\n- [#36](' + url + '/pull/36) by [@docs-author](https://github.com/docs-author)')); + assert(!/\/pull\/(?:37|38|40|41|42|43)\)/.test(main)); + assert(credits.includes('[@new-user](https://github.com/new-user) made their first contribution in [#32](' + url + '/pull/32)')); assert(credits.includes('@another-user') && !credits.includes('@regular') && !credits.includes('@incorrect')); assert.equal((credits.match(/made their first contribution/g) || []).length, 2); - assert.equal(full.calls.filter(([, path]) => path === 'pulls/32').length, 1); - assert(full.warnings.length > 0 && !full.calls.some(([, path]) => path === 'pulls/37')); + assert.equal(full.calls.filter(([, path]) => path === `commits/${mergeShas[32]}/pulls?per_page=100&page=1`).length, 1); + assert(full.warnings.some(message => message.includes('PR #31'))); + assert(full.warnings.some(message => message.includes('No verified GitHub profile for PR #42'))); for (const text of [expected, '## New Contributors', '## Standalone Edition']) assert.equal(full.body.split(text).length, 2); assert(full.body.includes('OWASP-DecodeBox-Standalone-v0.2.0.html') && full.body.includes('open it in your browser')); assert(full.body.includes('offline') && full.body.includes('locally') && full.body.includes('no installation or server')); for (const metadata of [ nativeChanges, '## New Contributors\n' + first('incorrect', 31), - '## New Contributors\n' + first('regular', 31), // Real author, merge outside the tag range. + '## New Contributors\n' + first('regular', 37), // Associated PR, merge outside the tag range. ['## New Contributors', first('new-user', 32), first('new-user', 34)].join('\n'), ['## New Contributors', first('new-user', 32), first('another-user', 32)].join('\n'), ['## New Contributors', first('new-user', 32), '## New Contributors'].join('\n'), @@ -109,6 +122,7 @@ async function testPublication(options) { const result = await exercise(fixes, metadata); assert(result.body.includes('### Fixed') && !result.body.includes('### Added') && !result.body.includes('## New Contributors')); assert(result.body.includes('OWASP-DecodeBox-Standalone-v0.1.2.html')); + assert(result.body.includes('by [@regular](https://github.com/regular)')); if (typeof metadata !== 'string') assert(result.warnings.length); } for (const tag of ['v0.1.0', 'v0.1.1']) await assert.rejects(exercise(fixes, native, { tag }), /protected/); diff --git a/docs/sdk/README.md b/docs/sdk/README.md index e927ab3..3ff863c 100644 --- a/docs/sdk/README.md +++ b/docs/sdk/README.md @@ -101,15 +101,14 @@ any integrity pin your application uses. ### Verify a release -For an official release that includes the SDK, obtain `DecodeBox-SDK-vX.Y.Z-SHA256SUMS` -from the corresponding [OWASP release](https://github.com/OWASP/DecodeBox/releases). -Place the three versioned SDK files and the trusted manifest in one directory. With the actual -release tag substituted in the filename, verify the files. +The versioned SDK directory `/sdk/v1/X.Y.Z/` contains `SHA256SUMS` alongside the classic +bundle, ES module and TypeScript declarations. Download all four files for the same version +and run this command in their directory. ```sh -sha256sum -c DecodeBox-SDK-vX.Y.Z-SHA256SUMS +sha256sum -c SHA256SUMS ``` The digest must cover the exact file your integration loads. A manifest downloaded alongside -a bundle detects corruption. Establish provenance through a separately trusted release or a -digest pinned by your administrator. +a bundle detects corruption. For an independent integrity check, compare the digest with one +pinned by your administrator or build the SDK from a trusted release tag and compare manifests.