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(); });