diff --git a/nats-base-client/protocol.ts b/nats-base-client/protocol.ts index 3d24de9c..9a4aa3a2 100644 --- a/nats-base-client/protocol.ts +++ b/nats-base-client/protocol.ts @@ -65,6 +65,12 @@ export function createInbox(prefix = ""): string { if (typeof prefix !== "string") { throw (new Error("prefix must be a string")); } + prefix.split(".") + .forEach((v) => { + if (v === "*" || v === ">") { + throw new Error(`inbox prefixes cannot have wildcards '${prefix}'`); + } + }); return `${prefix}.${nuid.next()}`; } diff --git a/tests/basics_test.ts b/tests/basics_test.ts index b0df59f9..478b6241 100644 --- a/tests/basics_test.ts +++ b/tests/basics_test.ts @@ -1177,3 +1177,21 @@ Deno.test("basics - close promise resolves", async () => { fail(err); }); }); + +Deno.test("basics - inbox prefixes cannot have wildcards", async () => { + await assertRejects( + async () => { + await connect({ inboxPrefix: "_inbox.foo.>" }); + }, + Error, + "inbox prefixes cannot have wildcards", + ); + + assertThrows( + () => { + createInbox("_inbox.foo.*"); + }, + Error, + "inbox prefixes cannot have wildcards", + ); +});