Skip to content

fix(lib): use a cryptographically secure source for async helper ids - #266

Open
mfdebian wants to merge 1 commit into
pillarjs:5.0from
mfdebian:lib-use-safe-random-string
Open

fix(lib): use a cryptographically secure source for async helper ids#266
mfdebian wants to merge 1 commit into
pillarjs:5.0from
mfdebian:lib-use-safe-random-string

Conversation

@mfdebian

@mfdebian mfdebian commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Async helper placeholder ids were being generated with Math.random(). This change swaps that for crypto.randomBytes() since Math.random() exposed them to being guessable.

This carries forward the intent of 361bdd7 authored by @dougwilson, who identified the problem and fixed it with uid-safe. I've decided to not use uid-safe since it looks like it's no longer being maintained and Node.js already includes the needed functionality natively (As I learned on my previous PR to Node.js).

This was one of 2 leftover cherry picks discussed in #244, for 5ee89a1, this branch already dropped support for Express < 4 but this particular change still needed attention.

Credit for the diagnosis and the fix direction belongs to @dougwilson; only the implementation differs.

@mfdebian mfdebian mentioned this pull request Aug 9, 2026
9 tasks
Comment thread lib/async.js
obj.resolve = function resolve (fn) {
const args = Array.prototype.slice.call(arguments, 1)
const id = '__' + genId() + '__'
const id = '__' + randomBytes(10).toString('base64url') + '__'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we could use the uuid function. The only concern is that it has a longer length than the usual one, and I’m not sure if that could affect things here. At least for session, I avoided using it because the longer key could break more things than I intended. But here, I don’t think anything is stored in a database.

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