Security Fix: Add CSRF Protection to API Requests (Frontend) #371
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.
🔒 Security Fix - CSRF Protection
This PR adds CSRF token validation to all state-changing API requests as part of fixing multiple HIGH severity CSRF vulnerabilities.
🐛 Problem
The application currently sends API requests without CSRF tokens, allowing Cross-Site Request Forgery attacks. Affected endpoints:
DELETE /api/projects/:id/- Project deletionPATCH /api/projects/:id/- Project updatesPATCH /api/users/:id/- User profile updatesPOST /api/webhooks/- Webhook creation✅ Solution
Modified
ApiProvider.tsxto automatically includeX-CSRFTokenheader in all non-GET/HEAD requests.Changes Made
File:
frontend/src/providers/ApiProvider.tsxHow it works:
<meta name="csrfmiddlewaretoken" value="...">X-CSRFTokenheader to POST/PUT/PATCH/DELETE requests🧪 Testing
Before Fix:
After Fix:
Manual Testing Performed:
📊 Security Impact
Severity: HIGH (CVSS 8.1)
Prevents:
Attack Vector Blocked:
Attackers can no longer trick users into performing unwanted actions by visiting malicious websites.
This is the frontend component of the fix.
The backend must also:
X-CSRFTokenheader on protected endpointsSince backend code is not in this public repository, backend changes must be implemented separately.
🔗 Related
Issue: #372
Severity: HIGH
🎯 Files Changed
frontend/src/providers/ApiProvider.tsx- Add CSRF token to API calls🔐 Security Notice
This change alone is not sufficient to prevent CSRF attacks. Backend validation must also be implemented to:
Backend requirements:
Submitted by: @Stevo1935
Report Date: [11/19/2025]