Security Fix: Add CSRF Protection to API Requests (Frontend)#371
Open
Stevo1935 wants to merge 2 commits intoAIxBlock-2023:mainfrom
Open
Security Fix: Add CSRF Protection to API Requests (Frontend)#371Stevo1935 wants to merge 2 commits intoAIxBlock-2023:mainfrom
Stevo1935 wants to merge 2 commits intoAIxBlock-2023:mainfrom
Conversation
- Add X-CSRFToken header to all state-changing requests (POST, PUT, PATCH, DELETE) - Retrieve token from DOM meta tag via getCsrfToken() - Prevent CSRF attacks on project, user, and webhook endpoints - GET and HEAD requests unaffected (no token needed) This frontend change requires corresponding backend CSRF validation. Fixes: Multiple CSRF vulnerabilities Severity: HIGH (CVSS 8.1) Related Issue: #[ISSUE_NUMBER]
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.
🔒 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]