Skip to content

Commit b304eca

Browse files
committed
fix(access-control): add auth to allowlist endpoint, fix loading state race, use accurate error message
1 parent 5c0b6c3 commit b304eca

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

apps/sim/app/api/settings/allowed-integrations/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { NextResponse } from 'next/server'
2+
import { getSession } from '@/lib/auth'
23
import { getAllowedIntegrationsFromEnv } from '@/lib/core/config/feature-flags'
34

45
export async function GET() {
6+
const session = await getSession()
7+
if (!session?.user?.id) {
8+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
9+
}
10+
511
return NextResponse.json({
612
allowedIntegrations: getAllowedIntegrationsFromEnv(),
713
})

apps/sim/ee/access-control/utils/permission-check.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ export class ProviderNotAllowedError extends Error {
2727
}
2828

2929
export class IntegrationNotAllowedError extends Error {
30-
constructor(blockType: string) {
31-
super(`Integration "${blockType}" is not allowed based on your permission group settings`)
30+
constructor(blockType: string, reason?: string) {
31+
super(
32+
reason
33+
? `Integration "${blockType}" is not allowed: ${reason}`
34+
: `Integration "${blockType}" is not allowed based on your permission group settings`
35+
)
3236
this.name = 'IntegrationNotAllowedError'
3337
}
3438
}
@@ -159,7 +163,7 @@ export async function validateBlockType(
159163
const envAllowlist = getAllowedIntegrationsFromEnv()
160164
if (envAllowlist !== null && !envAllowlist.includes(blockType)) {
161165
logger.warn('Integration blocked by env allowlist', { blockType })
162-
throw new IntegrationNotAllowedError(blockType)
166+
throw new IntegrationNotAllowedError(blockType, 'blocked by server ALLOWED_INTEGRATIONS policy')
163167
}
164168

165169
if (!userId) {

apps/sim/hooks/use-permission-config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ export function usePermissionConfig(): PermissionConfigResult {
5353
const { data: organizationsData } = useOrganizations()
5454
const activeOrganization = organizationsData?.activeOrganization
5555

56-
const { data: permissionData, isLoading } = useUserPermissionConfig(activeOrganization?.id)
57-
const { data: envAllowlistData } = useAllowedIntegrationsFromEnv()
56+
const { data: permissionData, isLoading: isPermissionLoading } = useUserPermissionConfig(
57+
activeOrganization?.id
58+
)
59+
const { data: envAllowlistData, isLoading: isEnvAllowlistLoading } =
60+
useAllowedIntegrationsFromEnv()
61+
62+
const isLoading = isPermissionLoading || isEnvAllowlistLoading
5863

5964
const config = useMemo(() => {
6065
if (accessControlDisabled) {

0 commit comments

Comments
 (0)