Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AsyncLocalStorage } from "node:async_hooks";
import { randomUUID } from "node:crypto";

import { IterableClient } from "@iterable/api";
import { logger } from "@iterable/api";
Expand Down Expand Up @@ -234,6 +235,11 @@ export class IterableMcpServer {
}
}

function createSessionId(): string {
return Math.random().toString(36).slice(2) + Date.now().toString(36);
/**
* Generate a cryptographically secure session ID
* Uses crypto.randomUUID() for guaranteed uniqueness and unpredictability
* Exported for testing purposes
*/
export function createSessionId(): string {
return randomUUID();
}
15 changes: 15 additions & 0 deletions tests/unit/session-id.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable simple-import-sort/imports */
import { describe, expect, it } from "@jest/globals";
import { createSessionId } from "../../src/server";

describe("Session ID Generation", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is a standard library do we really need all these tests?

it("generates unique session IDs", () => {
const id1 = createSessionId();
const id2 = createSessionId();
const id3 = createSessionId();

expect(id1).not.toBe(id2);
expect(id2).not.toBe(id3);
expect(id1).not.toBe(id3);
});
});