fix(tasks): require JWT + org scope on stats endpoint#3436
fix(tasks): require JWT + org scope on stats endpoint#3436PierreBrisorgueil merged 3 commits intomasterfrom
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 29 minutes and 18 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ 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 |
There was a problem hiding this comment.
Pull request overview
This PR secures the tasks stats endpoint by requiring JWT authentication, resolving organization context, enforcing CASL authorization, and returning an organization-scoped task count instead of a global estimate.
Changes:
- Protect
GET /api/tasks/statswithpassport.authenticate('jwt'),resolveOrganization, andpolicy.isAllowed. - Scope stats counting to
organizationIdviacountDocuments(filter)and plumb org context through controller → service → repository. - Update integration tests for authenticated/unauthenticated behavior and controller error handling.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| modules/tasks/routes/tasks.routes.js | Adds auth + org resolution + CASL policy middleware to /api/tasks/stats. |
| modules/tasks/controllers/tasks.controller.js | Switches stats handler to try/catch and passes req.organization to service. |
| modules/tasks/services/tasks.service.js | Updates stats() to accept an optional organization and build a filter. |
| modules/tasks/repositories/tasks.repository.js | Replaces estimatedDocumentCount() with countDocuments(filter) for scoping support. |
| modules/tasks/tests/tasks.integration.tests.js | Adds/updates tests for stats auth requirement and error path behavior. |
| MIGRATIONS.md | Documents the breaking change for downstream consumers of /api/tasks/stats. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3436 +/- ##
=======================================
Coverage 85.58% 85.58%
=======================================
Files 113 113
Lines 2879 2879
Branches 796 796
=======================================
Hits 2464 2464
Misses 329 329
Partials 86 86 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The /api/tasks/stats endpoint was publicly accessible without authentication and returned a global count across all organizations. Align with other task endpoints by requiring JWT auth, resolving the organization context, and scoping the count query by organizationId. Closes #3430
The stats endpoint was changed from public to authenticated, so the guest-access test must expect 401 instead of 200.
…for logout, fix markdown
007f68b to
f06dfc6
Compare
Summary
GET /api/tasks/stats— previously public with no authorganizationIdusingcountDocuments(filter)instead of globalestimatedDocumentCount()Migration
See
MIGRATIONS.md— downstream projects calling/api/tasks/statswithout a JWT will now receive401.Test plan
Closes #3430