Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+2
-2
@@ -30,8 +30,8 @@ vi.mock("~/utils/auth/passwordHasher.server", () => ({ verifyPassword: vi.fn().m
|
||||
vi.mock("~/modules/ipAddress/services/IpAddressService.server", () => ({ default: { log: vi.fn().mockResolvedValue(null) } }));
|
||||
vi.mock("~/services/auth/admin-fallback.server", () => ({ assertAdminFallbackLoginAllowed: vi.fn(), AdminFallbackLoginRejected: class extends Error {} }));
|
||||
vi.mock("~/modules/admin-sso/audit.server", () => ({ writeAdminSsoAuditEvent: vi.fn() }));
|
||||
vi.mock("@toolctrl/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@toolctrl/config")>("@toolctrl/config");
|
||||
vi.mock("@hivegrid/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@hivegrid/config")>("@hivegrid/config");
|
||||
return {
|
||||
...actual,
|
||||
loadRequiredWebConfig: () => ({
|
||||
|
||||
+7
-7
@@ -28,7 +28,7 @@ vi.mock("~/utils/session.server", () => ({
|
||||
getUserSession: vi.fn(),
|
||||
setLoggedUser: vi.fn().mockResolvedValue({ userId: "u1", defaultTenantId: "t1", defaultTenant: { id: "t1", slug: "t1" } }),
|
||||
validateCSRFToken: vi.fn(),
|
||||
commitPendingMfaLoginCookie: vi.fn().mockResolvedValue("RJ_session=pending; Path=/; HttpOnly"),
|
||||
commitPendingMfaLoginCookie: vi.fn().mockResolvedValue("hivegrid_session=pending; Path=/; HttpOnly"),
|
||||
}));
|
||||
vi.mock("~/services/auth/sessionLifecycle.server", () => ({ startServerSession: vi.fn().mockResolvedValue("server-token") }));
|
||||
vi.mock("~/utils/db/tenants.db.server", () => ({ getTenant: vi.fn().mockResolvedValue({ id: "t1", slug: "t1" }) }));
|
||||
@@ -42,7 +42,7 @@ vi.mock("~/services/auth/login-captcha-gate.server", () => ({
|
||||
loginRequiresCaptcha: vi.fn().mockReturnValue(false),
|
||||
recordFailedLogin: vi.fn(),
|
||||
}));
|
||||
vi.mock("@toolctrl/captcha", () => ({
|
||||
vi.mock("@hivegrid/captcha", () => ({
|
||||
getSitekey: vi.fn(),
|
||||
isCaptchaConfigured: vi.fn().mockReturnValue(false),
|
||||
resolveCaptchaConfig: vi.fn().mockReturnValue({}),
|
||||
@@ -57,10 +57,10 @@ vi.mock("~/utils/auth/mfa/challenge-rate-limit.server", () => ({
|
||||
}));
|
||||
vi.mock("~/utils/auth/mfa/trusted-device.server", () => ({
|
||||
isTrustedDevice: vi.fn().mockResolvedValue(false),
|
||||
rememberDeviceForUser: vi.fn().mockResolvedValue("RJ_trusted_device=marker; Path=/; HttpOnly"),
|
||||
rememberDeviceForUser: vi.fn().mockResolvedValue("hivegrid_trusted_device=marker; Path=/; HttpOnly"),
|
||||
}));
|
||||
vi.mock("@toolctrl/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@toolctrl/config")>("@toolctrl/config");
|
||||
vi.mock("@hivegrid/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@hivegrid/config")>("@hivegrid/config");
|
||||
return {
|
||||
...actual,
|
||||
loadRequiredWebConfig: () => ({
|
||||
@@ -128,7 +128,7 @@ describe("loginFromRequest — 2FA gate", () => {
|
||||
expect(response.status).toBe(200);
|
||||
expect(body.requiresMfa).toBe(true);
|
||||
expect(body.mfaVerifyPath).toBe("/login-mfa");
|
||||
expect(response.headers.get("Set-Cookie")).toContain("RJ_session=pending");
|
||||
expect(response.headers.get("Set-Cookie")).toContain("hivegrid_session=pending");
|
||||
expect(commitPendingMfaLoginCookieMock).toHaveBeenCalledWith(expect.any(Request), { userId: "u1", redirectTo: "" });
|
||||
expect(createUserSessionMock).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -200,7 +200,7 @@ describe("verifyMfaLoginFromRequest", () => {
|
||||
const response = await AuthService.verifyMfaLoginFromRequest(new Request("https://app.example.com/login-mfa", { method: "POST" }), form);
|
||||
|
||||
expect(rememberDeviceForUser).toHaveBeenCalledWith({ request: expect.any(Request), userId: "u1" });
|
||||
expect(response.headers.getSetCookie?.().some((c) => c.includes("RJ_trusted_device")) ?? true).toBe(true);
|
||||
expect(response.headers.getSetCookie?.().some((c) => c.includes("hivegrid_trusted_device")) ?? true).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects a wrong code without issuing a session", async () => {
|
||||
|
||||
+2
-2
@@ -39,8 +39,8 @@ vi.mock("~/services/auth/admin-fallback.server", () => ({
|
||||
AdminFallbackLoginRejected: class extends Error {},
|
||||
}));
|
||||
vi.mock("~/modules/admin-sso/audit.server", () => ({ writeAdminSsoAuditEvent: vi.fn() }));
|
||||
vi.mock("@toolctrl/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@toolctrl/config")>("@toolctrl/config");
|
||||
vi.mock("@hivegrid/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@hivegrid/config")>("@hivegrid/config");
|
||||
return {
|
||||
...actual,
|
||||
loadRequiredWebConfig: () => ({
|
||||
|
||||
+20
-15
@@ -1,14 +1,15 @@
|
||||
/**
|
||||
* Phase 01 / #20 — Magic-link-only account login guard.
|
||||
* Phase 01 / #20 + security audit #9 — Magic-link-only account login guard.
|
||||
*
|
||||
* Asserts that AuthService.loginFromRequest refuses a password-login
|
||||
* attempt for a user whose `passwordHash` is null (magic-link-only
|
||||
* account provisioned by the invitation flow), and surfaces a
|
||||
* `requiresMagicLink: true` hint pointing at /forgot-password.
|
||||
* account provisioned by the invitation flow) WITHOUT leaking that the
|
||||
* account exists. The response must be byte-identical to an unknown-email
|
||||
* or wrong-password attempt (generic invalid-credentials, no
|
||||
* `requiresMagicLink` signal), and the dummy-hash comparison must run so
|
||||
* there is no timing side-channel.
|
||||
*
|
||||
* The critical guarantee: no path grants a session on a null hash, and
|
||||
* the dummy-hash fallthrough never produces "bad credentials" for these
|
||||
* accounts — the user gets a friendly, actionable error instead.
|
||||
* The critical guarantee: no path grants a session on a null hash.
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
@@ -37,8 +38,8 @@ vi.mock("~/utils/auth/passwordHasher.server", () => ({
|
||||
vi.mock("~/modules/ipAddress/services/IpAddressService.server", () => ({ default: { log: vi.fn().mockResolvedValue(null) } }));
|
||||
vi.mock("~/services/auth/admin-fallback.server", () => ({ assertAdminFallbackLoginAllowed: vi.fn(), AdminFallbackLoginRejected: class extends Error {} }));
|
||||
vi.mock("~/modules/admin-sso/audit.server", () => ({ writeAdminSsoAuditEvent: vi.fn() }));
|
||||
vi.mock("@toolctrl/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@toolctrl/config")>("@toolctrl/config");
|
||||
vi.mock("@hivegrid/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@hivegrid/config")>("@hivegrid/config");
|
||||
return {
|
||||
...actual,
|
||||
loadRequiredWebConfig: () => ({
|
||||
@@ -73,7 +74,10 @@ describe("AuthService magic-link-only account guard (#20)", () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("rejects login when the user's passwordHash is null and signals requiresMagicLink", async () => {
|
||||
it("rejects a null-hash login with a generic response that does not leak account existence", async () => {
|
||||
// verifyPassword returns valid:true here to prove the null-hash guard
|
||||
// does not depend on the comparison result — the account must still be
|
||||
// rejected without a session.
|
||||
getUserByEmailMock.mockResolvedValue({
|
||||
id: "u-invited",
|
||||
email: "invited@example.com",
|
||||
@@ -92,12 +96,13 @@ describe("AuthService magic-link-only account guard (#20)", () => {
|
||||
expect(result).toBeInstanceOf(Response);
|
||||
expect(result.status).toBe(400);
|
||||
const body = await result.json();
|
||||
expect(body.requiresMagicLink).toBe(true);
|
||||
expect(body.magicLinkHref).toBe("/forgot-password");
|
||||
expect(body.error).toBe("auth:errors.passwordlessAccountUseMagicLink");
|
||||
// Critical: must never have called verifyPassword for a null-hash row.
|
||||
expect(verifyPasswordMock).not.toHaveBeenCalled();
|
||||
// Critical: must never have created a session.
|
||||
// Anti-enumeration: identical to the unknown-email / wrong-password path.
|
||||
expect(body.error).toBe("api.errors.invalidPassword");
|
||||
expect(body.requiresMagicLink).toBeUndefined();
|
||||
expect(body.magicLinkHref).toBeUndefined();
|
||||
// Timing side-channel closed: the dummy-hash comparison runs anyway.
|
||||
expect(verifyPasswordMock).toHaveBeenCalledTimes(1);
|
||||
// Critical: must never have created a session on a null-hash row.
|
||||
expect(setLoggedUserMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+2
-2
@@ -20,8 +20,8 @@ vi.mock("~/utils/services/authService", () => ({
|
||||
}));
|
||||
vi.mock("~/utils/db/registration.db.server", () => ({ getRegistrationByToken: vi.fn(), updateRegistration: vi.fn() }));
|
||||
vi.mock("~/modules/ipAddress/services/IpAddressService.server", () => ({ default: { log: vi.fn() } }));
|
||||
vi.mock("@toolctrl/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@toolctrl/config")>("@toolctrl/config");
|
||||
vi.mock("@hivegrid/config", async () => {
|
||||
const actual = await vi.importActual<typeof import("@hivegrid/config")>("@hivegrid/config");
|
||||
return {
|
||||
...actual,
|
||||
loadRequiredWebConfig: () => ({
|
||||
|
||||
+17
-30
@@ -22,11 +22,11 @@ import { Params, redirect } from "react-router";
|
||||
import IpAddressServiceServer from "~/modules/ipAddress/services/IpAddressService.server";
|
||||
import { isCanonicalAdminHostRoute } from "~/utils/app/HostRouting.server";
|
||||
import { absoluteAdminPath, absoluteAppPath, absoluteAppRootPath } from "~/utils/app/CrossHostUrls";
|
||||
import { loadRequiredWebConfig } from "@toolctrl/config";
|
||||
import { loadRequiredWebConfig } from "@hivegrid/config";
|
||||
import { isRemovedRoutePath } from "~/utils/app/RedirectSafety.server";
|
||||
import { checkAuthRateLimit } from "~/services/auth/auth-rate-limit.server";
|
||||
import { clearFailedLogins, getFailedLoginCount, loginRequiresCaptcha, recordFailedLogin } from "~/services/auth/login-captcha-gate.server";
|
||||
import { getSitekey, isCaptchaConfigured, resolveCaptchaConfig, verifyCaptchaToken } from "@toolctrl/captcha";
|
||||
import { getSecret, getSitekey, isCaptchaConfigured, resolveCaptchaConfig, verifyCaptchaToken } from "@hivegrid/captcha";
|
||||
import { createScopedLogger } from "~/utils/logger.server";
|
||||
import { validatePassword as validatePolicyPassword } from "~/services/auth/password-policy.server";
|
||||
|
||||
@@ -209,15 +209,16 @@ async function loginFromRequest(request: Request, form: FormData) {
|
||||
return Response.json({ fields, error: t("api.errors.tooManyRequests") }, { status: 429, headers: { "Retry-After": String(rateLimit.retryAfterSeconds) } });
|
||||
}
|
||||
|
||||
// Brute-Force-Soft-Gate: ab dem 3. Fehlversuch (pro IP+Email) ein mCaptcha verlangen,
|
||||
// bevor der Passwort-Check laeuft. No-op, solange mCaptcha nicht konfiguriert ist.
|
||||
// Brute-force soft gate: after repeated failures per IP+email, require the
|
||||
// configured self-hosted captcha before checking the password.
|
||||
const captchaConfig = resolveCaptchaConfig(process.env);
|
||||
if (isCaptchaConfigured(captchaConfig) && loginRequiresCaptcha(getFailedLoginCount({ request, identifier: email }))) {
|
||||
const captchaOk = await verifyCaptchaToken({
|
||||
token: form.get("captchaToken")?.toString(),
|
||||
token: form.get("cap-token")?.toString() ?? form.get("mcaptcha__token")?.toString() ?? form.get("captchaToken")?.toString(),
|
||||
sitekey: getSitekey(captchaConfig, "login"),
|
||||
secret: captchaConfig.accountSecret,
|
||||
secret: getSecret(captchaConfig, "login"),
|
||||
instanceUrl: captchaConfig.instanceUrl,
|
||||
provider: captchaConfig.provider,
|
||||
failOpen: captchaConfig.failOpen,
|
||||
logger: authLogger,
|
||||
});
|
||||
@@ -241,31 +242,17 @@ async function loginFromRequest(request: Request, form: FormData) {
|
||||
}
|
||||
}
|
||||
// Phase 01 / #20 — Magic-link-only accounts have `passwordHash = null`
|
||||
// (invitation flow provisions them without a password). Reject the
|
||||
// password-login attempt *before* the verify step so we never grant a
|
||||
// session on the dummy-hash fallthrough, and surface a friendly
|
||||
// message pointing the user at the magic-link entrypoint. We still
|
||||
// return 400 so the response shape stays compatible with existing
|
||||
// clients and login-form error rendering.
|
||||
if (user && user.passwordHash === null) {
|
||||
return Response.json(
|
||||
{
|
||||
fields,
|
||||
error: t("auth:errors.passwordlessAccountUseMagicLink"),
|
||||
requiresMagicLink: true,
|
||||
magicLinkHref: "/forgot-password",
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// (invitation flow provisions them without a password). We must never
|
||||
// grant a session on such a row, but we must also not reveal that the
|
||||
// account exists: an early distinct "use the magic link" response (plus
|
||||
// skipping verifyPassword) let an attacker enumerate invited accounts by
|
||||
// their content and timing. Instead we fall through to the SAME dummy-hash
|
||||
// comparison and the SAME generic invalid-credentials response as an
|
||||
// unknown email — verifyPassword against DUMMY_PASSWORD_HASH always returns
|
||||
// false for a null-hash row, so no session is ever issued. The magic-link
|
||||
// hint is surfaced generically on the /forgot-password flow, not here.
|
||||
const { valid: isCorrectPassword, rehashedHash } = await verifyPassword(password, user?.passwordHash ?? DUMMY_PASSWORD_HASH);
|
||||
if (!user) {
|
||||
recordFailedLogin({ request, identifier: email });
|
||||
return Response.json({ fields, error: t("api.errors.invalidPassword") }, { status: 400 });
|
||||
}
|
||||
|
||||
if (!isCorrectPassword) {
|
||||
if (!user || user.passwordHash === null || !isCorrectPassword) {
|
||||
recordFailedLogin({ request, identifier: email });
|
||||
return Response.json({ fields, error: t("api.errors.invalidPassword") }, { status: 400 });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user