Skip to content

Commit

Permalink
[FIX] added a check on createInbox() to reject prefixes that contain …
Browse files Browse the repository at this point in the history
…wildcards
  • Loading branch information
aricart committed Feb 6, 2023
1 parent 839642f commit 15ee7d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nats-base-client/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/basics_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});

0 comments on commit 15ee7d5

Please sign in to comment.