-
Notifications
You must be signed in to change notification settings - Fork 1.4k
UBERF-9747 #8867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
UBERF-9747 #8867
Conversation
Connected to Huly®: UBERF-10522 |
const employee = await ensureEmployee( | ||
ctx, | ||
accountRef, | ||
newClient, | ||
workspaceLoginInfo.workspace, | ||
Array.from(accountRef.fullSocialIds.values()), | ||
getGlobalPerson | ||
) |
Check failure
Code scanning / CodeQL
Insecure randomness High
Math.random()
This uses a cryptographically insecure random number generated at
Math.random()
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 14 days ago
To fix the issue, we need to replace the use of Math.random()
with a cryptographically secure random number generator. In Node.js, the crypto
module provides a secure method for generating random values. Specifically, we can use crypto.randomBytes
to generate random bytes and convert them to a hexadecimal string.
The changes will involve:
- Replacing the
Math.random()
calls inpackages/core/src/utils.ts
with a secure random value generated usingcrypto.randomBytes
. - Updating the
random
variable ingenerateId
to use the secure random value.
-
Copy modified lines R64-R67
@@ -63,4 +63,6 @@ | ||
|
||
let counter = (Math.random() * (1 << 24)) | 0 | ||
const random = toHex((Math.random() * (1 << 24)) | 0, 6) + toHex((Math.random() * (1 << 16)) | 0, 4) | ||
import { randomBytes } from 'crypto'; | ||
|
||
let counter = (randomBytes(3).readUIntBE(0, 3)) | 0; | ||
const random = toHex(randomBytes(3).readUIntBE(0, 3), 6) + toHex(randomBytes(2).readUIntBE(0, 2), 4); | ||
|
Signed-off-by: Andrey Sobolev <[email protected]>
|
||
const session = this.createSession(token, workspace.wsId, account) | ||
session.sessionId = sessionId !== undefined && (sessionId ?? '').trim().length > 0 ? sessionId : generateId() |
Check failure
Code scanning / CodeQL
Insecure randomness High
Math.random()
This uses a cryptographically insecure random number generated at
Math.random()
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 14 days ago
To fix the issue, replace the insecure Math.random()
usage in the generateId()
function with a cryptographically secure random number generator. Specifically, use crypto.randomUUID()
or crypto.getRandomValues()
to generate secure random values. This ensures that the generated sessionId
is unpredictable and suitable for security-sensitive contexts.
Steps to implement the fix:
- Modify the
generateId()
function inpackages/core/src/utils.ts
to usecrypto.getRandomValues()
for generating random values instead ofMath.random()
. - Ensure that the replacement maintains the same functionality (e.g., hexadecimal formatting and concatenation).
- Update the imports if necessary to include the
crypto
module.
-
Copy modified lines R64-R65
@@ -63,4 +63,4 @@ | ||
|
||
let counter = (Math.random() * (1 << 24)) | 0 | ||
const random = toHex((Math.random() * (1 << 24)) | 0, 6) + toHex((Math.random() * (1 << 16)) | 0, 4) | ||
let counter = 0 | ||
const random = toHex(crypto.getRandomValues(new Uint32Array(1))[0], 8) + toHex(crypto.getRandomValues(new Uint16Array(1))[0], 4) | ||
|
No description provided.