Add Input Sanitization for SQL Injection Prevention (#93)#162
Open
David-patrick-chuks wants to merge 3 commits intollinsss:masterfrom
Open
Add Input Sanitization for SQL Injection Prevention (#93)#162David-patrick-chuks wants to merge 3 commits intollinsss:masterfrom
David-patrick-chuks wants to merge 3 commits intollinsss:masterfrom
Conversation
|
@David-patrick-chuks is attempting to deploy a commit to the llinsomoudu-gmailcom's projects Team on Vercel. A member of the Team first needs to authorize it. |
👷 Deploy request for taggedpay pending review.Visit the deploys page to approve it
|
Contributor
Author
@llinsss Done! I've removed package-lock.json |
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.
Overview
This PR introduces a robust, global SQL injection prevention mechanism. A new middleware layer intercepts all incoming requests to actively detect and block malicious payloads (like
UNION SELECT,DROP TABLE, etc.) before they reach our controllers, ensuring maximum database security.Related Issue
Closes #93
Changes
� Security Middleware
backend/middleware/validation.js:detectSqlInjectionmiddleware.req.query,req.body, andreq.params(even in deeply nested objects) for destructive SQL patterns.403 Forbidden: Suspicious input detectedresponse when an attack is spotted, completely neutralizing it at the routing level.� Global Integration
backend/app.js:detectSqlInjectionglobally into the Express app directly after the body parsers and right before standard sanitization. This provides a universal security umbrella across all API endpoints seamlessly.📊 Model Audits
backend/models/*.js:insert,update, and standardwhereclauses, minimizing internal vulnerability surface.🧪 Automated Guards
backend/tests/sql_injection.test.js:Verification Results
UNION SELECTin queries;--) in queriesDROP TABLEin request bodyHow to Test
npm run devGET /healthorPOST /api/auth/login). Ensure it succeeds smoothly.GET /health?filter=1; DROP TABLE users;--403 Forbiddenresponse.{ "password": "password' OR 1=1--" }403 Forbiddenresponse.Screenshots & Evidence
1. Malicious Request Blocked (Postman/cURL)
2. Automated Test Suite Success