mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-16 21:19:43 +02:00
fix(core): Check the project of an existing system agent thread (no-changelog)
createThread checks access on the requested working project. It now returns an existing thread only when that thread is in the same project. A thread in another project is not found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
79c25ea218
commit
509b359a6d
|
|
@ -1029,6 +1029,37 @@ describe('SystemAgentExecutionService', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('refuses to return an existing session of the user from another project', async () => {
|
||||
const { service, threadRepository, txRunner } = setup();
|
||||
threadRepository.findOneBy.mockResolvedValue({ ...thread, projectId: 'project-2' } as never);
|
||||
|
||||
await expect(
|
||||
service.createThread({
|
||||
agentId: AGENT_ID,
|
||||
user,
|
||||
projectId: 'project-1',
|
||||
threadId: 'thread-1',
|
||||
}),
|
||||
).rejects.toThrow(NotFoundError);
|
||||
expect(txRunner.run).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns an existing session of the user in the same project', async () => {
|
||||
const { service, threadRepository, txRunner } = setup();
|
||||
const existing = { ...thread, projectId: 'project-1' };
|
||||
threadRepository.findOneBy.mockResolvedValue(existing as never);
|
||||
|
||||
expect(
|
||||
await service.createThread({
|
||||
agentId: AGENT_ID,
|
||||
user,
|
||||
projectId: 'project-1',
|
||||
threadId: 'thread-1',
|
||||
}),
|
||||
).toBe(existing);
|
||||
expect(txRunner.run).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('refuses to create a session with the id of a thread of another user', async () => {
|
||||
const { service, threadRepository, txRunner } = setup();
|
||||
threadRepository.findOneBy.mockResolvedValue({ ...thread, ownerId: 'user-2' } as never);
|
||||
|
|
|
|||
|
|
@ -148,7 +148,9 @@ export class SystemAgentExecutionService {
|
|||
if (
|
||||
existing.agentId !== params.agentId ||
|
||||
existing.accessScope !== 'user' ||
|
||||
existing.ownerId !== params.user.id
|
||||
existing.ownerId !== params.user.id ||
|
||||
// The access check above ran for `params.projectId`, not for the project of this thread.
|
||||
existing.projectId !== params.projectId
|
||||
) {
|
||||
throw new NotFoundError('Session not found');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user