Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(auth): enforce disabled local login (#1375)

Tin Sever8c8eaf3e86a5
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index 9c1dc4204..bdb430fb1 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -42,6 +42,7 @@ import { generateDemoName } from "./utils/generate-demo-name";
import { getGithubSsoOAuthCredentials } from "./utils/github-sso-env";
import { isCloud } from "./utils/is-cloud";
import { isDisposableEmail } from "./utils/is-disposable-email";
+import { isLocalSignInPath } from "./utils/is-local-sign-in-path";
import { verifyTurnstile } from "./utils/verify-turnstile";
config();
@@ -51,6 +52,7 @@ const githubSso = getGithubSsoOAuthCredentials();
const isRegistrationDisabled = process.env.DISABLE_REGISTRATION === "true";
const isPasswordRegistrationDisabled =
process.env.DISABLE_PASSWORD_REGISTRATION === "true";
+const isLoginFormDisabled = process.env.DISABLE_LOGIN_FORM === "true";
const isEmailOtpSignInDisabled =
process.env.DISABLE_EMAIL_OTP_SIGN_IN === "true";
@@ -552,6 +554,13 @@ export const auth = betterAuth({
},
hooks: {
before: createAuthMiddleware(async (ctx) => {
+ if (isLoginFormDisabled && isLocalSignInPath(ctx.path)) {
+ throw new APIError("FORBIDDEN", {
+ message:
+ "Local sign-in is disabled. Please use a configured social or OIDC sign-in method.",
+ });
+ }
+
// Block invite-member calls on cloud from anonymous users or to
// disposable-email addresses. The 2026-05-28 incident saw ~14k phishing
// invites sent from throwaway disposable-email signups; gating here
diff --git a/apps/api/src/utils/is-local-sign-in-path.ts b/apps/api/src/utils/is-local-sign-in-path.ts
new file mode 100644
index 000000000..5f07eac71
--- /dev/null
+++ b/apps/api/src/utils/is-local-sign-in-path.ts
@@ -0,0 +1,10 @@
+const localSignInPaths = new Set([
+ "/sign-in/email",
+ "/sign-in/magic-link",
+ "/magic-link/verify",
+ "/sign-in/email-otp",
+]);
+
+export function isLocalSignInPath(path: string) {
+ return localSignInPaths.has(path) || path.startsWith("/email-otp/");
+}
diff --git a/tests/api/utils/is-local-sign-in-path.test.ts b/tests/api/utils/is-local-sign-in-path.test.ts
new file mode 100644
index 000000000..6564dc217
--- /dev/null
+++ b/tests/api/utils/is-local-sign-in-path.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from "vitest";
+import { isLocalSignInPath } from "../../../apps/api/src/utils/is-local-sign-in-path";
+
+describe("isLocalSignInPath", () => {
+ it.each([
+ "/sign-in/email",
+ "/sign-in/magic-link",
+ "/magic-link/verify",
+ "/sign-in/email-otp",
+ "/email-otp/send-verification-otp",
+ ])("blocks %s", (path) => {
+ expect(isLocalSignInPath(path)).toBe(true);
+ });
+
+ it.each([
+ "/sign-in/social",
+ "/callback/google",
+ "/get-session",
+ ])("allows %s", (path) => {
+ expect(isLocalSignInPath(path)).toBe(false);
+ });
+});