Skip to content
Open
Prev Previous commit
Next Next commit
channelSignature: keep an own __proto__ wire member inside the signed…
… scope

The standalone canonical reader copied the unsigned envelope with plain
assignment. For an own `__proto__` member, which JSON.parse creates, that
assignment hits the inherited setter and drops the member, so a message
with unsigned content under that name still hashed to the signed bytes
and passed. Copy members as own data properties, and return an `error`
decision instead of throwing when the envelope has no canonical form.
Same class as dacs-sdk GHSA-pjhm-8m5v-v63m; regression tests cover
primitive, null, object and array values and an honest producer that
signs such a member.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KuxqrwyA8kuyT1ZJLUWZWo
  • Loading branch information
pallytin88 and claude committed Oct 12, 2026
commit 07457a5f622634c1cbaec9630d867831d76b2ead
15 changes: 13 additions & 2 deletions src/channelSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,16 @@ function checkProfile(profile: unknown, expected: ExpectedProfile, sessionChanne
return { ok: true, members: identities };
}

/**
* Own-data copy of every member but `signature`. Plain assignment would route
* an own `__proto__` member (which `JSON.parse` creates) through the inherited
* setter and drop it from the signed scope (dacs-sdk GHSA-pjhm-8m5v-v63m).
*/
function withoutSignature(message: Record<string, unknown>): Record<string, unknown> {
const unsigned: Record<string, unknown> = {};
for (const key of Object.keys(message)) {
if (key !== "signature") unsigned[key] = message[key];
if (key === "signature") continue;
Object.defineProperty(unsigned, key, { value: message[key], enumerable: true, writable: true, configurable: true });
}
return unsigned;
}
Expand Down Expand Up @@ -614,7 +620,12 @@ export async function readCanonicalChannelMessage(
if (signature === null) return { decision: "error", reason: "signature value is malformed" };

const unsigned = withoutSignature(message as unknown as Record<string, unknown>);
const hash = messageHashHex(unsigned);
let hash: string;
try {
hash = messageHashHex(unsigned);
} catch {
return { decision: "error", reason: "message has no canonical form" };
}
const verified = await verifyMemberSignature(
message.sender, message.signature.algorithm, signature, canonicalSignedBytes(hash),
profile.members, authority.resolve,
Expand Down
33 changes: 33 additions & 0 deletions test/channelSignature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,36 @@ describe("canonical producer", () => {
expect(result.message?.experimentalHint).toEqual({ future: true });
});
});

describe("own __proto__ members on the wire (dacs-sdk GHSA-pjhm-8m5v-v63m)", () => {
const signer = keyObjectSigner(BUYER, buyerKeys.privateKey);
const readAuthority = {
members: [BUYER, SELLER],
profile: { authenticated: true, sessionId: "chan-sig-1", participantIdentities: [BUYER, SELLER], ...DACS_V06_PROFILE },
expectedProfile: DACS_V06_PROFILE,
resolve: authority.resolve,
};

test("an unsigned __proto__ member added after signing never passes", async () => {
const signed = await signCanonicalChannelMessage(unsigned(1) as never, signer);
for (const value of ['"unsigned-claim: price was 1 USDC"', "1", "null", "true", '{"a":1}', "[1]"]) {
const wire = JSON.parse(JSON.stringify(signed).replace(/^\{/, `{"__proto__":${value},`)) as Record<string, unknown>;
expect(Object.prototype.hasOwnProperty.call(wire, "__proto__")).toBe(true);
const result = await readCanonicalChannelMessage(wire, ctx, readAuthority);
expect(result.decision).not.toBe("pass");
expect(result.message).toBeUndefined();
}
});

test("a producer that signs an own __proto__ member is read back with it", async () => {
const envelope = JSON.parse(JSON.stringify(unsigned(1)).replace(/^\{/, '{"__proto__":{"future":true},')) as Record<string, unknown>;
const signed = await signCanonicalChannelMessage(envelope as never, signer);
const wire = JSON.parse(JSON.stringify(signed)) as Record<string, unknown>;
const result = await readCanonicalChannelMessage(wire, ctx, readAuthority);
expect(result.decision).toBe("pass");
expect(Object.getOwnPropertyDescriptor(result.message, "__proto__")?.value).toEqual({ future: true });
const stripped = JSON.parse(JSON.stringify(wire)) as Record<string, unknown>;
delete stripped["__proto__"];
expect((await readCanonicalChannelMessage(stripped, ctx, readAuthority)).decision).toBe("fail");
});
});