Skip to content

Commit df57493

Browse files
committed
Use crypto randomInt for the compare_images tiebreak order
CodeQL flags Math.random as insecure randomness. The tiebreak order choice isn't security-sensitive, but node:crypto randomInt costs nothing and clears the alert. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SGdnz8JAsc4p3SyUUY3sAc
1 parent 97f9aff commit df57493

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/agents/src/tools/creative-critique-tools.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* exactly like they do everywhere else.
2828
*/
2929

30+
import { randomInt } from "node:crypto";
3031
import type { Message, MessageContent } from "@nodetool-ai/protocol";
3132
import type { ProcessingContext } from "@nodetool-ai/runtime";
3233
import { Tool } from "./base-tool.js";
@@ -366,8 +367,10 @@ export class CompareImagesTool extends Tool {
366367
if (forward.winner === reversed.winner) {
367368
return { winner: forward.winner, reason: forward.reason };
368369
}
369-
const tiebreakFirst = Math.random() < 0.5;
370-
const tiebreak = tiebreakFirst ? await call(a, b) : await call(b, a);
370+
// crypto randomInt over Math.random: not security-sensitive (it only
371+
// picks the tiebreak presentation order), but it keeps CodeQL's
372+
// insecure-randomness rule quiet without an exception.
373+
const tiebreak = randomInt(2) === 0 ? await call(a, b) : await call(b, a);
371374
return {
372375
winner: tiebreak.winner,
373376
reason: `(order-sensitive verdict, tiebreak) ${tiebreak.reason}`

0 commit comments

Comments
 (0)