|
1 | 1 | import crypto from "node:crypto"; |
2 | 2 | import bcrypt from "bcrypt"; |
3 | | -import { generateSecret, generateURI, verify } from "otplib"; |
| 3 | +import { createGuardrails, generateSecret, generateURI, verify } from "otplib"; |
4 | 4 | import errs from "../lib/error.js"; |
5 | 5 | import authModel from "../models/auth.js"; |
6 | 6 | import internalUser from "./user.js"; |
@@ -204,6 +204,13 @@ const internal2fa = { |
204 | 204 | const result = await verify({ |
205 | 205 | token, |
206 | 206 | secret, |
| 207 | + // These guardrails lower the minimum length requirement for secrets. |
| 208 | + // In v12 of otplib the default minimum length is 10 and in v13 it is 16. |
| 209 | + // Since there are 2fa secrets in the wild generated with v12 we need to allow shorter secrets |
| 210 | + // so people won't be locked out when upgrading. |
| 211 | + guardrails: createGuardrails({ |
| 212 | + MIN_SECRET_BYTES: 10, |
| 213 | + }), |
207 | 214 | }); |
208 | 215 |
|
209 | 216 | if (result.valid) { |
@@ -278,7 +285,11 @@ const internal2fa = { |
278 | 285 | }, |
279 | 286 |
|
280 | 287 | getUserPasswordAuth: async (userId) => { |
281 | | - const auth = await authModel.query().where("user_id", userId).andWhere("type", "password").first(); |
| 288 | + const auth = await authModel |
| 289 | + .query() |
| 290 | + .where("user_id", userId) |
| 291 | + .andWhere("type", "password") |
| 292 | + .first(); |
282 | 293 |
|
283 | 294 | if (!auth) { |
284 | 295 | throw new errs.ItemNotFoundError("Auth not found"); |
|
0 commit comments