fix(core): Prevent unauthorised workflow termination (#16405)

This commit is contained in:
Marc Littlemore
2025-06-18 08:27:43 +01:00
committed by GitHub
parent b5828e5b56
commit 29752ead00
5 changed files with 81 additions and 32 deletions

View File

@@ -3,7 +3,11 @@ import type { User } from '@n8n/db';
import { ConcurrencyControlService } from '@/concurrency/concurrency-control.service';
import { WaitTracker } from '@/wait-tracker';
import { createSuccessfulExecution, getAllExecutions } from './shared/db/executions';
import {
createSuccessfulExecution,
createWaitingExecution,
getAllExecutions,
} from './shared/db/executions';
import { createTeamProject, linkUserToProject } from './shared/db/projects';
import { createMember, createOwner } from './shared/db/users';
import { createWorkflow, shareWorkflowWithUsers } from './shared/db/workflows';
@@ -27,6 +31,11 @@ const saveExecution = async ({ belongingTo }: { belongingTo: User }) => {
return await createSuccessfulExecution(workflow);
};
const saveWaitingExecution = async ({ belongingTo }: { belongingTo: User }) => {
const workflow = await createWorkflow({}, belongingTo);
return await createWaitingExecution(workflow);
};
beforeEach(async () => {
await testDb.truncate(['ExecutionEntity', 'WorkflowEntity', 'SharedWorkflow']);
testServer.license.reset();
@@ -117,3 +126,21 @@ describe('POST /executions/delete', () => {
expect(executions).toHaveLength(0);
});
});
describe('POST /executions/stop', () => {
test('should not stop an execution we do not have access to', async () => {
await saveExecution({ belongingTo: owner });
const incorrectExecutionId = '1234';
await testServer
.authAgentFor(owner)
.post(`/executions/${incorrectExecutionId}/stop`)
.expect(500);
});
test('should stop an execution we have access to', async () => {
const execution = await saveWaitingExecution({ belongingTo: owner });
await testServer.authAgentFor(owner).post(`/executions/${execution.id}/stop`).expect(200);
});
});