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 <diego.resendez@zero-oneit.com>
This commit is contained in:
2 files changed
+9
No files matched your search
@@ -97,6 +97,9 @@ const SHAPE: Record<Frame['type'], ShapeCheck> = {
|
||||
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');
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user