提交记录修改docs/public-releases.md+2 −0看文件
修改www/scripts/sync-release.mjs+47 −5看文件
修改www/scripts/sync-release.test.mjs+45 −1看文件
| @@ -35,6 +35,8 @@ node scripts/prepare-release-assets.mjs \ | ||
| 35 | 35 | |
| 36 | 36 | 人工公开发布 Release 会运行 `Website and public releases`:匿名下载附件,核对 SHA-256、应用版本、Developer ID 签名、公证票据与 Gatekeeper;通过后重建并部署主页。自动发布入口直接调用同一网站流程。草稿不会进入公开下载列表;编辑历史 Release 不自动重新部署网站。验收失败时,该轮主页部署停止,维护者应检查 Actions 日志并修正发行物。 |
| 37 | 37 | |
| 38 | 新增:GitHub 匿名 API 的额度耗尽时,指定版本的验证流程从该版本公开的 SHA256SUMS 和附件响应重建下载清单。此路径不使用维护者令牌;清单只能包含该版本安装包和允许的源码附件,所有文件仍须匿名下载并通过摘要、签名与公证检查。没有指定版本的自动列表检查继续报告 API 限流。 | |
| 39 | 新增: | |
| 38 | 40 | 版本标签对应的源码须包含发布工作流。需要复验时,使用下文带 `release_tag` 的手动命令。 |
| 39 | 41 | |
| 40 | 42 | GitHub Release 一旦公开,应用内更新即可读到它,早于这项事后检查完成。因此,本地打包验收必须在发布草稿前通过,不能依赖 Actions 作为安装包公开前的审批门槛。CI 中若用默认 `GITHUB_TOKEN` 发布 Release,不会触发后续工作流,须另外显式调用网站工作流;手工网页发布或 `gh` 用户凭据发布会正常触发。 |
| @@ -1,4 +1,4 @@ | ||
| 1 | 删除:// Use anonymous public endpoints: a maintainer token must not hide download failures. | |
| 1 | 新增:// Public downloads and metadata stay anonymous, including the manifest fallback. | |
| 2 | 2 | import { createHash } from 'node:crypto'; |
| 3 | 3 | import { createWriteStream } from 'node:fs'; |
| 4 | 4 | import { mkdir, writeFile, rm } from 'node:fs/promises'; |
| @@ -12,15 +12,57 @@ const repository = 'Lee-xeo/Claude-Cage'; | ||
| 12 | 12 | const repoURL = `https://github.com/${repository}`; |
| 13 | 13 | const apiURL = `https://api.github.com/repos/${repository}/releases`; |
| 14 | 14 | |
| 15 | 删除:async function request(url, timeout = 180_000) { | |
| 16 | 删除: const response = await fetch(url, { | |
| 17 | 删除: headers: { 'User-Agent': 'Cage-Release-Verification', Accept: url.startsWith(apiURL) ? 'application/vnd.github+json' : 'application/octet-stream' }, | |
| 15 | 新增:export async function request(url, timeout = 180_000, { fetchImpl = fetch } = {}) { | |
| 16 | 新增: const target = new URL(url); | |
| 17 | 新增: const metadata = target.origin === 'https://api.github.com' && | |
| 18 | 新增: (target.pathname === `/repos/${repository}/releases` || target.pathname.startsWith(`/repos/${repository}/releases/`)); | |
| 19 | 新增: const options = { | |
| 20 | 新增: headers: { 'User-Agent': 'Cage-Release-Verification', Accept: metadata ? 'application/vnd.github+json' : 'application/octet-stream' }, | |
| 18 | 21 | signal: AbortSignal.timeout(timeout), |
| 19 | 删除: }); | |
| 22 | 新增: }; | |
| 23 | 新增: let response = await fetchImpl(url, options); | |
| 24 | 新增: if (metadata && response.status === 403 && response.headers.get('x-ratelimit-remaining') === '0') { | |
| 25 | 新增: const tag = target.pathname.match(/^\/repos\/Lee-xeo\/Claude-Cage\/releases\/tags\/(v\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/)?.[1]; | |
| 26 | 新增: if (tag) { | |
| 27 | 新增: await response.body?.cancel(); | |
| 28 | 新增: console.warn('Anonymous GitHub API is rate limited; reading the requested version from its public checksum manifest.'); | |
| 29 | 新增: return new Response(JSON.stringify(await publicManifestRelease(tag, fetchImpl))); | |
| 30 | 新增: } | |
| 31 | 新增: } | |
| 20 | 32 | if (!response.ok) throw new Error(`Public download failed: HTTP ${response.status} (${new URL(url).pathname})`); |
| 21 | 33 | return response; |
| 22 | 34 | } |
| 23 | 35 | |
| 36 | 新增:export async function publicManifestRelease(tag, fetchImpl = fetch) { | |
| 37 | 新增: if (!/^v\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(tag)) throw new Error('Invalid public release tag'); | |
| 38 | 新增: const base = `${repoURL}/releases/download/${tag}/`; | |
| 39 | 新增: const manifest = await request(`${base}SHA256SUMS`, 180_000, { fetchImpl }); | |
| 40 | 新增: const text = await manifest.text(); | |
| 41 | 新增: if (!text.length || Buffer.byteLength(text) > 65536) throw new Error('Invalid public checksum manifest size'); | |
| 42 | 新增: const names = new Map(); | |
| 43 | 新增: for (const line of text.split(/\r?\n/).filter(Boolean)) { | |
| 44 | 新增: const match = /^([a-f0-9]{64}) [ *]([A-Za-z0-9][A-Za-z0-9._-]*)$/i.exec(line); | |
| 45 | 新增: if (!match || names.has(match[2])) throw new Error('Invalid or duplicate public checksum entry'); | |
| 46 | 新增: names.set(match[2], match[1].toLowerCase()); | |
| 47 | 新增: } | |
| 48 | 新增: const version = tag.slice(1); | |
| 49 | 新增: const allowed = name => [ | |
| 50 | 新增: `Cage-${version}-macos-arm64.dmg`, `Cage-${version}-windows-amd64-setup.exe`, | |
| 51 | 新增: `Cage-${version}-windows-amd64-setup-unsigned.exe`, `Cage-${version}-linux-amd64.deb`, | |
| 52 | 新增: ].includes(name) || /^mihomo-v[\d.]+-source\.tar\.gz$/.test(name) || /^qemu-[0-9a-f]{40}-source\.tar\.gz$/.test(name); | |
| 53 | 新增: if ([...names.keys()].some(name => !allowed(name))) throw new Error('Unexpected public release asset'); | |
| 54 | 新增: const assets = [{ name: 'SHA256SUMS', state: 'uploaded', size: Buffer.byteLength(text), browser_download_url: `${base}SHA256SUMS` }]; | |
| 55 | 新增: for (const [name, digest] of names) { | |
| 56 | 新增: const response = await fetchImpl(`${base}${name}`, { method: 'HEAD', headers: { 'User-Agent': 'Cage-Release-Verification' }, signal: AbortSignal.timeout(180_000) }); | |
| 57 | 新增: const size = Number(response.headers.get('content-length')); | |
| 58 | 新增: if (!response.ok || !Number.isSafeInteger(size) || size <= 0 || size > 512 * 1024 * 1024) throw new Error(`Missing or incomplete public asset: ${name}`); | |
| 59 | 新增: assets.push({ name, state: 'uploaded', size, digest: `sha256:${digest}`, browser_download_url: `${base}${name}` }); | |
| 60 | 新增: } | |
| 61 | 新增: const release = { tag_name: tag, draft: false, prerelease: version.includes('-'), assets }; | |
| 62 | 新增: releaseAssets(release); | |
| 63 | 新增: return release; | |
| 64 | 新增:} | |
| 65 | 新增: | |
| 24 | 66 | export function releaseAssets(release) { |
| 25 | 67 | if (release.draft || !/^v\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(release.tag_name)) { |
| 26 | 68 | throw new Error('Expected a published Cage version tag'); |
| @@ -6,7 +6,51 @@ import { join } from 'node:path'; | ||
| 6 | 6 | import { spawnSync } from 'node:child_process'; |
| 7 | 7 | import { fileURLToPath } from 'node:url'; |
| 8 | 8 | import { test } from 'node:test'; |
| 9 | 删除:import { releaseAssets, checksumFor, releaseMetadata } from './sync-release.mjs'; | |
| 9 | 新增:import { releaseAssets, checksumFor, releaseMetadata, request, publicManifestRelease } from './sync-release.mjs'; | |
| 10 | 新增: | |
| 11 | 新增:test('exhausted version API falls back to anonymous public manifest and attachment checks', async () => { | |
| 12 | 新增: const calls = []; | |
| 13 | 新增: const tag = 'v0.2.0'; | |
| 14 | 新增: const manifest = `${'a'.repeat(64)} Cage-0.2.0-macos-arm64.dmg\n${'b'.repeat(64)} mihomo-v1.19.33-source.tar.gz\n`; | |
| 15 | 新增: const fetchImpl = async (url, options) => { | |
| 16 | 新增: calls.push({ url, ...options }); | |
| 17 | 新增: assert.equal(options.headers.Authorization, undefined); | |
| 18 | 新增: if (url.startsWith('https://api.github.com/')) return new Response('', { status: 403, headers: { 'x-ratelimit-remaining': '0' } }); | |
| 19 | 新增: if (url.endsWith('/SHA256SUMS')) return new Response(manifest); | |
| 20 | 新增: assert.equal(options.method, 'HEAD'); | |
| 21 | 新增: return new Response('', { headers: { 'content-length': '100' } }); | |
| 22 | 新增: }; | |
| 23 | 新增: const response = await request(`https://api.github.com/repos/Lee-xeo/Claude-Cage/releases/tags/${tag}`, 1000, { fetchImpl }); | |
| 24 | 新增: assert.equal(releaseAssets(await response.json()).version, '0.2.0'); | |
| 25 | 新增: assert.equal(calls.length, 4); | |
| 26 | 新增:}); | |
| 27 | 新增: | |
| 28 | 新增:test('ordinary API errors, unversioned lists and other origins do not use a fallback', async () => { | |
| 29 | 新增: for (const [url, status, headers] of [ | |
| 30 | 新增: ['https://api.github.com/repos/Lee-xeo/Claude-Cage/releases/tags/v0.2.0', 404, {}], | |
| 31 | 新增: ['https://api.github.com/repos/Lee-xeo/Claude-Cage/releases/tags/v0.2.0', 403, {}], | |
| 32 | 新增: ['https://api.github.com/repos/Lee-xeo/Claude-Cage/releases', 403, { 'x-ratelimit-remaining': '0' }], | |
| 33 | 新增: ['https://github.com/Lee-xeo/Claude-Cage/releases/download/v0.2.0/SHA256SUMS', 403, { 'x-ratelimit-remaining': '0' }], | |
| 34 | 新增: ['https://example.test/repos/Lee-xeo/Claude-Cage/releases', 403, { 'x-ratelimit-remaining': '0' }], | |
| 35 | 新增: ]) { | |
| 36 | 新增: let count = 0; | |
| 37 | 新增: await assert.rejects(request(url, 1000, { fetchImpl: async (_url, options) => { | |
| 38 | 新增: count++; assert.equal(options.headers.Authorization, undefined); | |
| 39 | 新增: return new Response('', { status, headers }); | |
| 40 | 新增: } })); | |
| 41 | 新增: assert.equal(count, 1); | |
| 42 | 新增: } | |
| 43 | 新增:}); | |
| 44 | 新增: | |
| 45 | 新增:test('manifest fallback rejects missing bytes, duplicate digests, traversal and wrong versions', async () => { | |
| 46 | 新增: const valid = `${'a'.repeat(64)} Cage-0.2.0-macos-arm64.dmg\n${'b'.repeat(64)} mihomo-v1.19.33-source.tar.gz\n`; | |
| 47 | 新增: for (const [text, missing] of [[valid, true], [valid + valid, false], [valid.replace('Cage-', '../Cage-'), false], [valid.replace('0.2.0-macos', '0.1.0-macos'), false], ['', false]]) { | |
| 48 | 新增: await assert.rejects(publicManifestRelease('v0.2.0', async (url) => { | |
| 49 | 新增: if (url.endsWith('/SHA256SUMS')) return new Response(text); | |
| 50 | 新增: return new Response('', { status: missing ? 404 : 200, headers: { 'content-length': '100' } }); | |
| 51 | 新增: })); | |
| 52 | 新增: } | |
| 53 | 新增:}); | |
| 10 | 54 | |
| 11 | 55 | const hash = 'a'.repeat(64); |
| 12 | 56 | function fixture() { |

