feat: Implement Webhooks Ownership and Authentication Boundary#533
Conversation
Fixes OlufunbiIK#473. - Created WebhookPolicyService to enforce that a user can only access or mutate their own webhooks. - Added JwtAuthGuard to WebhooksController to secure all webhook management routes. - Extracted user identity from the authenticated JWT token (@currentuser) instead of relying on client-provided IDs. - Updated CreateWebhookDto to make userId optional since it's now inferred securely from the context. - Wrote extensive unit tests verifying authorization enforcement across all routes.
|
@Xaxxoo is attempting to deploy a commit to the olufunbiik's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThis pull request implements ownership-based access control for webhook management by making the Changes
Sequence DiagramsequenceDiagram
participant Client
participant Controller as WebhooksController
participant Guard as JwtAuthGuard
participant Service as WebhooksService
participant Policy as WebhookPolicyService
participant DB as Database
Client->>Controller: Request (protected endpoint)
Controller->>Guard: Check JWT token
Guard-->>Controller: Authenticated user
alt Create Webhook
Controller->>Service: create(dto, userId from auth)
Service->>DB: Save webhook with userId
DB-->>Service: Created webhook
Service-->>Controller: Return webhook
else Access Existing Webhook
Controller->>DB: Load webhook by ID
DB-->>Controller: Webhook data
Controller->>Policy: assertOwnership(user, webhook)
Policy-->>Controller: ✓ Ownership verified
Controller->>Service: Perform operation
Service-->>Controller: Return result
else Unauthorized Access
Controller->>DB: Load webhook by ID
DB-->>Controller: Webhook data
Controller->>Policy: assertOwnership(user, webhook)
Policy-->>Controller: ✗ ForbiddenException
Controller-->>Client: 403 Forbidden
end
Controller-->>Client: Response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #473.
Changes:
userIdduring webhook creation. It's now correctly derived exclusively from the context of the requesting user.Summary by CodeRabbit
Security
Improvements