🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(auth): improve name and password verification (#4434)
Marc Klingen583e90321e5a
diff --git a/packages/shared/src/utils/zod.ts b/packages/shared/src/utils/zod.tsindex 9a31e36f23..421b52113b 100644--- a/packages/shared/src/utils/zod.ts+++ b/packages/shared/src/utils/zod.ts@@ -26,7 +26,7 @@ export const jsonSchemaNullable: z.ZodType<JsonNested> = z.lazy(() =>nestedLiteralSchema,z.array(jsonSchemaNullable),z.record(jsonSchemaNullable),- ])+ ]),);// Root schema that does not allow nulls at the root level@@ -35,17 +35,17 @@ export const jsonSchema: z.ZodType<Json> = z.lazy(() =>rootLiteralSchema,z.array(jsonSchemaNullable),z.record(jsonSchemaNullable),- ])+ ]),);export const paginationZod = {page: z.preprocess((x) => (x === "" ? undefined : x),- z.coerce.number().default(1)+ z.coerce.number().default(1),),limit: z.preprocess((x) => (x === "" ? undefined : x),- z.coerce.number().lte(100).default(50)+ z.coerce.number().lte(100).default(50),),};@@ -69,8 +69,11 @@ export const paginationMetaResponseZod = z.object({totalPages: z.number().int().nonnegative(),});-export const noHtmlRegex = /<[^>]*>/;-export const noHtmlCheck = (value: string) => !noHtmlRegex.test(value);+export const htmlRegex = /<[^>]*>/;+export const noHtmlCheck = (value: string) => !htmlRegex.test(value);++const urlRegex = /https?:\/\/[^\s/$.?#].[^\s]*/i;+export const noUrlCheck = (value: string) => !urlRegex.test(value);export const NonEmptyString = z.string().min(1);@@ -83,7 +86,7 @@ export const NonEmptyString = z.string().min(1);*/export const validateZodSchema = <T extends z.ZodTypeAny>(schema: T,- object: z.infer<T>+ object: z.infer<T>,): z.infer<T> => {return schema.parse(object);};diff --git a/web/src/__e2e__/auth.spec.ts b/web/src/__e2e__/auth.spec.tsindex 6c77842d18..8be293e67e 100644--- a/web/src/__e2e__/auth.spec.ts+++ b/web/src/__e2e__/auth.spec.ts@@ -22,7 +22,7 @@ test("Successfully sign up & able to go to homepage", async ({ page }) => {await page.goto("auth/sign-up");await page.fill('input[name="name"]', "demo lang");await page.fill('input[name="email"]', randomEmailAddress());- await page.fill('input[type="password"]', "password2");+ await page.fill('input[type="password"]', "Password2#!");await page.click('button[data-testid="submit-email-password-sign-up-form"]');await page.waitForTimeout(2000);// see get started page@@ -35,7 +35,7 @@ test("Successfully sign up & able to go to homepage with uppercase email", asyncawait page.goto("auth/sign-up");await page.fill('input[name="name"]', "demo lang");await page.fill('input[name="email"]', "A" + randomEmailAddress());- await page.fill('input[type="password"]', "password3");+ await page.fill('input[type="password"]', "Password3#!");await page.click('button[data-testid="submit-email-password-sign-up-form"]');await page.waitForTimeout(2000);// see get started page@@ -50,7 +50,7 @@ test("Signup input validation", async ({ page }) => {await page.waitForTimeout(2000);await expect(page.getByText("Invalid email")).toBeVisible();await expect(- page.getByText("Password must be at least 8 characters long"),+ page.getByText("Password must be at least 8 characters long."),).toBeVisible();await page.click('button[data-testid="submit-email-password-sign-up-form"]');await page.waitForTimeout(2000);diff --git a/web/src/features/auth-credentials/components/ResetPasswordPage.tsx b/web/src/features/auth-credentials/components/ResetPasswordPage.tsxindex fd0930f648..dfe8afea09 100644--- a/web/src/features/auth-credentials/components/ResetPasswordPage.tsx+++ b/web/src/features/auth-credentials/components/ResetPasswordPage.tsx@@ -25,16 +25,13 @@ import { isEmailVerifiedWithinCutoff } from "@/src/features/auth-credentials/libimport Link from "next/link";import { ErrorPage } from "@/src/components/error-page";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";+import { passwordSchema } from "@/src/features/auth/lib/signupSchema";const resetPasswordSchema = z.object({email: z.string().email(),- password: z.string().min(8, {- message: "Password must be at least 8 characters long",- }),- confirmPassword: z.string().min(8, {- message: "Password must be at least 8 characters long",- }),+ password: passwordSchema,+ confirmPassword: passwordSchema,}).refine((data) => data.password === data.confirmPassword, {message: "Passwords do not match",diff --git a/web/src/features/auth-credentials/server/credentialsRouter.ts b/web/src/features/auth-credentials/server/credentialsRouter.tsindex e4e0e56c8c..079ecd2d2b 100644--- a/web/src/features/auth-credentials/server/credentialsRouter.ts+++ b/web/src/features/auth-credentials/server/credentialsRouter.ts@@ -1,9 +1,9 @@import { z } from "zod";import { createTRPCRouter, protectedProcedure } from "@/src/server/api/trpc";-import { passwordSchema } from "@/src/features/auth-credentials/types";import { updateUserPassword } from "@/src/features/auth-credentials/lib/credentialsServerUtils";import { TRPCError } from "@trpc/server";import { isEmailVerifiedWithinCutoff } from "@/src/features/auth-credentials/lib/credentialsUtils";+import { passwordSchema } from "@/src/features/auth/lib/signupSchema";export const credentialsRouter = createTRPCRouter({resetPassword: protectedProcedurediff --git a/web/src/features/auth-credentials/types.ts b/web/src/features/auth-credentials/types.tsdeleted file mode 100644index 85afd23175..0000000000--- a/web/src/features/auth-credentials/types.ts+++ /dev/null@@ -1,5 +0,0 @@-import { z } from "zod";--export const passwordSchema = z.string().min(8, {- message: "Password must be at least 8 characters long",-});diff --git a/web/src/features/auth/lib/signupSchema.ts b/web/src/features/auth/lib/signupSchema.tsindex dd0e149753..a98f76c0dd 100644--- a/web/src/features/auth/lib/signupSchema.ts+++ b/web/src/features/auth/lib/signupSchema.ts@@ -1,16 +1,33 @@-import { noHtmlCheck } from "@langfuse/shared";+import { noHtmlCheck, noUrlCheck } from "@langfuse/shared";import * as z from "zod";+export const passwordSchema = z+ .string()+ .min(8, { message: "Password must be at least 8 characters long." })+ .regex(/[A-Za-z]/, {+ message:+ "Please choose a secure password by combining letters, numbers, and special characters.",+ })+ .regex(/[0-9]/, {+ message:+ "Please choose a secure password by combining letters, numbers, and special characters.",+ })+ .regex(/[^A-Za-z0-9]/, {+ message:+ "Please choose a secure password by combining letters, numbers, and special characters.",+ });+export const signupSchema = z.object({name: z.string().min(1, { message: "Name is required" }).refine((value) => noHtmlCheck(value), {message: "Input should not contain HTML",+ })+ .refine((value) => noUrlCheck(value), {+ message: "Input should not contain a URL",}),email: z.string().email(),- password: z.string().min(8, {- message: "Password must be at least 8 characters long",- }),+ password: passwordSchema,referralSource: z.string().optional(),});