Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -27,14 +27,15 @@
*/
import { z } from "zod";
import { createSlidingWindowRateLimiter } from "@toolctrl/shared-store";
import { createSlidingWindowRateLimiter } from "@hivegrid/shared-store";
import { captureLead } from "~/utils/leads/captureLead.server";
import { matchAllowedOrigin, parseAllowedOrigins } from "~/utils/leads/originCheck";
import { getSharedStore } from "~/shared-store.server";
import { createScopedLogger } from "~/utils/logger.server";
import { evaluateFlagForContext } from "~/utils/services/.server/featureFlagEvaluator.server";
import { getTranslations } from "~/locale/i18next.server";
import { resolveCaptchaConfig, verifyCaptchaToken } from "@toolctrl/captcha";
import { getSecret, resolveCaptchaConfig, verifyCaptchaToken } from "@hivegrid/captcha";
import { getTrustedClientIp } from "~/utils/server/IpUtils";
const log = createScopedLogger("marketing.lead-capture");
@@ -71,6 +72,7 @@ const CaptureSchema = z.object({
source: z.string().max(120).optional().nullable(),
attribution: AttributionSchema.optional(),
turnstileToken: z.string().max(2048).optional().nullable(),
captchaToken: z.string().max(4096).optional().nullable(),
// Honeypot — when present-and-truthy we silently 204.
[HONEYPOT_FIELD]: z.string().optional().nullable(),
});
@@ -78,9 +80,11 @@ const CaptureSchema = z.object({
type CapturePayload = z.infer<typeof CaptureSchema>;
function clientIp(request: Request): string | null {
const fwd = request.headers.get("x-forwarded-for");
if (fwd) return fwd.split(",")[0]?.trim() || null;
return request.headers.get("x-real-ip");
// Use a trusted, proxy-set header only. The leftmost X-Forwarded-For value is
// client-controlled, so keying the per-IP rate limit on it let an attacker
// reset their bucket by rotating the header.
const ip = getTrustedClientIp(request);
return ip === "unknown" ? null : ip;
}
function corsHeaders(origin: string | null, allowed: readonly string[]): Headers {
@@ -220,7 +224,7 @@ export async function action({ request }: { request: Request }): Promise<Respons
// Non-production: fail open so local/dev captures aren't dropped.
}
// 5. Optional captcha gate (mCaptcha, feature-flag-gated)
// 5. Optional captcha gate (self-hosted provider, feature-flag-gated)
try {
const flag = await evaluateFlagForContext("marketing-funnel-turnstile", {
flagName: "marketing-funnel-turnstile",
@@ -228,12 +232,14 @@ export async function action({ request }: { request: Request }): Promise<Respons
userId: null,
});
const captcha = resolveCaptchaConfig(process.env);
if (flag.enabled && captcha.instanceUrl && captcha.accountSecret) {
const secret = getSecret(captcha, "forms");
if (flag.enabled && captcha.instanceUrl && secret) {
const ok = await verifyCaptchaToken({
token: payload.turnstileToken ?? null,
token: payload.captchaToken ?? payload.turnstileToken ?? null,
sitekey: captcha.sitekeys.forms,
secret: captcha.accountSecret,
secret,
instanceUrl: captcha.instanceUrl,
provider: captcha.provider,
failOpen: captcha.failOpen,
logger: log,
});