Skip to content

Commit 69f05ad

Browse files
committed
crypto secure
1 parent 3afacfa commit 69f05ad

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/renderer/components/ShellTerminal.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ interface ShellTerminalProps {
1111
cwd?: string;
1212
}
1313

14+
// Generate a cryptographically secure random string
15+
function secureRandomString(length: number): string {
16+
const array = new Uint8Array(length);
17+
window.crypto.getRandomValues(array);
18+
return Array.from(array, (byte) => byte.toString(36).padStart(2, "0"))
19+
.join("")
20+
.substring(0, length);
21+
}
22+
1423
export function ShellTerminal({ cwd }: ShellTerminalProps) {
1524
const terminalRef = useRef<HTMLDivElement>(null);
1625
const terminal = useRef<Terminal | null>(null);
@@ -38,8 +47,8 @@ export function ShellTerminal({ cwd }: ShellTerminalProps) {
3847
useEffect(() => {
3948
if (!terminalRef.current) return;
4049

41-
// Generate unique session ID for this effect run
42-
const sessionId = `shell-${Date.now()}-${Math.random().toString(36).substring(7)}`;
50+
// Generate unique session ID for this effect run using cryptographically secure random
51+
const sessionId = `shell-${Date.now()}-${secureRandomString(7)}`;
4352
sessionIdRef.current = sessionId;
4453

4554
// Initialize terminal with same styling as task mode

0 commit comments

Comments
 (0)