-
Notifications
You must be signed in to change notification settings - Fork 285
fix(security): resolve IDOR and missing authentication on ticket endpoints #2502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
riteshbonthalakoti
merged 2 commits into
riteshbonthalakoti:gssoc
from
codeboost-tr:fix/security-idor-tickets
Jun 9, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| 🔒 **SECURITY FIX: IDOR and Missing Authentication on Ticket Endpoints** | ||
|
|
||
| This PR addresses the critical security vulnerability reported in Issue #1669, where the `/tickets` endpoints lacked authentication and tenant isolation, potentially leading to cross-tenant data breaches. | ||
|
|
||
| **Changes Implemented in `backend/main.py`:** | ||
| 1. **Moved Authentication Block:** Repositioned the `get_current_user` and related authentication helpers above the API routes to ensure they can be used as dependencies (`Depends`) without raising `NameError`. | ||
| 2. **Fixed Syntax Error:** Corrected a missing `Response` import from `fastapi` which was preventing the application from starting when calling auth endpoints. | ||
| 3. **Secured `GET /tickets`:** | ||
| * Added `Depends(get_current_user)` to enforce authentication. | ||
| * Fetches the authenticated user's `company_id` from the `profiles` table. | ||
| * Restricts the Supabase query to only return tickets matching the user's `company_id` (Tenant Isolation). | ||
| 4. **Secured `GET /tickets/{ticket_id}`:** | ||
| * Added `Depends(get_current_user)`. | ||
| * Validates that the requested ticket's `company_id` matches the authenticated user's `company_id`. Raises `403 Forbidden` if there is a mismatch, preventing IDOR. | ||
| 5. **Secured `POST /tickets/save`:** | ||
| * Added `Depends(get_current_user)` to enforce authentication. | ||
| * Overrides the `request_body.user_id` with the authenticated user's ID (`user["id"]`) to prevent attackers from assigning tickets to arbitrary users. | ||
|
|
||
| **Updates based on CodeRabbit AI Review:** | ||
| * **Consistency in `POST /tickets/save`:** Adjusted tenant validation and logging to consistently use `authenticated_user_id` and corrected `elif` to `else`. | ||
| * **Robust Profile Lookups:** Replaced `.single()` with `.maybe_single()` in profile lookups (`get_tickets`, `get_ticket_by_id`, `save_ticket`) to gracefully handle cases where a profile might not be found. | ||
| * **`get_current_user` Validation:** Added explicit validation to `get_current_user` to ensure the `user` object contains `id` and `email` fields, improving type safety and preventing potential downstream errors. | ||
|
|
||
| **Verification:** | ||
| - Wrote and executed automated tests using `TestClient` to verify that unauthenticated requests now return `401 Unauthorized`. | ||
| - Verified that cross-tenant access to `GET /tickets/{ticket_id}` returns `403 Forbidden`. | ||
| - Confirmed that `POST /tickets/save` strictly uses the authenticated user's ID. | ||
|
|
||
| Closes #1669 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.