Skip to content

feat(site): generate random hex string (non-uuid) for template builder session ID - #27935

Open
aqandrew wants to merge 5 commits into
mainfrom
aqandrew/generate-session-id-helper-function
Open

feat(site): generate random hex string (non-uuid) for template builder session ID#27935
aqandrew wants to merge 5 commits into
mainfrom
aqandrew/generate-session-id-helper-function

Conversation

@aqandrew

@aqandrew aqandrew commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Session ids for template builder telemetry need to be hexadecimal strings, not UUIDs.

  • creates a generateSessionId helper function which reuses our existing generateRandomString logic
  • renames our existing generateRandomString function to be generateRandomBase64String
  • adds tests for utils/random.ts

additional context from #27671 (comment):

I just re-read the RFC; initial functional requirement 1 is:

Clients must generate 16-byte session ID encoded as a 32-character hexadecimal string.

UUIDs don't conform--they include hyphens in addition to hexadecimal chars. So httpmw's validSessionID function (added in this PR) will return false for a UUID.

const sessionId = useMemo(() => uuidv4(), []);

I believe we will need a helper function to generate session IDs for the template builder after all, like #27661, just without the hyphens

Comment thread site/src/utils/random.ts
* Generate a random hexadecimal string from the specified number of bytes.
*/
const generateRandomString = (bytes: number): string => {
const byteArr = crypto.getRandomValues(new Uint8Array(bytes));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

getRandomValues not getRandomBytes 👍
bytes are mapped into hex characters as a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants