Fix SQL injection vulnerabilities in authentication and product queries #90
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.
This PR fixes critical SQL injection vulnerabilities in the vulnerable-node application by replacing string concatenation in SQL queries with parameterized queries.
Vulnerabilities Fixed
The following functions were vulnerable to SQL injection attacks due to direct string concatenation of user input into SQL queries:
Authentication Module (
model/auth.js)do_auth(): User credentials were directly concatenated into the WHERE clauseBefore:
After:
Products Module (
model/products.js)getProduct(): Product ID was directly concatenated into the WHERE clausesearch(): Search query was directly concatenated into ILIKE clausespurchase(): All cart properties were directly concatenated into INSERT VALUESget_purcharsed(): Username was directly concatenated into the WHERE clauseBefore:
After:
Security Impact
These changes prevent attackers from:
Testing
The application now uses PostgreSQL's parameterized query feature through pg-promise, which automatically escapes and validates parameters to prevent SQL injection attacks.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.