From d9e0318703b1e42e84446fd14389d0b414932bf4 Mon Sep 17 00:00:00 2001 From: EagleFox31 <86088743+EagleFox31@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:11:48 +0100 Subject: [PATCH 1/4] feat: validate bounded Studio release package with strict in-memory TAR layout --- src/studio-staging-release-package.ts | 108 ++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/studio-staging-release-package.ts diff --git a/src/studio-staging-release-package.ts b/src/studio-staging-release-package.ts new file mode 100644 index 0000000..991f932 --- /dev/null +++ b/src/studio-staging-release-package.ts @@ -0,0 +1,108 @@ +// Fixed, in-memory first-release package for Studio. No path extraction, +// code execution, provider call or authorization is performed here. +const MAX_COMPRESSED = 16 * 1024 * 1024; +const MAX_TAR = 32 * 1024 * 1024; +const MAX_MODULE = 8 * 1024 * 1024; +const MAX_MAP = 16 * 1024 * 1024; +const MAX_ASSET = 5 * 1024 * 1024; +const MAX_ENTRIES = 256; +const BLOCK = 512; +const fail = (): never => { throw Error("STUDIO_RELEASE_PACKAGE_INVALID"); }; +const check = (v: unknown) => { if (!v) fail(); }; +const zero = (b: Uint8Array) => b.every(x => x === 0); +const text = (b: Uint8Array) => new TextDecoder("utf-8", {fatal:true}).decode(b); +function field(b:Uint8Array): string { + const end=b.indexOf(0); + if(end<0)return text(b); + check(zero(b.subarray(end))); + return text(b.subarray(0,end)); +} +function octal(b:Uint8Array):number { + const raw=text(b).replace(/[\x00 ]+$/,"").replace(/^ +/,""); + check(/^[0-7]+$/.test(raw)); + const n=Number.parseInt(raw,8); + check(Number.isSafeInteger(n)&&n>=0); + return n; +} +const DIRECTORIES = new Set(["worker","apps/web/dist","apps/web/dist/assets"]); +const ASSET = /^apps\/web\/dist\/(?:index\.html|favicon\.svg|assets\/[A-Za-z0-9][A-Za-z0-9_.-]*\.(?:js|css|woff2|svg|png|webp|jpg|jpeg|ico))$/; +export type StudioReleasePackage = { + module:Uint8Array; + sourceMap:Uint8Array; + assets:ReadonlyMap; +}; +async function inflateBounded(compressed:Uint8Array):Promise{ + check(compressed.length>0&&compressed.length<=MAX_COMPRESSED); + const chunks:Uint8Array[]=[]; + let size=0; + const reader=new Blob([Uint8Array.from(compressed).buffer]).stream() + .pipeThrough(new DecompressionStream("gzip")).getReader(); + try{ + for(;;){ + const {done,value}=await reader.read(); + if(done)break; + size+=value.byteLength; + check(size<=MAX_TAR); + chunks.push(value); + } + const result=new Uint8Array(size); + let offset=0; + for(const chunk of chunks){result.set(chunk,offset);offset+=chunk.length;} + return result; + }finally{await reader.cancel().catch(()=>undefined);reader.releaseLock();} +} + +/** Parse only the archive format emitted by the reviewed GNU tar/gzip workflow. + * A new artifact layout needs explicit review; never follow links or extract to disk. + * The caller must separately authenticate the original artifact and manifest digest. + */ +export async function decodeStudioReleasePackage(compressed:Uint8Array):Promise{ + try{ + const tar=await inflateBounded(compressed); + check(tar.length>=BLOCK*2&&tar.length%BLOCK===0); + const files=new Map(); + const seen=new Set(); + let pos=0,ended=false; + while(pos+BLOCK<=tar.length){ + const header=tar.subarray(pos,pos+BLOCK); + if(zero(header)){ + check(pos+2*BLOCK<=tar.length&&zero(tar.subarray(pos))); + ended=true;break; + } + check(seen.sizesum+(i>=148&&i<156?32:value),0); + check(checksum===octal(header.subarray(148,156))); + check(zero(header.subarray(157,257))); // no linkname + const type=header[156]; + check(type===48||type===53); + const rawName=field(header.subarray(0,100)); + const name=type===53?rawName.replace(/\/$/,""):rawName; + check(!seen.has(name)); + seen.add(name); + const size=octal(header.subarray(124,136)); + const start=pos+BLOCK,end=start+size,next=start+Math.ceil(size/BLOCK)*BLOCK; + check(end<=tar.length&&next<=tar.length&&zero(tar.subarray(end,next))); + if(type===53){ + check(DIRECTORIES.has(name)&&size===0&&rawName===name+"/"); + }else{ + const max=name==="worker/index.js"?MAX_MODULE: + name==="worker/index.js.map"?MAX_MAP: + name==="worker/README.md"?4096: + ASSET.test(name)?MAX_ASSET:0; + check(max>0&&size>0&&size<=max); + files.set(name,tar.subarray(start,end)); + } + pos=next; + } + check(ended&&[...DIRECTORIES].every(d=>seen.has(d))); + const module=files.get("worker/index.js"); + const sourceMap=files.get("worker/index.js.map"); + check(module&&sourceMap&&files.has("apps/web/dist/index.html")); + const assets=new Map(); + for(const [name,bytes] of files) + if(name.startsWith("apps/web/dist/"))assets.set(name.slice("apps/web/dist/".length),bytes); + return {module:module!,sourceMap:sourceMap!,assets}; + }catch{throw Error("STUDIO_RELEASE_PACKAGE_INVALID");} +} From 2c3912a03a76d534046fbae52379b6d9395d8702 Mon Sep 17 00:00:00 2001 From: EagleFox31 <86088743+EagleFox31@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:11:57 +0100 Subject: [PATCH 2/4] feat: bind strict release package extraction to qualified artifact authority --- src/studio-staging-build-evidence.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/studio-staging-build-evidence.ts b/src/studio-staging-build-evidence.ts index bd24e41..6cf5a84 100644 --- a/src/studio-staging-build-evidence.ts +++ b/src/studio-staging-build-evidence.ts @@ -1,3 +1,4 @@ +import { decodeStudioReleasePackage } from "./studio-staging-release-package"; // Fixed Studio pilot. Validation only; no deployment or execution of downloaded files. const REPOSITORY="Trigenys/trigenys-studio"; const WORKFLOW=".github/workflows/staging-build-evidence.yml"; @@ -107,3 +108,12 @@ export async function verifyStudioStagingBuildEvidence(authority:StudioBuildAuth runId:metadata.runId,runAttempt:metadata.runAttempt,artifactId:metadata.artifactId, wrapperDigest:metadata.digest,archiveSha256,liveBindingsVerified:false as const,deploymentAuthorized:false as const}; } + +/** Internal artifact-to-release-package boundary. The original authority, outer + * digest and manifest must qualify before any decompression. No public route. + */ +export async function readVerifiedStudioStagingPackage(authority:StudioBuildAuthority,bytes:Uint8Array,now=Date.now()){ + const receipt=await verifyStudioStagingBuildEvidence(authority,bytes,now); + const archive=readStoredEvidenceZip(bytes).get("staging-build.tar.gz")!; + return {receipt,package:await decodeStudioReleasePackage(archive)}; +} From c2ca076dab8ab4a8718fbc382cc41fb6b6543a70 Mon Sep 17 00:00:00 2001 From: EagleFox31 <86088743+EagleFox31@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:12:19 +0100 Subject: [PATCH 3/4] test: exercise verified artifact extraction and bounded package validation --- test/typescript-staging-recipe.test.mjs | 55 +++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/test/typescript-staging-recipe.test.mjs b/test/typescript-staging-recipe.test.mjs index 922cac7..d06016c 100644 --- a/test/typescript-staging-recipe.test.mjs +++ b/test/typescript-staging-recipe.test.mjs @@ -180,7 +180,9 @@ test("first release preparation rejects wrong repository, config or resource ide const evidenceSource=fs.readFileSync("src/studio-staging-build-evidence.ts","utf8"); -const {validateStudioBuildMetadata,verifyStudioStagingBuildEvidence}=await import(data(compile(evidenceSource))); +const packageUrl=data(compile(fs.readFileSync("src/studio-staging-release-package.ts","utf8"))); +const {decodeStudioReleasePackage}=await import(packageUrl); +const {validateStudioBuildMetadata,verifyStudioStagingBuildEvidence,readVerifiedStudioStagingPackage}=await import(data(compile(evidenceSource).replace('from "./studio-staging-release-package"','from "'+packageUrl+'"'))); const buildHash=async b=>(await import("node:crypto")).createHash("sha256").update(b).digest("hex"); // Minimal two-entry stored ZIP fixture, never extracted or executed. function evidenceZip(files,{descriptor=false,reverse=false}={}){ @@ -197,10 +199,10 @@ function evidenceZip(files,{descriptor=false,reverse=false}={}){ end.writeUInt32LE(0x06054b50);end.writeUInt16LE(files.length,8);end.writeUInt16LE(files.length,10);end.writeUInt32LE(directory.length,12);end.writeUInt32LE(offset,16); return Buffer.concat([...local,directory,end]); } -async function evidenceFixture(patch={},filename="staging-build.tar.gz",zipOptions={}){ +async function evidenceFixture(patch={},filename="staging-build.tar.gz",zipOptions={},packageBytes){ const now=Date.parse("2026-12-04T10:00:00Z"); const repository={id:123,full_name:"Trigenys/trigenys-studio"}; - const archive=(await import("node:zlib")).gzipSync(Buffer.from("synthetic build fixture")); + const archive=packageBytes??(await import("node:zlib")).gzipSync(Buffer.from("synthetic build fixture")); const manifest={schemaVersion:1,kind:"OFFLINE_STAGING_BUILD_ONLY",repository:repository.full_name,revision:releaseRevision,event:"push",runId:"44",runAttempt:"1",nodeVersion:"v24.1.0",worker:identity.worker,sourceConfigSha256:"a".repeat(64),lockfileSha256:"b".repeat(64),archiveSha256:await buildHash(archive),syntheticHyperdrive:true,liveBindingsVerified:false,deployed:false,...patch}; const bytes=evidenceZip([["manifest.json",JSON.stringify(manifest)],[filename,archive]],zipOptions); const authority={revision:releaseRevision,repositoryId:repository.id,workflowBlobSha:"b4667e9202095ba8276723be488d62312b2bd0be",sourceConfigSha256:"a".repeat(64),lockfileSha256:"b".repeat(64), @@ -307,3 +309,50 @@ test("qualification dependency failure returns fixed phase and never provider de const ready=await qualifyStudioStagingReadiness(releaseRevision,readinessFixture().deps); await assert.rejects(qualifyStudioStagingReleaseEvidence(releaseRevision,{readiness:async()=>ready,database:async()=>{throw Error("ROADMAP_DENIED")}}),e=>e.phase==="DATABASE"&&e.message==="ROADMAP_DENIED"); }); + + +// Canonical GNU tar fixture: no filesystem extraction and no executable payload. +function releaseTar(extra=[],omit=[]){ + const entries=[ + ["worker/","5",""],["worker/index.js","0","fixture module"], + ["worker/index.js.map","0","fixture map"],["worker/README.md","0","fixture readme"], + ["apps/web/dist/","5",""],["apps/web/dist/assets/","5",""], + ["apps/web/dist/index.html","0","fixture HTML"],["apps/web/dist/assets/index-fixture.js","0","fixture JS"], + ].filter(([name])=>!omit.includes(name)).concat(extra); + const chunks=[]; + for(const [name,type,value] of entries){ + const header=Buffer.alloc(512),body=Buffer.from(value); + header.write(name,0,100,"utf8"); + header.write(body.length.toString(8).padStart(11,"0")+"\0",124,12,"ascii"); + header.fill(32,148,156); + header.write(type,156,1,"ascii"); + header.write("ustar \0",257,8,"ascii"); + const checksum=header.reduce((a,b)=>a+b,0); + header.write(checksum.toString(8).padStart(6,"0")+"\0 ",148,8,"ascii"); + chunks.push(header,body,Buffer.alloc((512-body.length%512)%512)); + } + return Buffer.concat([...chunks,Buffer.alloc(1024)]); +} +test("verified release package returns only exact module, source map and bounded static assets",async()=>{ + const {gzipSync}=await import("node:zlib"); + const f=await evidenceFixture({},"staging-build.tar.gz",{},gzipSync(releaseTar())); + const result=await readVerifiedStudioStagingPackage(f.authority,f.bytes,f.now); + assert.equal(result.receipt.deploymentAuthorized,false); + assert.equal(Buffer.from(result.package.module).toString(),"fixture module"); + assert.deepEqual([...result.package.assets.keys()],["index.html","assets/index-fixture.js"]); +}); +test("release package refuses unsupported layout, duplicate names, missing files and malformed or oversized archives",async()=>{ + const {gzipSync}=await import("node:zlib"); + for(const tar of [ + releaseTar([["worker/extra.js","0","unexpected"]]), + releaseTar([["apps/web/dist/assets/index-fixture.js","0","duplicate"]]), + releaseTar([["apps/web/dist/assets/other.js","2",""]]), + releaseTar([["apps/web/dist/assets/../other.js","0","unexpected"]]), + releaseTar([],["worker/index.js"]), + releaseTar([],["apps/web/dist/index.html"]), + releaseTar().subarray(0,-512), + Buffer.alloc(33*1024*1024) + ])await assert.rejects(decodeStudioReleasePackage(gzipSync(tar)),/STUDIO_RELEASE_PACKAGE_INVALID/); + const malformed=releaseTar();malformed[0]^=1; + await assert.rejects(decodeStudioReleasePackage(gzipSync(malformed)),/STUDIO_RELEASE_PACKAGE_INVALID/); +}); From 730d2b1b9ea37484c32f87c3e253e14c85c3fa6b Mon Sep 17 00:00:00 2001 From: EagleFox31 <86088743+EagleFox31@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:13:09 +0100 Subject: [PATCH 4/4] docs: record actual Studio package validation and exact-release boundary --- docs/typescript-worker-runtime.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/typescript-worker-runtime.md b/docs/typescript-worker-runtime.md index e9b661d..0de9f68 100644 --- a/docs/typescript-worker-runtime.md +++ b/docs/typescript-worker-runtime.md @@ -171,3 +171,7 @@ Studio #125, main `ca599140cf9e3c2f135e4c85f043f402457874bd`: [offline build](ht ## Qualification failure isolation — 2026-12-04 After #259, Studio run 47372776920 job 145267060105 still returned generic HTTP 503 despite successful database receipt (migration run 47372776967 attempt 3) and offline build. The precise root cause remains unconfirmed. Combined qualification now shares one request-local scoped GitHub read authority across build, historical migration, resources and current DB receipt. All source and freshness checks remain. Dependency failures return a fixed phase AUTHORITY/BUILD/MIGRATION/RESOURCES/DATABASE and a safe allowlisted error code; unknown errors become fixed phase-specific UNAVAILABLE codes, never provider messages, URLs, credentials or response bodies. This improves the diagnosis and removes three redundant authority requests without granting release authority. Studio must run the new broker on the exact current revision, including fresh DB evidence, before any staging deployment claim. No new permission, resource mutation or bypass. + +## First release package — qualified archive, not a rebuild + +Studio main `511e669bd05fcd51ceb987587b1ceae2669c81eb` passed the synchronized qualification (run 47411892451, job 145317300197; all five main workflows green). The observed 503 no longer reproduced after #261, without establishing the historical root cause. DB evidence is time-bound and must be renewed before release execution. Independently downloaded build artifact 15880808630 (run 47411892432 attempt 1): wrapper SHA-256 `2bb08e5045cff8731925bfcba173a4392427389bbbb72eb3b6069e05e3b38fc6`, CRC valid, archive SHA-256 `188605ab0f72c24067258825fee9d23dcc4406f3fb56606ca6b07da18f4ed857`. The real GNU tar contains 16 entries, including the 5904304-byte bundled module and 12686130-byte source map. The new in-memory decoder was exercised against that actual archive under Node 22: exact module SHA-256 `dd0c2668ff6158878ec498156a917a74068892f8bb33dc940eff448d0f8308c8`, ten static assets (645061 bytes total). The existing authority verifier must first validate the original wrapper and manifest. The new internal reader bounds gzip expansion (32 MiB), accepted layout and file sizes; rejects ambiguous paths, unsupported tar types, duplicate entries and invalid checksums. No disk extraction, execution of downloaded JavaScript, or provider call. The original source map is retained separately; deployment must preserve exact module/asset bytes while replacing only the synthetic resource configuration using the existing qualified recipe. No runtime Worker deployment or asset-upload authorization is implied; a provider-side implementation, durable execution claim, renewed database proof and actual readback remain necessary.