From 414b18879265c7841a73fa3e603c178f7f8921f2 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Sun, 6 Sep 2026 16:25:27 -0500 Subject: [PATCH] fix(mesh): reject a manifest step that is not a string decode is the mesh's trust boundary, reached before the handshake authenticates the peer. The manifest row checked that steps was an array but not what was in it, so {"steps":[123]} decoded cleanly and 123 would have become a graph node name in buildRemote. Signed-off-by: Diego Resendez --- src/mesh/protocol.ts | 3 +++ test/mesh/protocol.test.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/mesh/protocol.ts b/src/mesh/protocol.ts index 3ce3bc3..85d082f 100644 --- a/src/mesh/protocol.ts +++ b/src/mesh/protocol.ts @@ -97,6 +97,9 @@ const SHAPE: Record = { manifest: (frame, bad) => { if (!isNumber(frame.v)) bad('missing protocol version'); if (!Array.isArray(frame.steps) || !Array.isArray(frame.routes)) bad('steps and routes must be arrays'); + // Array.isArray above already guarantees this, but TS does not carry that narrowing through a + // `never`-typed callback parameter — the cast is safe, not a bypass. + if (!(frame.steps as unknown[]).every(isString)) bad('every step must be a string'); }, 'rpc-req': (frame, bad) => { if (!isString(frame.id)) bad('id must be a string'); diff --git a/test/mesh/protocol.test.ts b/test/mesh/protocol.test.ts index 53580d4..67323a8 100644 --- a/test/mesh/protocol.test.ts +++ b/test/mesh/protocol.test.ts @@ -32,6 +32,12 @@ describe('protocol codec', () => { ); }); + it('rejects a manifest whose steps array contains a non-string element', () => { + expect(() => decode(JSON.stringify({ type: 'manifest', v: V, steps: [123], routes: [] }))).toThrow( + /every step must be a string/, + ); + }); + it('throws on malformed json', () => { expect(() => decode('{not json')).toThrow(); });