Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🔒️ Close the password sign-up endpoint (#3229)

Luke Vella2f9547cf380a
diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.ts
index 56b359fd4..6e65861f4 100644
--- a/apps/web/src/lib/auth.ts
+++ b/apps/web/src/lib/auth.ts
@@ -81,7 +81,7 @@ const conditionalPlugins: BetterAuthPlugin[] = [
// Every caller of the OTP send endpoint (combined login/signup
// page, event RSVP verification) renders the Turnstile widget and
// sends the token via the x-captcha-response header.
- endpoints: ["/sign-up/email", "/email-otp/send-verification-otp"],
+ endpoints: ["/email-otp/send-verification-otp"],
}),
]
: []),
@@ -129,12 +129,11 @@ export const authLib = betterAuth({
emailAndPassword: {
enabled: env.EMAIL_LOGIN_ENABLED !== "false",
requireEmailVerification: true,
- onExistingUserSignUp: async ({ user }, request) => {
- await authLib.api.sendVerificationOTP({
- body: { email: user.email, type: "email-verification" },
- request,
- });
- },
+ // Accounts are only ever created through a verified OTP, and a password
+ // can only be set from a signed-in session. Leaving the sign-up endpoint
+ // open would let anyone reserve an address with a password before its
+ // owner first logs in, which the OTP login would then inherit.
+ disableSignUp: true,
sendResetPassword: async ({ user, url }) => {
const locale =
"locale" in user ? (user.locale as string) : await getLocale();
@@ -292,10 +291,6 @@ export const authLib = betterAuth({
enabled: env.RATE_LIMIT_ENABLED !== "false",
storage: redis ? "secondary-storage" : "memory",
customRules: {
- "/sign-up/email": {
- window: 60 * 60, // 1 hour
- max: 50,
- },
"/email-otp/send-verification-otp": {
window: 60 * 60, // 1 hour
max: 100,
@@ -322,7 +317,6 @@ export const authLib = betterAuth({
before: createAuthMiddleware(async (ctx) => {
if (
ctx.path.startsWith("/sign-in") ||
- ctx.path.startsWith("/sign-up") ||
ctx.path.startsWith("/email-otp")
) {
// The email change endpoints submit the address as `newEmail`
diff --git a/apps/web/tests/password-sign-up.spec.ts b/apps/web/tests/password-sign-up.spec.ts
new file mode 100644
index 000000000..ad64fffb0
--- /dev/null
+++ b/apps/web/tests/password-sign-up.spec.ts
@@ -0,0 +1,21 @@
+import { expect, test } from "@playwright/test";
+import { prisma } from "@rallly/database";
+
+const email = "[email protected]";
+
+test.afterAll(async () => {
+ await prisma.user.deleteMany({ where: { email } });
+});
+
+// No UI calls this endpoint. It must stay closed at the API: it is the one
+// path that could attach a password to an address before its owner has
+// verified it, and the OTP login would inherit that password.
+test("the password sign-up endpoint is closed", async ({ request }) => {
+ const signUp = await request.post("/api/better-auth/sign-up/email", {
+ data: { email, password: "attacker-chosen-password", name: "Mallory" },
+ });
+ expect(signUp.status()).toBe(400);
+
+ const user = await prisma.user.findUnique({ where: { email } });
+ expect(user).toBeNull();
+});