fix(security): Add Firebase token verification to Gemini API routes - #136
Merged
smrithipiedy merged 1 commit intoJul 8, 2026
Merged
Conversation
|
@Madhavi1108 is attempting to deploy a commit to the Smrithi P's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
Hi @smrithipiedy , |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
This PR strengthens the application's security by introducing a global authentication and authorization layer for all state-mutating API endpoints. Instead of protecting individual routes independently, write operations are now secured centrally through middleware that enforces authentication and RBAC permissions before requests reach business logic.
The implementation also preserves existing ownership-based authorization, avoids redundant JWT verification, and ensures all API write operations are protected by default.
Related Issue
Fixes #133
Type
Changes Implemented
Global Authentication Middleware
middleware/globalWriteAuth.js) that automatically protects every POST, PUT, PATCH, and DELETE request./api/auth/login/api/auth/register/api/upload/chunkPermission Mapping
Mapped CRUD operations to RBAC permissions:
create:*edit:*edit:*delete:*Custom state-mutating endpoints now require authentication by default.
Authentication Improvements
Updated
middleware/auth.js.Improvements
req.userif authentication had already been performed by the global middleware.Express Integration
Integrated the middleware globally inside
server.js.This ensures:
Files Added / Modified
New
middleware/globalWriteAuth.jstest_auth_edge_cases.jsModified
middleware/auth.jsserver.jsTesting
Global Authentication Edge Cases
✅ GET Requests
Scenario
Verify GET endpoints bypass global authentication.
Result
✅ Public Authentication Endpoint
Scenario
POST /api/auth/loginwithout a token.Result
✅ Generic State-Mutating Endpoint
Scenario
POST /api/eventswithout authentication.Result
✅ Protected Item Creation (No Token)
Scenario
POST /api/itemswithout authentication.Result
✅ Visitor Permission Enforcement
Scenario
Visitor attempts to create an item.
Result
create:itemspermission enforced successfully.✅ Contributor Permission Validation
Scenario
Contributor creates a new item.
Result
✅ Ownership Verification (Critical Edge Case)
Issue Found
Initially, Contributors were incorrectly blocked from editing or deleting their own resources because the middleware enforced only:
edit:itemsdelete:itemsFix Applied
Added support for fallback permissions:
edit:own_itemsdelete:own_itemsThe request now correctly proceeds to the existing
verifyOwnershipmiddleware.Validation
RBAC Regression Testing
Executed the complete RBAC test suite after integrating the global middleware.
Authentication
Protected Routes
/users.User Management
Resource Operations
Session Management
Automated Test Summary
Global Authentication Tests
edit:own_itemsanddelete:own_items.RBAC Tests
Overall Verification
Checklist