Skip to content

Commit 5c0d3b8

Browse files
fix(auth): enforce SSO on server-side sign-in endpoints (Dokploy#5291)
* 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 * [autofix.ci] apply automated fixes * fix(auth): block passkey authentication and email signup when SSO is enforced - Include /sign-in/passkey, /passkey/verify-authentication, /passkey/generate-authenticate-options, and /sign-up/email in enforced SSO block - Prevents registered passkeys from bypassing enforced SSO policies --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2 parents 7effae3 + 5f10ed6 commit 5c0d3b8

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ const createBetterAuth = () =>
125125
...(ctx.context.baseURL ? [new URL(ctx.context.baseURL).origin] : []),
126126
...(await resolveTrustedOrigins()),
127127
].filter(Boolean);
128+
129+
const isBlockedAuthPath =
130+
ctx.path.startsWith("/sign-in/email") ||
131+
ctx.path.startsWith("/sign-in/social") ||
132+
ctx.path.startsWith("/sign-in/passkey") ||
133+
ctx.path.startsWith("/sign-up/email") ||
134+
ctx.path.startsWith("/passkey/verify-authentication") ||
135+
ctx.path.startsWith("/passkey/generate-authenticate-options");
136+
137+
if (!IS_CLOUD && isBlockedAuthPath) {
138+
const settings = await getWebServerSettings();
139+
if (settings?.enforceSSO) {
140+
throw new APIError("FORBIDDEN", {
141+
message:
142+
"SSO is enforced. Direct password, social, and passkey sign-in are disabled.",
143+
});
144+
}
145+
}
128146
}),
129147
},
130148
emailVerification: {

0 commit comments

Comments
 (0)