Skip to content

Commit 97b96f6

Browse files
christopherholland-workdaychristopherholland-workdayyau-wd
authored
Fix Credential Data Leak (FlowiseAI#6042)
Co-authored-by: christopherholland-workday <christopher.holland+evisort@workday.com> Co-authored-by: yau-wd <yau.ong@workday.com>
1 parent f8defac commit 97b96f6

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

packages/agentflow/src/infrastructure/api/credentials.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,15 @@ describe('bindCredentialsApi', () => {
3333
expect(mockClient.get).toHaveBeenCalledWith('/credentials', { params: { credentialName: 'openAIApi' } })
3434
expect(result).toEqual(mockCredentials)
3535
})
36+
37+
it('should not expose encryptedData in the response', async () => {
38+
const mockCredentials = [{ id: '1', name: 'My OpenAI Key', credentialName: 'openAIApi' }]
39+
;(mockClient.get as jest.Mock).mockResolvedValue({ data: mockCredentials })
40+
41+
const result = await api.getCredentialsByName('openAIApi')
42+
for (const credential of result) {
43+
expect(credential).not.toHaveProperty('encryptedData')
44+
}
45+
})
3646
})
3747
})

packages/server/src/services/credentials/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ const getAllCredentials = async (paramCredentialName: any, workspaceId: string)
6060
...getWorkspaceSearchOptions(workspaceId)
6161
}
6262
const credentials = await appServer.AppDataSource.getRepository(Credential).findBy(searchOptions)
63-
dbResponse.push(...credentials)
63+
dbResponse.push(...credentials.map((c) => omit(c, ['encryptedData'])))
6464
}
6565
} else {
6666
const searchOptions = {
6767
credentialName: paramCredentialName,
6868
...getWorkspaceSearchOptions(workspaceId)
6969
}
7070
const credentials = await appServer.AppDataSource.getRepository(Credential).findBy(searchOptions)
71-
dbResponse = [...credentials]
71+
dbResponse = credentials.map((c) => omit(c, ['encryptedData']))
7272
}
7373
// get shared credentials
7474
if (workspaceId) {

0 commit comments

Comments
 (0)