Skip to content

Commit 689dfa3

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

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/utils/gemini-client.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,16 @@ export class GeminiClient {
250250
}
251251

252252
// Generate a temporary session ID for legacy calls
253-
const tempSessionId = `legacy-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
253+
const randomArray = new Uint32Array(2);
254+
(typeof window !== 'undefined' && window.crypto
255+
? window.crypto.getRandomValues(randomArray)
256+
: (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function'
257+
? crypto.getRandomValues(randomArray)
258+
: (() => { throw new Error('No secure random generator available'); })()
259+
)
260+
);
261+
const randomString = Array.from(randomArray).map(n => n.toString(36)).join('').substr(0, 9);
262+
const tempSessionId = `legacy-${Date.now()}-${randomString}`;
254263
const userMessage = messages[messages.length - 1].content;
255264
const conversationHistory = messages.slice(0, -1);
256265

0 commit comments

Comments
 (0)