fix(packs): SP5 re-check, the inline pin digest is canonicalJson's for integer-like keys (#1873)

digestPrd rebuilds an object, so integer-like keys come first and the JSON
differs from canonicalJson, the digest the pack apply records. An inline
entry with such a key (a credential scope map group) refused as stale on
every raise. The broker now builds the canonical string itself, a local copy
of util.mjs canonicalJson, so the sandbox import closure is unchanged.
This commit was merged in pull request #1957.
This commit is contained in:
jason.woltje committed 2026-11-12 19:05:33 -06:00
1 parent 808b2b7cbf
commit 34dd331016
1 file changed
+7 -4
+7 -4
View File
@@ -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');