Skip to content

Conversation

@rajat1saxena
Copy link
Member

No description provided.

@vercel
Copy link

vercel bot commented Oct 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
courselit-docs Ready Ready Preview Comment Oct 25, 2025 6:49am

// Inspired from: https://github.com/nextauthjs/next-auth/blob/c4ad77b86762b7fd2e6362d8bf26c5953846774a/packages/next-auth/src/core/lib/utils.ts#L16
export function hashCode(code: number) {
return createHash("sha256")
.update(`${code}${process.env.AUTH_SECRET}`)

Check failure

Code scanning / CodeQL

Use of password hash with insufficient computational effort High

Password from
a call to generateUniquePasscode
is hashed insecurely.

Copilot Autofix

AI 3 months ago

To fix the problem, we should replace the use of crypto.createHash('sha256') with a proper password hashing function, such as bcrypt. This means importing the bcrypt library, and using bcrypt.hashSync (or its async variant if desired) to hash the passcode along with a unique salt.

The hashCode function in apps/web/lib/utils.ts should be changed to use bcrypt.hashSync, using a salt value that is sufficiently high (e.g., 10 rounds). Since only the static six-digit passcode (plus the secret) is currently hashed, the resulting code will now use bcrypt's built-in salting and iteration functionality. Any usage of hashCode (called on line 33 in apps/web/app/api/auth/code/generate/route.ts) will now use the improved hashing scheme, but no further changes are needed to the rest of this code.

We need to:

  • Import the bcrypt library at the top of apps/web/lib/utils.ts.
  • Update hashCode to use bcrypt.hashSync instead of crypto.createHash.
  • Optionally, update any relevant tests or usages, but none are present in the shown snippet.
Suggested changeset 2
apps/web/lib/utils.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/web/lib/utils.ts b/apps/web/lib/utils.ts
--- a/apps/web/lib/utils.ts
+++ b/apps/web/lib/utils.ts
@@ -1,5 +1,6 @@
 import { UIConstants } from "@courselit/common-models";
-import { createHash, randomInt } from "crypto";
+import { randomInt } from "crypto";
+import bcrypt from "bcrypt";
 
 export const capitalize = (s: string) => {
     if (typeof s !== "string") return "";
@@ -69,7 +70,7 @@
 
 // Inspired from: https://github.com/nextauthjs/next-auth/blob/c4ad77b86762b7fd2e6362d8bf26c5953846774a/packages/next-auth/src/core/lib/utils.ts#L16
 export function hashCode(code: number) {
-    return createHash("sha256")
-        .update(`${code}${process.env.AUTH_SECRET}`)
-        .digest("hex");
+    const saltRounds = 10;
+    const toHash = `${code}${process.env.AUTH_SECRET}`;
+    return bcrypt.hashSync(toHash, saltRounds);
 }
EOF
@@ -1,5 +1,6 @@
import { UIConstants } from "@courselit/common-models";
import { createHash, randomInt } from "crypto";
import { randomInt } from "crypto";
import bcrypt from "bcrypt";

export const capitalize = (s: string) => {
if (typeof s !== "string") return "";
@@ -69,7 +70,7 @@

// Inspired from: https://github.com/nextauthjs/next-auth/blob/c4ad77b86762b7fd2e6362d8bf26c5953846774a/packages/next-auth/src/core/lib/utils.ts#L16
export function hashCode(code: number) {
return createHash("sha256")
.update(`${code}${process.env.AUTH_SECRET}`)
.digest("hex");
const saltRounds = 10;
const toHash = `${code}${process.env.AUTH_SECRET}`;
return bcrypt.hashSync(toHash, saltRounds);
}
apps/web/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/web/package.json b/apps/web/package.json
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -77,7 +77,8 @@
     "stripe": "^17.5.0",
     "tailwind-merge": "^2.5.4",
     "tailwindcss-animate": "^1.0.7",
-    "zod": "^3.24.1"
+    "zod": "^3.24.1",
+    "bcrypt": "^6.0.0"
   },
   "devDependencies": {
     "@shelf/jest-mongodb": "^5.2.2",
EOF
@@ -77,7 +77,8 @@
"stripe": "^17.5.0",
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.24.1"
"zod": "^3.24.1",
"bcrypt": "^6.0.0"
},
"devDependencies": {
"@shelf/jest-mongodb": "^5.2.2",
This fix introduces these dependencies
Package Version Security advisories
bcrypt (npm) 6.0.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
@rajat1saxena rajat1saxena merged commit 5fbdc5f into main Oct 25, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants