🪢 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
feat(security): add `AUTH_DISABLE_SIGNUP` env to disable all new signups (#1666)
Marc Klingen0cbab9966a02
diff --git a/.env.prod.example b/.env.prod.exampleindex 0283200e9b..6019e48db1 100644--- a/.env.prod.example+++ b/.env.prod.example@@ -37,6 +37,7 @@ LANGFUSE_CSP_ENFORCE_HTTPS="true"# Auth, optional configuration# AUTH_DOMAINS_WITH_SSO_ENFORCEMENT=domain1.com,domain2.com# AUTH_DISABLE_USERNAME_PASSWORD=true+# AUTH_DISABLE_SIGNUP=true# SSO, each group is optional# AUTH_GOOGLE_CLIENT_ID=diff --git a/docker-compose.build.yml b/docker-compose.build.ymlindex 2b5a2ea6d0..e16d2dfbc0 100644--- a/docker-compose.build.yml+++ b/docker-compose.build.yml@@ -16,7 +16,6 @@ services:- SALT=mysalt- NEXTAUTH_URL=http://localhost:3000- TELEMETRY_ENABLED=${TELEMETRY_ENABLED:-true}- - NEXT_PUBLIC_SIGN_UP_DISABLED=${NEXT_PUBLIC_SIGN_UP_DISABLED:-false}- LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES=${LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES:-false}- LANGFUSE_WORKER_HOST=${LANGFUSE_WORKER_HOST:-worker}- LANGFUSE_WORKER_PASSWORD=${LANGFUSE_WORKER_PASSWORD:-mybasicauthsecret}diff --git a/docker-compose.yml b/docker-compose.ymlindex c7a7e4849b..5070ec450f 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -13,7 +13,6 @@ services:- SALT=mysalt- NEXTAUTH_URL=http://localhost:3000- TELEMETRY_ENABLED=${TELEMETRY_ENABLED:-true}- - NEXT_PUBLIC_SIGN_UP_DISABLED=${NEXT_PUBLIC_SIGN_UP_DISABLED:-false}- LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES=${LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES:-false}db:diff --git a/web/src/env.mjs b/web/src/env.mjsindex 7e0c9491d3..2684543d99 100644--- a/web/src/env.mjs+++ b/web/src/env.mjs@@ -61,6 +61,7 @@ export const env = createEnv({AUTH_AUTH0_ALLOW_ACCOUNT_LINKING: z.enum(["true", "false"]).optional(),AUTH_DOMAINS_WITH_SSO_ENFORCEMENT: z.string().optional(),AUTH_DISABLE_USERNAME_PASSWORD: z.enum(["true", "false"]).optional(),+ AUTH_DISABLE_SIGNUP: z.enum(["true", "false"]).optional(),EMAIL_FROM_ADDRESS: z.string().optional(),SMTP_CONNECTION_URL: z.string().optional(),@@ -85,6 +86,8 @@ export const env = createEnv({* Specify your client-side environment variables schema here. This way you can ensure the app* isn't built with invalid env vars. To expose them to the client, prefix them with* `NEXT_PUBLIC_`.+ *+ * WARNING: They do not work when used in Docker builds as NEXT_PUBLIC variables are not runtime but compile-time.*/client: {// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),@@ -150,6 +153,7 @@ export const env = createEnv({AUTH_DOMAINS_WITH_SSO_ENFORCEMENT:process.env.AUTH_DOMAINS_WITH_SSO_ENFORCEMENT,AUTH_DISABLE_USERNAME_PASSWORD: process.env.AUTH_DISABLE_USERNAME_PASSWORD,+ AUTH_DISABLE_SIGNUP: process.env.AUTH_DISABLE_SIGNUP,EMAIL_FROM_ADDRESS: process.env.EMAIL_FROM_ADDRESS,SMTP_CONNECTION_URL: process.env.SMTP_CONNECTION_URL,diff --git a/web/src/pages/api/auth/signup.ts b/web/src/pages/api/auth/signup.tsindex eed05650bf..2fd57ffe9d 100644--- a/web/src/pages/api/auth/signup.ts+++ b/web/src/pages/api/auth/signup.ts@@ -12,7 +12,10 @@ export default async function handler(res: NextApiResponse,) {if (req.method !== "POST") return;- if (env.NEXT_PUBLIC_SIGN_UP_DISABLED === "true") {+ if (+ env.NEXT_PUBLIC_SIGN_UP_DISABLED === "true" ||+ env.AUTH_DISABLE_SIGNUP === "true"+ ) {res.status(422).json({ message: "Sign up is disabled." });return;}diff --git a/web/src/pages/auth/sign-in.tsx b/web/src/pages/auth/sign-in.tsxindex b16226bf0e..6455bbe9c2 100644--- a/web/src/pages/auth/sign-in.tsx+++ b/web/src/pages/auth/sign-in.tsx@@ -46,6 +46,7 @@ export type PageProps = {azureAd: boolean;auth0: boolean;};+ signUpDisabled: boolean;};// Also used in src/pages/auth/sign-up.tsx@@ -74,6 +75,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async () => {env.AUTH_AUTH0_CLIENT_SECRET !== undefined &&env.AUTH_AUTH0_ISSUER !== undefined,},+ signUpDisabled: env.AUTH_DISABLE_SIGNUP === "true",},};};@@ -82,7 +84,10 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async () => {export function SSOButtons({authProviders,action = "Sign in",-}: PageProps & { action?: string }) {+}: {+ authProviders: PageProps["authProviders"];+ action?: string;+}) {const posthog = usePostHog();return (@@ -159,7 +164,7 @@ export function SSOButtons({);}-export default function SignIn({ authProviders }: PageProps) {+export default function SignIn({ authProviders, signUpDisabled }: PageProps) {const [credentialsFormError, setCredentialsFormError] = useState<string | null>(null);@@ -292,7 +297,8 @@ export default function SignIn({ authProviders }: PageProps) {<CloudPrivacyNotice action="signing in" /></div>- {env.NEXT_PUBLIC_SIGN_UP_DISABLED !== "true" &&+ {!signUpDisabled &&+ env.NEXT_PUBLIC_SIGN_UP_DISABLED !== "true" &&authProviders.credentials ? (<p className="mt-10 text-center text-sm text-gray-500">No account yet?{" "}diff --git a/web/src/server/auth.ts b/web/src/server/auth.tsindex 2373d5f1c1..48cf3d2f02 100644--- a/web/src/server/auth.ts+++ b/web/src/server/auth.ts@@ -174,7 +174,10 @@ const extendedPrismaAdapter: Adapter = {async createUser(profile) {if (!prismaAdapter.createUser)throw new Error("createUser not implemented");- if (env.NEXT_PUBLIC_SIGN_UP_DISABLED === "true") {+ if (+ env.NEXT_PUBLIC_SIGN_UP_DISABLED === "true" ||+ env.AUTH_DISABLE_SIGNUP === "true"+ ) {throw new Error("Sign up is disabled.");}if (!profile.email) {