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:
Jaakko Husso 2026-10-16 21:48:01 +03:00 committed by GitHub
parent 79c25ea218
commit 509b359a6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View File

@ -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);

View File

@ -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');
}