Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Use crypto.randomInt for OTP generation (#3837)

Kiran K22c901075ead
diff --git a/apps/web/lib/auth/utils.ts b/apps/web/lib/auth/utils.ts
index 405ecf8c04..d52d0e5fe0 100644
--- a/apps/web/lib/auth/utils.ts
+++ b/apps/web/lib/auth/utils.ts
@@ -1,5 +1,6 @@
import { getServerSession } from "next-auth/next";
import { NextRequest } from "next/server";
+import { randomInt } from "node:crypto";
import { DubApiError } from "../api/errors";
import { authOptions } from "./options";
@@ -37,8 +38,7 @@ export const getAuthTokenOrThrow = (
};
export function generateOTP() {
- // Generate a random number between 0 and 999999
- const randomNumber = Math.floor(Math.random() * 1000000);
+ const randomNumber = randomInt(0, 1000000);
// Pad the number with leading zeros if necessary to ensure it is always 6 digits
return randomNumber.toString().padStart(6, "0");