Add Input Validation Middleware to ATS Score Endpoint #24
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.
🐛 Problem
The
/api/ats-scoreendpoint (added in recent updates) lacks proper input validation middleware, creating several security and consistency issues:Security Vulnerability: No max length validation allows potential DoS attacks
Inconsistency: Unlike
/api/compileand/api/optimizeendpoints which use validation middleware, this endpoint uses manual validation inside the handlerMissing Type Checks: No validation for data types (could send objects/arrays instead of strings)
Poor Error Messages: Manual validation provides less detailed error feedback
✅ Solution
Added
validateATSScoremiddleware inbackend/middleware/validation.jsresumeText: required, string, 1-50,000 charactersjobDescription: required, string, 10-10,000 charactersexpress-validatorfor consistent validation patternsApplied validation to endpoint in
backend/app.jsvalidateATSScoreto middleware chain🧪 Testing
Created comprehensive test suite with 8 test cases - all passing ✅
Test Results:
What Was Tested:
📝 Changes
backend/middleware/validation.jsbackend/app.jsBefore:
After:
🔒 Security Improvements
🎨 Code Quality
📋 Checklist
🔗 Related
📊 Impact
Reviewer Notes:
This PR follows the same validation pattern established in previous merged PRs. The validation rules are appropriate for the ATS scoring use case and prevent potential abuse of the TF-IDF calculation endpoint.