Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(audit-logs): send only documented fields for signing key events

KhaledR57a3c16ded73e2
diff --git a/packages/server/api/src/app/ee/signing-key/signing-key-controller.ts b/packages/server/api/src/app/ee/signing-key/signing-key-controller.ts
index 57518d8b929..3752ad988b1 100644
--- a/packages/server/api/src/app/ee/signing-key/signing-key-controller.ts
+++ b/packages/server/api/src/app/ee/signing-key/signing-key-controller.ts
@@ -18,7 +18,12 @@ export const signingKeyController: FastifyPluginAsyncZod = async (app) => {
applicationEvents(req.log).sendUserEvent(req, {
action: ApplicationEventName.SIGNING_KEY_CREATED,
data: {
- signingKey: newSigningKey,
+ signingKey: {
+ id: newSigningKey.id,
+ displayName: newSigningKey.displayName,
+ created: newSigningKey.created,
+ updated: newSigningKey.updated,
+ },
},
})
diff --git a/packages/server/api/test/integration/cloud/signing-key/signing-key-events.test.ts b/packages/server/api/test/integration/cloud/signing-key/signing-key-events.test.ts
index afe81ea7354..346abb71298 100644
--- a/packages/server/api/test/integration/cloud/signing-key/signing-key-events.test.ts
+++ b/packages/server/api/test/integration/cloud/signing-key/signing-key-events.test.ts
@@ -2,6 +2,7 @@ import { ApplicationEventName, PrincipalType } from '@activepieces/shared'
import { faker } from '@faker-js/faker'
import { FastifyInstance } from 'fastify'
import { StatusCodes } from 'http-status-codes'
+import { auditLogRepo } from '../../../../src/app/ee/audit-logs/audit-event-service'
import * as applicationEventsModule from '../../../../src/app/helper/application-events'
import { actionsEmitted } from '../../../helpers/application-events'
import { generateMockToken } from '../../../helpers/auth'
@@ -57,5 +58,58 @@ describe('Signing key application events', () => {
ApplicationEventName.SIGNING_KEY_CREATED,
])
})
+
+ it('keeps the private key out of the SIGNING_KEY_CREATED payload', async () => {
+ const { mockOwner, mockPlatform } = await mockAndSaveBasicSetup({ plan: { embeddingEnabled: true } })
+ const token = await generateMockToken({
+ type: PrincipalType.USER,
+ id: mockOwner.id,
+ platform: { id: mockPlatform.id },
+ })
+
+ const response = await app.inject({
+ method: 'POST',
+ url: '/api/v1/signing-keys',
+ body: { displayName: faker.lorem.word() },
+ headers: { authorization: `Bearer ${token}` },
+ })
+
+ expect(response?.statusCode).toBe(StatusCodes.CREATED)
+ const createdKey = response.json()
+ expect(createdKey.privateKey).toContain('PRIVATE KEY')
+ const emittedSigningKey = sendUserEventSpy.mock.calls[0][1].data.signingKey
+ expect(Object.keys(emittedSigningKey).sort()).toEqual(['created', 'displayName', 'id', 'updated'])
+ expect(emittedSigningKey.id).toBe(createdKey.id)
+ expect(emittedSigningKey.displayName).toBe(createdKey.displayName)
+ })
+})
+
+describe('Signing key audit persistence', () => {
+ it('does not store the private key in the audit log', async () => {
+ const { mockOwner, mockPlatform } = await mockAndSaveBasicSetup({ plan: { embeddingEnabled: true, auditLogEnabled: true } })
+ const token = await generateMockToken({
+ type: PrincipalType.USER,
+ id: mockOwner.id,
+ platform: { id: mockPlatform.id },
+ })
+
+ const response = await app.inject({
+ method: 'POST',
+ url: '/api/v1/signing-keys',
+ body: { displayName: faker.lorem.word() },
+ headers: { authorization: `Bearer ${token}` },
+ })
+
+ expect(response?.statusCode).toBe(StatusCodes.CREATED)
+ const privateKey: string = response.json().privateKey
+ await vi.waitUntil(
+ async () => await auditLogRepo().countBy({ platformId: mockPlatform.id, action: ApplicationEventName.SIGNING_KEY_CREATED }) > 0,
+ { timeout: 5000, interval: 50 },
+ )
+ const savedEvent = await auditLogRepo().findOneByOrFail({ platformId: mockPlatform.id, action: ApplicationEventName.SIGNING_KEY_CREATED })
+ const serializedEvent = JSON.stringify(savedEvent)
+ expect(serializedEvent).not.toContain('PRIVATE KEY')
+ expect(serializedEvent).not.toContain(privateKey)
+ })
})