Skip to content

Commit b839e6d

Browse files
committed
fix(auth): enforce SSO on server-side sign-in endpoints
Resolves Dokploy#5288. - In better-auth hooks.before, reject /sign-in/email and /sign-in/social with FORBIDDEN when webServerSettings.enforceSSO is enabled - Prevents direct API password authentication when SSO enforcement is enabled
1 parent 03cdd00 commit b839e6d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎packages/server/src/lib/auth.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ const createBetterAuth = () =>
125125
...(ctx.context.baseURL ? [new URL(ctx.context.baseURL).origin] : []),
126126
...(await resolveTrustedOrigins()),
127127
].filter(Boolean);
128+
129+
if (
130+
!IS_CLOUD &&
131+
(ctx.path.startsWith("/sign-in/email") ||
132+
ctx.path.startsWith("/sign-in/social"))
133+
) {
134+
const settings = await getWebServerSettings();
135+
if (settings?.enforceSSO) {
136+
throw new APIError("FORBIDDEN", {
137+
message: "SSO is enforced. Direct password and social sign-in are disabled.",
138+
});
139+
}
140+
}
128141
}),
129142
},
130143
emailVerification: {

0 commit comments

Comments
 (0)