Skip to content

Commit 97b8db6

Browse files
committed
fix(access-control): never leave a new chat with zero selectable auth modes
Surface SSO in the chat deploy options whenever the permission group explicitly allows it (not only when the env flag is on or the chat is saved as SSO), so a group whose only allowed mode is SSO can't produce an empty option set that strands a new chat on a disallowed default. Also drop a redundant trailing comment in the copilot deploy handler.
1 parent 032ee85 commit 97b8db6

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

  • apps/sim
    • app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/chat
    • lib/copilot/tools/handlers/deployment

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/chat/chat.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -677,27 +677,20 @@ function AuthSelector({
677677
}
678678

679679
const { config: permissionConfig } = usePermissionConfig()
680+
const allowedAuthTypes = permissionConfig.allowedChatDeployAuthTypes
680681

681-
// SSO shows when the env flag is on, or when this chat is already saved as SSO,
682-
// so an existing SSO mode is never dropped (and silently downgraded by the snap
683-
// effect below) when the flag is off.
684-
const ssoEnabled = isTruthy(getEnv('NEXT_PUBLIC_SSO_ENABLED')) || savedAuthType === 'sso'
685-
const baseAuthOptions: AuthType[] = ssoEnabled
682+
const ssoAvailable =
683+
isTruthy(getEnv('NEXT_PUBLIC_SSO_ENABLED')) ||
684+
savedAuthType === 'sso' ||
685+
(allowedAuthTypes?.includes('sso') ?? false)
686+
const baseAuthOptions: AuthType[] = ssoAvailable
686687
? ['public', 'password', 'email', 'sso']
687688
: ['public', 'password', 'email']
688689

689-
// Org access-control may restrict which auth modes are allowed (`null` = all).
690-
// The route is the source of truth; this just hides disallowed options. Only a
691-
// chat's already-saved mode is grandfathered (kept visible) — not the unsaved
692-
// `public` default of a brand-new chat.
693-
const allowedAuthTypes = permissionConfig.allowedChatDeployAuthTypes
694690
const authOptions = baseAuthOptions.filter(
695691
(type) => allowedAuthTypes === null || allowedAuthTypes.includes(type) || type === savedAuthType
696692
)
697693

698-
// If the current selection isn't offered (e.g. a new chat defaulting to a
699-
// now-disallowed `public`), snap to the first allowed mode so the form can't
700-
// submit a value the server will reject.
701694
useEffect(() => {
702695
if (authOptions.length > 0 && !authOptions.includes(authType)) {
703696
onAuthTypeChange(authOptions[0])

apps/sim/lib/copilot/tools/handlers/deployment/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export async function executeDeployChat(
406406

407407
// Enforce the permission group's chat auth-mode allow-list, but only when the
408408
// mode actually changes (or on a first deploy) so an existing grandfathered
409-
// mode can be re-saved. New/changed modes must be allowed.
409+
// mode can be re-saved.
410410
if (workflowRecord.workspaceId && resolvedAuthType !== existingDeployment?.authType) {
411411
try {
412412
await validateChatDeployAuth(context.userId, workflowRecord.workspaceId, resolvedAuthType)

0 commit comments

Comments
 (0)