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
+1
-1
@@ -10,7 +10,7 @@ import {
|
||||
isSensitiveAdminAction,
|
||||
} from "./admin-mfa-gate.server";
|
||||
|
||||
vi.mock("@toolctrl/config", () => ({
|
||||
vi.mock("@hivegrid/config", () => ({
|
||||
loadRequiredWebConfig: vi.fn(() => ({ routing: { appUrl: "https://app.example.test" } })),
|
||||
}));
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
* redirect when challenge is required.
|
||||
*/
|
||||
import { redirect } from "react-router";
|
||||
import { loadRequiredWebConfig } from "@toolctrl/config";
|
||||
import { loadRequiredWebConfig } from "@hivegrid/config";
|
||||
import { enforceAdminMfa } from "~/utils/auth/mfa/enforcement.server";
|
||||
import { checkMfaStepUpState } from "~/utils/auth/mfa/step-up.server";
|
||||
import { absoluteAppRootPath } from "~/utils/app/CrossHostUrls";
|
||||
|
||||
+14
-3
@@ -16,7 +16,7 @@ describe("auth rate limiting", () => {
|
||||
|
||||
it("builds stable keys from action, client ip, and normalized identifier", () => {
|
||||
const request = new Request("https://example.test/login", {
|
||||
headers: { "x-forwarded-for": "203.0.113.10, 198.51.100.5" },
|
||||
headers: { "cf-connecting-ip": "203.0.113.10" },
|
||||
});
|
||||
|
||||
expect(getAuthRateLimitKey({ request, action: "login", identifier: " Ada@Example.COM " })).toBe(
|
||||
@@ -27,9 +27,20 @@ describe("auth rate limiting", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("does not key on a spoofable X-Forwarded-For / X-Client-IP", () => {
|
||||
// Both spoofable headers must be ignored, so a forged value cannot move the
|
||||
// request into a fresh rate-limit bucket. Both requests collapse to the same
|
||||
// (untrusted -> "unknown") key.
|
||||
const forged = new Request("https://example.test/login", { headers: { "x-forwarded-for": "9.9.9.9", "x-client-ip": "8.8.8.8" } });
|
||||
const bare = new Request("https://example.test/login", {});
|
||||
expect(getAuthRateLimitKey({ request: forged, action: "login", identifier: "ada@example.com" })).toBe(
|
||||
getAuthRateLimitKey({ request: bare, action: "login", identifier: "ada@example.com" })
|
||||
);
|
||||
});
|
||||
|
||||
it("allows requests up to the limit and returns retry timing after the limit", () => {
|
||||
const request = new Request("https://example.test/login", {
|
||||
headers: { "x-client-ip": "203.0.113.10" },
|
||||
headers: { "cf-connecting-ip": "203.0.113.10" },
|
||||
});
|
||||
const options = { request, action: "login" as const, identifier: "ada@example.com", limit: 2, windowMs: 30_000 };
|
||||
|
||||
@@ -40,7 +51,7 @@ describe("auth rate limiting", () => {
|
||||
|
||||
it("starts a new window after the cached counter expires", () => {
|
||||
const request = new Request("https://example.test/mfa", {
|
||||
headers: { "x-client-ip": "203.0.113.10" },
|
||||
headers: { "cf-connecting-ip": "203.0.113.10" },
|
||||
});
|
||||
const options = { request, action: "mfa" as const, identifier: "ada@example.com", limit: 1, windowMs: 10_000 };
|
||||
|
||||
|
||||
+4
-2
@@ -1,7 +1,7 @@
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
import { cache } from "~/utils/cache.server";
|
||||
import { getClientIPAddress } from "~/utils/server/IpUtils";
|
||||
import { getTrustedClientIp } from "~/utils/server/IpUtils";
|
||||
|
||||
type AuthRateLimitOptions = {
|
||||
request: Request;
|
||||
@@ -16,7 +16,9 @@ type AuthRateLimitResult =
|
||||
| { allowed: false; retryAfterSeconds: number };
|
||||
|
||||
export function getAuthRateLimitKey({ request, action, identifier }: Omit<AuthRateLimitOptions, "limit" | "windowMs">) {
|
||||
const ipAddress = getClientIPAddress(request.headers)?.toString() ?? "unknown";
|
||||
// Trusted proxy-set header only; leftmost X-Forwarded-For / X-Client-IP are
|
||||
// client-spoofable and would let an attacker reset this per-IP auth throttle.
|
||||
const ipAddress = getTrustedClientIp(request) || "unknown";
|
||||
const normalizedIdentifier = identifier?.trim().toLowerCase() ?? "";
|
||||
const digest = createHash("sha256").update(`${action}:${ipAddress}:${normalizedIdentifier}`).digest("hex");
|
||||
return `auth-rate-limit:${action}:${digest}`;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { getMailTranslator, getMailTranslatorFromRequest } from "~/locale/mail-t
|
||||
import { queueTransactionalEmail } from "~/modules/emails/services/TransactionalEmailQueue.server";
|
||||
import { db } from "~/utils/db.server";
|
||||
|
||||
vi.mock("@toolctrl/config", () => ({
|
||||
vi.mock("@hivegrid/config", () => ({
|
||||
loadRequiredWebConfig: vi.fn(() => ({ cryptoSecret: "test-secret", sessionSecret: "session-secret" })),
|
||||
}));
|
||||
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
||||
import { resolveTransactionalBrandTokens } from "@toolctrl/brand";
|
||||
import { loadRequiredWebConfig } from "@toolctrl/config";
|
||||
import { buildBrand, renderTransactionalEmail } from "@toolctrl/mail";
|
||||
import { resolveTransactionalBrandTokens } from "@hivegrid/brand";
|
||||
import { loadRequiredWebConfig } from "@hivegrid/config";
|
||||
import { buildBrand, renderTransactionalEmail } from "@hivegrid/mail";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { getAbsoluteUrl } from "~/utils/url.server";
|
||||
import { queueTransactionalEmail } from "~/modules/emails/services/TransactionalEmailQueue.server";
|
||||
|
||||
+5
-5
@@ -9,8 +9,8 @@ vi.mock("~/utils/api/.server/CryptoApi", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@toolctrl/config", () => ({
|
||||
loadRequiredWebConfig: vi.fn(() => ({ appName: "ToolCTRL" })),
|
||||
vi.mock("@hivegrid/config", () => ({
|
||||
loadRequiredWebConfig: vi.fn(() => ({ appName: "HiveGrid" })),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/users.db.server", () => ({
|
||||
@@ -35,7 +35,7 @@ const vectorSecret = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ";
|
||||
|
||||
function generateExpectedCode(secret: string, timestamp: number): string {
|
||||
const totp = new OTPAuth.TOTP({
|
||||
issuer: "ToolCTRL",
|
||||
issuer: "HiveGrid",
|
||||
label: "test",
|
||||
algorithm: "SHA1",
|
||||
digits: 6,
|
||||
@@ -147,7 +147,7 @@ describe("services/auth/totp.server", () => {
|
||||
|
||||
test("startTotpEnrollment yields encrypted secret + parsable otpauth URI", async () => {
|
||||
const { startTotpEnrollment } = await import("./totp.server");
|
||||
const enrollment = startTotpEnrollment("person@example.com", { issuer: "ToolCTRL" });
|
||||
const enrollment = startTotpEnrollment("person@example.com", { issuer: "HiveGrid" });
|
||||
|
||||
expect(enrollment.secret).toMatch(/^[A-Z2-7]{32}$/);
|
||||
expect(enrollment.encryptedSecret).toBe(`encrypted:${enrollment.secret}`);
|
||||
@@ -191,7 +191,7 @@ describe("services/auth/totp.server", () => {
|
||||
const result = await createTotpEnrollmentForUser({
|
||||
userId: "user_1",
|
||||
userEmail: "security@example.com",
|
||||
issuer: "ToolCTRL Admin",
|
||||
issuer: "HiveGrid Admin",
|
||||
now,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as OTPAuth from "otpauth";
|
||||
import { loadRequiredWebConfig } from "@toolctrl/config";
|
||||
import { loadRequiredWebConfig } from "@hivegrid/config";
|
||||
import CryptoApi from "~/utils/api/.server/CryptoApi";
|
||||
import {
|
||||
activateUserTotpPendingSecret,
|
||||
|
||||
Reference in new issue
Block a user