Skip to content
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

fix: github code scanning alerts #17612

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: 'CodeQL'
on:
schedule:
- cron: '0 10 * * MON'
pull_request:
# we want to run the CI on every PR targetting those branches
branches: [master, dev, release/*]

permissions:
contents: read
Expand Down
18 changes: 13 additions & 5 deletions src/script/util/StringUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import getSlug from 'speakingurl';

import crypto from 'crypto';

import {randomElement} from 'Util/ArrayUtil';

import type {User} from '../entity/User';
Expand Down Expand Up @@ -219,6 +221,12 @@ const accentsMap: Record<string, string> = {
*/
export const replaceAccents = (text: string) => getSlug(text, {custom: accentsMap, uric: true});

const getRandomInt = (max: number) => {
const array = new Uint32Array(1);
crypto.getRandomValues(array);
return array[0] % max;
};

/**
* generate a random password
* @param passwordLength the desired length of the password
Expand All @@ -240,14 +248,14 @@ export const generateRandomPassword = (passwordLength: number = 8): string => {

// Add one random lowercase letter, one random uppercase letter, one random number, and one random special character to the password
let password = '';
password += lowercaseChars[Math.floor(Math.random() * lowercaseChars.length)];
password += uppercaseChars[Math.floor(Math.random() * uppercaseChars.length)];
password += numericChars[Math.floor(Math.random() * numericChars.length)];
password += specialChars[Math.floor(Math.random() * specialChars.length)];
password += lowercaseChars[getRandomInt(lowercaseChars.length)];
password += uppercaseChars[getRandomInt(uppercaseChars.length)];
password += numericChars[getRandomInt(numericChars.length)];
password += specialChars[getRandomInt(specialChars.length)];

// Add additional random characters to the password using all possible characters
for (let i = 0; i < additionalChars; i++) {
password += allChars[Math.floor(Math.random() * allChars.length)];
password += allChars[getRandomInt(allChars.length)];
}

// Shuffle the characters of the password randomly to make it more secure
Expand Down
Loading