Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+27
-2
@@ -6,6 +6,9 @@
|
||||
|
||||
import argon2 from "argon2";
|
||||
import bcryptjs from "bcryptjs";
|
||||
import { createScopedLogger } from "~/utils/logger.server";
|
||||
|
||||
const passwordHasherLogger = createScopedLogger("auth.password-hasher");
|
||||
|
||||
// OWASP 2024 recommendation for argon2id at modest server cost.
|
||||
// memoryCost is in KiB (19456 = 19 MiB).
|
||||
@@ -18,6 +21,7 @@ const ARGON2_OPTIONS = {
|
||||
|
||||
const ARGON2_PREFIX_RE = /^\$argon2(?:i|d|id)\$/;
|
||||
const BCRYPT_PREFIX_RE = /^\$2[abxy]\$/;
|
||||
const BCRYPT_MAX_PASSWORD_BYTES = 72;
|
||||
|
||||
export type VerifyPasswordResult = {
|
||||
valid: boolean;
|
||||
@@ -56,15 +60,28 @@ export async function verifyPassword(plain: string, hash: string | null | undefi
|
||||
try {
|
||||
const valid = await argon2.verify(hash, plain);
|
||||
return { valid };
|
||||
} catch {
|
||||
} catch (error: unknown) {
|
||||
passwordHasherLogger.warn(
|
||||
{ op: "verify.argon2.failed", error: toSafeVerificationError(error) },
|
||||
"Argon2 password verification raised; treating the credential as invalid."
|
||||
);
|
||||
return { valid: false };
|
||||
}
|
||||
}
|
||||
if (BCRYPT_PREFIX_RE.test(hash)) {
|
||||
// bcrypt silently truncates after 72 bytes. Reject an overlong legacy
|
||||
// credential so a different suffix cannot authenticate as the same key.
|
||||
if (Buffer.byteLength(plain, "utf8") > BCRYPT_MAX_PASSWORD_BYTES) {
|
||||
return { valid: false };
|
||||
}
|
||||
let valid = false;
|
||||
try {
|
||||
valid = await bcryptjs.compare(plain, hash);
|
||||
} catch {
|
||||
} catch (error: unknown) {
|
||||
passwordHasherLogger.warn(
|
||||
{ op: "verify.bcrypt.failed", error: toSafeVerificationError(error) },
|
||||
"Bcrypt password verification raised; treating the credential as invalid."
|
||||
);
|
||||
return { valid: false };
|
||||
}
|
||||
if (!valid) {
|
||||
@@ -85,3 +102,11 @@ export function isKnownHashFormat(hash: string): "argon2" | "bcrypt" | "unknown"
|
||||
if (BCRYPT_PREFIX_RE.test(hash)) return "bcrypt";
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
function toSafeVerificationError(error: unknown): { name: string; code?: string } {
|
||||
const candidate = error as { name?: unknown; code?: unknown } | null;
|
||||
return {
|
||||
name: typeof candidate?.name === "string" ? candidate.name : "Error",
|
||||
...(typeof candidate?.code === "string" ? { code: candidate.code } : {}),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user