Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

improvement(auth): make signup hCaptcha invisible (#8163)

Andrew Huang70e4d340cdf8
diff --git a/frontend/src/components/auth/AuthTermsNotice.tsx b/frontend/src/components/auth/AuthTermsNotice.tsx
index 6a3ad6297d..8aa6cdeb52 100644
--- a/frontend/src/components/auth/AuthTermsNotice.tsx
+++ b/frontend/src/components/auth/AuthTermsNotice.tsx
@@ -1,26 +1,55 @@
const linkClassName =
"underline underline-offset-2 transition-colors duration-200 hover:text-foreground hover:decoration-project/45";
-export const AuthTermsNotice = () => (
- <p className="text-xs text-pretty text-label">
- By signing up, you agree to our{" "}
- <a
- href="https://infisical.com/terms/cloud"
- target="_blank"
- rel="noopener noreferrer"
- className={linkClassName}
- >
- Terms of Service
- </a>{" "}
- and{" "}
- <a
- href="https://infisical.com/privacy"
- target="_blank"
- rel="noopener noreferrer"
- className={linkClassName}
- >
- Privacy Policy
- </a>
- .
- </p>
+interface AuthTermsNoticeProps {
+ showCaptchaNotice?: boolean;
+}
+
+export const AuthTermsNotice = ({ showCaptchaNotice = false }: AuthTermsNoticeProps) => (
+ <div className="flex flex-col gap-1 text-xs text-pretty text-label">
+ <p>
+ By signing up, you agree to our{" "}
+ <a
+ href="https://infisical.com/terms/cloud"
+ target="_blank"
+ rel="noopener noreferrer"
+ className={linkClassName}
+ >
+ Terms of Service
+ </a>{" "}
+ and{" "}
+ <a
+ href="https://infisical.com/privacy"
+ target="_blank"
+ rel="noopener noreferrer"
+ className={linkClassName}
+ >
+ Privacy Policy
+ </a>
+ .
+ </p>
+ {showCaptchaNotice && (
+ <p>
+ This site is protected by hCaptcha and its{" "}
+ <a
+ href="https://www.hcaptcha.com/privacy"
+ target="_blank"
+ rel="noopener noreferrer"
+ className={linkClassName}
+ >
+ Privacy Policy
+ </a>{" "}
+ and{" "}
+ <a
+ href="https://www.hcaptcha.com/terms"
+ target="_blank"
+ rel="noopener noreferrer"
+ className={linkClassName}
+ >
+ Terms of Service
+ </a>{" "}
+ apply.
+ </p>
+ )}
+ </div>
);
diff --git a/frontend/src/components/auth/InitialSignupStep.tsx b/frontend/src/components/auth/InitialSignupStep.tsx
index 0fa78a5462..558ab4cbfe 100644
--- a/frontend/src/components/auth/InitialSignupStep.tsx
+++ b/frontend/src/components/auth/InitialSignupStep.tsx
@@ -7,6 +7,7 @@ import { Link } from "@tanstack/react-router";
import { z } from "zod";
import { RegionSelect } from "@app/components/navigation/RegionSelect";
+import { createNotification } from "@app/components/notifications";
import {
Button,
ButtonBadge,
@@ -44,13 +45,13 @@ export default function InitialSignupStep({
const { t } = useTranslation();
const { config } = useServerConfig();
const { mutateAsync, isPending } = useSendVerificationEmail();
+ const requiresCaptcha = Boolean(envConfig.CAPTCHA_SITE_KEY);
const [emailError, setEmailError] = useState(false);
- const [captchaToken, setCaptchaToken] = useState("");
+ const [isCaptchaReady, setIsCaptchaReady] = useState(!requiresCaptcha);
+ const [isCaptchaPending, setIsCaptchaPending] = useState(false);
const captchaRef = useRef<HCaptcha>(null);
const isEmailValid = z.string().email().safeParse(email).success;
- const requiresCaptcha = Boolean(envConfig.CAPTCHA_SITE_KEY);
-
const shouldDisplaySignupMethod = (method: LoginMethod) =>
!config.enabledLoginMethods || config.enabledLoginMethods.includes(method);
@@ -76,17 +77,37 @@ export default function InitialSignupStep({
return;
}
+ let captchaToken: string | undefined;
+
+ if (requiresCaptcha) {
+ setIsCaptchaPending(true);
+ try {
+ captchaToken = (await captchaRef.current?.execute({ async: true }))?.response;
+ if (!captchaToken) {
+ throw new Error("hCaptcha did not return a token");
+ }
+ } catch {
+ createNotification({
+ type: "error",
+ text: "Captcha verification failed. Please try again."
+ });
+ captchaRef.current?.resetCaptcha();
+ return;
+ } finally {
+ setIsCaptchaPending(false);
+ }
+ }
+
try {
const { cooldownSeconds } = await mutateAsync({
email: normalizedEmail,
- captchaToken: requiresCaptcha ? captchaToken : undefined
+ captchaToken
});
incrementStep(normalizedEmail, cooldownSeconds);
} finally {
// hCaptcha tokens are single-use, so a retry with a stale one is rejected server-side.
if (requiresCaptcha) {
captchaRef.current?.resetCaptcha();
- setCaptchaToken("");
}
}
};
@@ -173,15 +194,13 @@ export default function InitialSignupStep({
isError={emailError}
/>
{envConfig.CAPTCHA_SITE_KEY && (
- <div className="flex justify-center [&>div]:!w-full">
- <HCaptcha
- theme="dark"
- sitekey={envConfig.CAPTCHA_SITE_KEY}
- onVerify={(token) => setCaptchaToken(token)}
- onExpire={() => setCaptchaToken("")}
- ref={captchaRef}
- />
- </div>
+ <HCaptcha
+ size="invisible"
+ theme="dark"
+ sitekey={envConfig.CAPTCHA_SITE_KEY}
+ onLoad={() => setIsCaptchaReady(true)}
+ ref={captchaRef}
+ />
)}
<Button
type="submit"
@@ -189,8 +208,8 @@ export default function InitialSignupStep({
variant="project"
size="lg"
isFullWidth
- isDisabled={!isEmailValid || isPending || (requiresCaptcha && !captchaToken)}
- isPending={isPending}
+ isDisabled={!isEmailValid || isPending || isCaptchaPending || !isCaptchaReady}
+ isPending={isPending || isCaptchaPending}
>
Continue with Email
</Button>
diff --git a/frontend/src/pages/auth/SignUpPage/SignUpPage.tsx b/frontend/src/pages/auth/SignUpPage/SignUpPage.tsx
index 3e8d1e68f3..905d8764b6 100644
--- a/frontend/src/pages/auth/SignUpPage/SignUpPage.tsx
+++ b/frontend/src/pages/auth/SignUpPage/SignUpPage.tsx
@@ -15,6 +15,7 @@ import { getSignupProduct, SignupProductType } from "@app/components/auth/signup
import TeamInviteStep from "@app/components/auth/TeamInviteStep";
import UserInfoStep from "@app/components/auth/UserInfoStep";
import { createNotification } from "@app/components/notifications";
+import { envConfig } from "@app/config/env";
import { useServerConfig } from "@app/context";
import { useSelectOrganization } from "@app/hooks/api/auth/queries";
import { fetchOrganizations } from "@app/hooks/api/organization/queries";
@@ -227,7 +228,7 @@ export const SignUpPage = ({ invite }: SignUpPageProps) => {
const renderBottomContent = () => {
if (section === SignupSection.Email) {
- return <AuthTermsNotice />;
+ return <AuthTermsNotice showCaptchaNotice={Boolean(envConfig.CAPTCHA_SITE_KEY)} />;
}
if (section === SignupSection.VerifyCode) {