Skip to content

Commit 86f3a53

Browse files
committed
fix(security): thread workflowId through internal HITL cancellation calls and remove dead branches in credential-access
1 parent a60057a commit 86f3a53

2 files changed

Lines changed: 70 additions & 74 deletions

File tree

apps/sim/lib/auth/credential-access.ts

Lines changed: 64 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -78,44 +78,40 @@ export async function authorizeCredentialUse(
7878
return { ok: false, error: 'Credential is not accessible from this workflow workspace' }
7979
}
8080

81-
if (actingUserId) {
82-
const requesterPerm = await getUserEntityPermissions(
83-
actingUserId,
84-
'workspace',
85-
platformCredential.workspaceId
86-
)
81+
const requesterPerm = await getUserEntityPermissions(
82+
actingUserId,
83+
'workspace',
84+
platformCredential.workspaceId
85+
)
8786

88-
const [membership] = await db
89-
.select({ id: credentialMember.id })
90-
.from(credentialMember)
91-
.where(
92-
and(
93-
eq(credentialMember.credentialId, platformCredential.id),
94-
eq(credentialMember.userId, actingUserId),
95-
eq(credentialMember.status, 'active')
96-
)
87+
const [membership] = await db
88+
.select({ id: credentialMember.id })
89+
.from(credentialMember)
90+
.where(
91+
and(
92+
eq(credentialMember.credentialId, platformCredential.id),
93+
eq(credentialMember.userId, actingUserId),
94+
eq(credentialMember.status, 'active')
9795
)
98-
.limit(1)
99-
100-
if (!membership) {
101-
return {
102-
ok: false,
103-
error:
104-
'You do not have access to this credential. Ask the credential admin to add you as a member.',
105-
}
106-
}
107-
if (requesterPerm === null) {
108-
return { ok: false, error: 'You do not have access to this workspace.' }
96+
)
97+
.limit(1)
98+
99+
if (!membership) {
100+
return {
101+
ok: false,
102+
error:
103+
'You do not have access to this credential. Ask the credential admin to add you as a member.',
109104
}
110-
} else if (!workflowContext) {
111-
return { ok: false, error: 'workflowId is required' }
105+
}
106+
if (requesterPerm === null) {
107+
return { ok: false, error: 'You do not have access to this workspace.' }
112108
}
113109

114110
return {
115111
ok: true,
116112
authType: auth.authType as CredentialAccessResult['authType'],
117113
requesterUserId: auth.userId,
118-
credentialOwnerUserId: actingUserId || auth.userId,
114+
credentialOwnerUserId: actingUserId,
119115
workspaceId: platformCredential.workspaceId,
120116
resolvedCredentialId: platformCredential.id,
121117
}
@@ -139,36 +135,34 @@ export async function authorizeCredentialUse(
139135
return { ok: false, error: 'Credential account not found' }
140136
}
141137

142-
if (actingUserId) {
143-
const requesterPerm = await getUserEntityPermissions(
144-
actingUserId,
145-
'workspace',
146-
platformCredential.workspaceId
147-
)
138+
const requesterPerm = await getUserEntityPermissions(
139+
actingUserId,
140+
'workspace',
141+
platformCredential.workspaceId
142+
)
148143

149-
const [membership] = await db
150-
.select({ id: credentialMember.id })
151-
.from(credentialMember)
152-
.where(
153-
and(
154-
eq(credentialMember.credentialId, platformCredential.id),
155-
eq(credentialMember.userId, actingUserId),
156-
eq(credentialMember.status, 'active')
157-
)
144+
const [membership] = await db
145+
.select({ id: credentialMember.id })
146+
.from(credentialMember)
147+
.where(
148+
and(
149+
eq(credentialMember.credentialId, platformCredential.id),
150+
eq(credentialMember.userId, actingUserId),
151+
eq(credentialMember.status, 'active')
158152
)
159-
.limit(1)
153+
)
154+
.limit(1)
160155

161-
if (!membership) {
162-
return {
163-
ok: false,
164-
error: `You do not have access to this credential. Ask the credential admin to add you as a member.`,
165-
}
156+
if (!membership) {
157+
return {
158+
ok: false,
159+
error: `You do not have access to this credential. Ask the credential admin to add you as a member.`,
166160
}
167-
if (requesterPerm === null) {
168-
return {
169-
ok: false,
170-
error: 'You do not have access to this workspace.',
171-
}
161+
}
162+
if (requesterPerm === null) {
163+
return {
164+
ok: false,
165+
error: 'You do not have access to this workspace.',
172166
}
173167
}
174168

@@ -222,25 +216,23 @@ export async function authorizeCredentialUse(
222216
return { ok: false, error: 'Credential account not found' }
223217
}
224218

225-
if (actingUserId) {
226-
const [membership] = await db
227-
.select({ id: credentialMember.id })
228-
.from(credentialMember)
229-
.where(
230-
and(
231-
eq(credentialMember.credentialId, workspaceCredential.id),
232-
eq(credentialMember.userId, actingUserId),
233-
eq(credentialMember.status, 'active')
234-
)
219+
const [membership] = await db
220+
.select({ id: credentialMember.id })
221+
.from(credentialMember)
222+
.where(
223+
and(
224+
eq(credentialMember.credentialId, workspaceCredential.id),
225+
eq(credentialMember.userId, actingUserId),
226+
eq(credentialMember.status, 'active')
235227
)
236-
.limit(1)
228+
)
229+
.limit(1)
237230

238-
if (!membership) {
239-
return {
240-
ok: false,
241-
error:
242-
'You do not have access to this credential. Ask the credential admin to add you as a member.',
243-
}
231+
if (!membership) {
232+
return {
233+
ok: false,
234+
error:
235+
'You do not have access to this credential. Ask the credential admin to add you as a member.',
244236
}
245237
}
246238

apps/sim/lib/workflows/executor/human-in-the-loop-manager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,14 @@ export class PauseResumeManager {
476476
failureReason: 'Resume execution cancelled',
477477
})
478478
const pausedCancellationStatus = await PauseResumeManager.getPausedCancellationStatus(
479-
pausedExecution.executionId
479+
pausedExecution.executionId,
480+
pausedExecution.workflowId
480481
)
481482
if (pausedCancellationStatus === 'cancelling') {
482-
await PauseResumeManager.completePausedCancellation(pausedExecution.executionId)
483+
await PauseResumeManager.completePausedCancellation(
484+
pausedExecution.executionId,
485+
pausedExecution.workflowId
486+
)
483487
}
484488
} else {
485489
await PauseResumeManager.updateSnapshotAfterResume({

0 commit comments

Comments
 (0)