Skip to content

Commit e0515eb

Browse files
committed
fix(auth): workflow system handler
1 parent 3d5bd00 commit e0515eb

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

apps/sim/app/api/workflows/[id]/route.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
3838
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
3939
}
4040

41+
const isInternalCall = auth.authType === 'internal_jwt'
4142
const userId = auth.userId || null
4243

4344
let workflowData = await getWorkflowById(workflowId)
@@ -47,29 +48,32 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
4748
return NextResponse.json({ error: 'Workflow not found' }, { status: 404 })
4849
}
4950

50-
// Check if user has access to this workflow
51-
if (!userId) {
51+
if (isInternalCall && !userId) {
52+
// Internal system calls (e.g. workflow-in-workflow executor) may not carry a userId.
53+
// These are already authenticated via internal JWT; allow read access.
54+
logger.info(`[${requestId}] Internal API call for workflow ${workflowId}`)
55+
} else if (!userId) {
5256
logger.warn(`[${requestId}] Unauthorized access attempt for workflow ${workflowId}`)
5357
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
54-
}
55-
56-
const authorization = await authorizeWorkflowByWorkspacePermission({
57-
workflowId,
58-
userId,
59-
action: 'read',
60-
})
61-
if (!authorization.workflow) {
62-
logger.warn(`[${requestId}] Workflow ${workflowId} not found`)
63-
return NextResponse.json({ error: 'Workflow not found' }, { status: 404 })
64-
}
58+
} else {
59+
const authorization = await authorizeWorkflowByWorkspacePermission({
60+
workflowId,
61+
userId,
62+
action: 'read',
63+
})
64+
if (!authorization.workflow) {
65+
logger.warn(`[${requestId}] Workflow ${workflowId} not found`)
66+
return NextResponse.json({ error: 'Workflow not found' }, { status: 404 })
67+
}
6568

66-
workflowData = authorization.workflow
67-
if (!authorization.allowed) {
68-
logger.warn(`[${requestId}] User ${userId} denied access to workflow ${workflowId}`)
69-
return NextResponse.json(
70-
{ error: authorization.message || 'Access denied' },
71-
{ status: authorization.status }
72-
)
69+
workflowData = authorization.workflow
70+
if (!authorization.allowed) {
71+
logger.warn(`[${requestId}] User ${userId} denied access to workflow ${workflowId}`)
72+
return NextResponse.json(
73+
{ error: authorization.message || 'Access denied' },
74+
{ status: authorization.status }
75+
)
76+
}
7377
}
7478

7579
logger.debug(`[${requestId}] Attempting to load workflow ${workflowId} from normalized tables`)

0 commit comments

Comments
 (0)