diff --git a/packages/bus/src/broker.mjs b/packages/bus/src/broker.mjs index ba10609b8..dc586768c 100644 --- a/packages/bus/src/broker.mjs +++ b/packages/bus/src/broker.mjs @@ -6724,10 +6724,13 @@ export class Broker { let role; if (Object.hasOwn(pin, 'inline')) { if (!object(hire.entry) || typeof pin.sha256 !== 'string') fail('invalid-request'); - // The broker's sandbox import closure is fixed, so the digest and the composition are the pure - // local forms: digestPrd is sha256 over sorted-key JSON, the canonicalJson digest SP4 records - // for the parsed file; the composition is definitions.mjs compositionOf. - if (digestPrd(hire.entry) !== pin.sha256) fail('starter-pack-proposal-stale'); + // The broker's sandbox import closure is fixed, so the digest and the composition are local + // copies: canonical is organization util.mjs canonicalJson, built as a string so integer-like + // keys keep the sorted order (an object would put them first), and the composition is + // definitions.mjs compositionOf. + const canonical = v => Array.isArray(v) ? `[${v.map(canonical).join(',')}]` : object(v) + ? `{${Object.keys(v).sort().map(k => `${JSON.stringify(k)}:${canonical(v[k])}`).join(',')}}` : JSON.stringify(v); + if (sha256(canonical(hire.entry)) !== pin.sha256) fail('starter-pack-proposal-stale'); const from = hire.entry.from?.template; if (from !== undefined && (b.launch?.noHire ?? []).includes(from)) fail('definition-not-hireable'); if (!object(hire.entry.role) || typeof hire.entry.instructions !== 'string') fail('invalid-request');