Skip to content

Commit d2a4cb6

Browse files
Potential fix for code scanning alert no. 38: Insecure randomness
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 1f86df3 commit d2a4cb6

File tree

1 file changed

+9
-2
lines changed
  • packages/cli/templates/webcomponents/igc-ts/grid/grid-editing/files/src/app/__path__

1 file changed

+9
-2
lines changed

packages/cli/templates/webcomponents/igc-ts/grid/grid-editing/files/src/app/__path__/DataGridSharedData.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,14 @@ export class DataGridSharedData {
202202
private static roadNames: string[] = ['Main', 'Garden', 'Broad', 'Oak', 'Cedar', 'Park', 'Pine', 'Elm', 'Market', 'Hill'];
203203

204204
private static getRandomNumber(min: number, max: number): number {
205-
return Math.round(min + Math.random() * (max - min));
205+
return Math.round(min + this.secureRandom() * (max - min));
206+
}
207+
208+
// Helper to produce a cryptographically secure random float in [0, 1)
209+
private static secureRandom(): number {
210+
const array = new Uint32Array(1);
211+
window.crypto.getRandomValues(array);
212+
return array[0] / 2 ** 32;
206213
}
207214

208215
private static getRandomItem(array: any[]): any {
@@ -211,7 +218,7 @@ export class DataGridSharedData {
211218
}
212219

213220
private static getRandomDate(start: Date, end: Date) {
214-
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
221+
return new Date(start.getTime() + this.secureRandom() * (end.getTime() - start.getTime()));
215222
}
216223

217224
private static getRandomPhone(): string {

0 commit comments

Comments
 (0)