fix(M2-005,M2-006): enforce user ownership at repo level for conversations and agents (#293)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #293.
This commit is contained in:
@@ -62,7 +62,11 @@ export class AgentConfigsController {
|
||||
if (!agent.isSystem && agent.ownerId !== user.id) {
|
||||
throw new ForbiddenException('Agent does not belong to the current user');
|
||||
}
|
||||
const updated = await this.brain.agents.update(id, dto);
|
||||
|
||||
// Pass ownerId for user agents so the repo WHERE clause enforces ownership.
|
||||
// For system agents (admin path) pass undefined so the WHERE matches only on id.
|
||||
const ownerId = agent.isSystem ? undefined : user.id;
|
||||
const updated = await this.brain.agents.update(id, dto, ownerId);
|
||||
if (!updated) throw new NotFoundException('Agent not found');
|
||||
return updated;
|
||||
}
|
||||
@@ -78,7 +82,8 @@ export class AgentConfigsController {
|
||||
if (agent.ownerId !== user.id) {
|
||||
throw new ForbiddenException('Agent does not belong to the current user');
|
||||
}
|
||||
const deleted = await this.brain.agents.remove(id);
|
||||
// Pass ownerId so the repo WHERE clause enforces ownership at the DB level.
|
||||
const deleted = await this.brain.agents.remove(id, user.id);
|
||||
if (!deleted) throw new NotFoundException('Agent not found');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user