fix(api): Fix RLS context, DTO validation, and error handling #110

Closed
jason.woltje wants to merge 0 commits from fix/rls-dto-errors into develop
Owner

Summary

Fixes High priority issues from code review.

Changes

1. RLS Context Transaction Safety

  • db-context.ts: Wrapped SET LOCAL in $transaction for connection pooling safety
  • workspace.guard.ts: Removed context setting (now done at service layer)

2. Optional workspaceId in Query DTOs

Made workspaceId optional since guards provide it:

  • query-tasks.dto.ts
  • query-events.dto.ts
  • query-projects.dto.ts
  • query-domains.dto.ts
  • query-ideas.dto.ts
  • query-activity-log.dto.ts

3. Activity Controller Error Handling

  • Replaced throw new Error() with throw new UnauthorizedException()
  • Returns proper 401 instead of 500

Impact

  • Prevents RLS context leakage with pooled connections
  • DTOs pass validation when workspaceId comes from guards
  • Proper HTTP status codes for auth errors
## Summary Fixes **High** priority issues from code review. ## Changes ### 1. RLS Context Transaction Safety - `db-context.ts`: Wrapped SET LOCAL in `$transaction` for connection pooling safety - `workspace.guard.ts`: Removed context setting (now done at service layer) ### 2. Optional workspaceId in Query DTOs Made workspaceId optional since guards provide it: - query-tasks.dto.ts - query-events.dto.ts - query-projects.dto.ts - query-domains.dto.ts - query-ideas.dto.ts - query-activity-log.dto.ts ### 3. Activity Controller Error Handling - Replaced `throw new Error()` with `throw new UnauthorizedException()` - Returns proper 401 instead of 500 ## Impact - Prevents RLS context leakage with pooled connections - DTOs pass validation when workspaceId comes from guards - Proper HTTP status codes for auth errors
jason.woltje added 1 commit 2026-01-30 02:15:31 +00:00
- Wrap SET LOCAL in transactions for proper connection pooling
- Make workspaceId optional in query DTOs (derived from guards)
- Replace Error throws with UnauthorizedException in activity controller
- Update workspace guard to remove RLS context setting
- Document that services should use withUserContext/withUserTransaction
jason.woltje closed this pull request 2026-01-30 03:04:03 +00:00

Pull request closed

Sign in to join this conversation.