Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

fix(auth): enforce registration disabled for email (#1453)

Corentin Thomasseta64cbba4c828
diff --git a/.changeset/four-rings-create.md b/.changeset/four-rings-create.md
new file mode 100644
index 00000000..f56b95b3
--- /dev/null
+++ b/.changeset/four-rings-create.md
@@ -0,0 +1,5 @@
+---
+'@papra/app': patch
+---
+
+Fixed an issue where setting `AUTH_IS_REGISTRATION_ENABLED=false` hid the sign-up interface but did not block email and password registrations made directly through the authentication API.
diff --git a/apps/papra-server/src/modules/app/auth/auth.services.ts b/apps/papra-server/src/modules/app/auth/auth.services.ts
index f8b375e6..21098ef3 100644
--- a/apps/papra-server/src/modules/app/auth/auth.services.ts
+++ b/apps/papra-server/src/modules/app/auth/auth.services.ts
@@ -45,6 +45,7 @@ export function getAuth({
},
emailAndPassword: {
enabled: config.auth.providers.email.isEnabled,
+ disableSignUp: !config.auth.isRegistrationEnabled,
revokeSessionsOnPasswordReset: true,
requireEmailVerification: config.auth.isEmailVerificationRequired,
sendResetPassword: config.auth.isPasswordResetEnabled
diff --git a/apps/papra-server/src/modules/app/auth/e2e/registration.e2e.test.ts b/apps/papra-server/src/modules/app/auth/e2e/registration.e2e.test.ts
new file mode 100644
index 00000000..711874ab
--- /dev/null
+++ b/apps/papra-server/src/modules/app/auth/e2e/registration.e2e.test.ts
@@ -0,0 +1,37 @@
+import { describe, expect, test } from 'vitest';
+import { overrideConfig } from '../../../config/config.test-utils';
+import { createInMemoryDatabase } from '../../database/database.test-utils';
+import { createServer } from '../../server';
+import { createTestServerDependencies } from '../../server.test-utils';
+
+describe('registration e2e', () => {
+ describe('when registration is disabled', () => {
+ test('email and password sign-up is rejected', async () => {
+ const { db } = await createInMemoryDatabase();
+ const config = overrideConfig({
+ auth: {
+ isRegistrationEnabled: false,
+ },
+ });
+ const { app } = createServer(createTestServerDependencies({ db, config }));
+
+ const response = await app.request('/api/auth/sign-up/email', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ email: '[email protected]',
+ password: 'StrongPassword123!',
+ name: 'Test User',
+ }),
+ });
+
+ expect(response.status).to.eql(400);
+ expect(await response.json()).to.eql({
+ code: 'EMAIL_PASSWORD_SIGN_UP_DISABLED',
+ message: 'Email and password sign up is not enabled',
+ });
+ });
+ });
+});