- ✅ LaTeX code validation (size, format, dangerous commands)
- ✅ Job description validation (length, format)
- ✅ Resume LaTeX validation
- ✅ Clear error messages for validation failures
- ✅ General API: 100 requests per 15 minutes
- ✅ Compile endpoint: 10 requests per 15 minutes
- ✅ Optimize endpoint: 5 requests per 15 minutes
- ✅ Dangerous LaTeX command detection
- ✅ Input size limits
- ✅ Proper CORS configuration
- ✅ Environment variable validation
- ✅ Centralized error handler
- ✅ Consistent error responses
- ✅ 404 handler for unknown routes
- ✅ Async error handling
- ✅ Health check endpoint
- ✅ Better server startup logging
- ✅ Configurable PORT via environment
cd backend
node app.jsResult: Server starts successfully with clear logging
✓ Server running on port 3000
✓ Environment: development
✓ CORS origin: http://localhost:5173
Test Command:
curl http://localhost:3000/api/healthExpected Response:
{
"success": true,
"message": "ResuMatrix API is running",
"timestamp": "2025-10-14T..."
}Test Command:
curl -X POST http://localhost:3000/api/compile \
-H "Content-Type: application/json" \
-d "{}"Expected Response:
{
"success": false,
"message": "Validation failed",
"errors": [
{
"field": "code",
"message": "LaTeX code is required"
}
]
}Test Command:
curl -X POST http://localhost:3000/api/compile \
-H "Content-Type: application/json" \
-d '{"code": ""}'Expected Response:
{
"success": false,
"message": "Validation failed",
"errors": [
{
"field": "code",
"message": "Code cannot be empty"
}
]
}Test Command:
curl -X POST http://localhost:3000/api/compile \
-H "Content-Type": application/json" \
-d '{"code": "\\documentclass{article}\\write18{malicious command}\\begin{document}Test\\end{document}"}'Expected Response:
{
"success": false,
"message": "Validation failed",
"errors": [
{
"field": "code",
"message": "Potentially dangerous LaTeX command detected: \\write18"
}
]
}Test Command:
curl -X POST http://localhost:3000/api/compile \
-H "Content-Type: application/json" \
-d '{"code": "\\documentclass{article}\\begin{document}Hello World\\end{document}"}'Expected: PDF binary data or compilation error (depending on LaTeX installation)
Test: Make 11 requests to /api/compile within 15 minutes
After 10th request:
{
"success": false,
"message": "Too many compilation requests. Please try again later.",
"retryAfter": "... seconds"
}Test: Make 6 requests to /api/optimize within 15 minutes
After 5th request:
{
"success": false,
"message": "Too many AI optimization requests. Please try again later.",
"retryAfter": "... seconds"
}Test Command:
curl http://localhost:3000/api/nonexistentExpected Response:
{
"success": false,
"message": "Route /api/nonexistent not found"
}Test Command:
curl -X POST http://localhost:3000/api/optimize \
-H "Content-Type: application/json" \
-d '{"jobDescription": "short", "resumeLatex": "test"}'Expected Response:
{
"success": false,
"message": "Validation failed",
"errors": [
{
"field": "jobDescription",
"message": "Job description must be between 10 and 10000 characters"
}
]
}The following potentially dangerous LaTeX commands are now blocked:
\write18- Shell escape\immediate\write- Write to files\input{/etc/- Read system files\include{/etc/- Include system files\openout- Open output streams\openin- Open input streams\read- Read from files\csname- Execute arbitrary commands@@input- Internal input command\catcode- Change character codes
| Endpoint | Limit | Window |
|---|---|---|
| General API | 100 requests | 15 min |
/api/compile |
10 requests | 15 min |
/api/optimize |
5 requests | 15 min |
GEMINI_API_KEY=your_api_key_here
FRONTEND_URL=http://localhost:5173
PORT=3000
NODE_ENV=developmentAll errors now follow a consistent format:
{
"success": false,
"message": "Error description",
"errors": [ // Optional, for validation errors
{
"field": "fieldName",
"message": "Specific error"
}
]
}All successful responses now include:
{
"success": true,
// ... additional data
}backend/middleware/validation.js- Input validation logicbackend/middleware/rateLimiter.js- Rate limiting configurationbackend/middleware/errorHandler.js- Centralized error handling
backend/app.js- Integrated all middlewarebackend/package.json- Added new dependencies, fixed entry point
{
"express-rate-limit": "^8.1.0",
"express-validator": "^7.2.1"
}- LaTeX Injection Prevention: Blocks dangerous commands that could execute system commands
- Input Size Limits: Prevents memory exhaustion attacks
- Rate Limiting: Prevents API abuse and DDoS
- Validation: Ensures all inputs are properly formatted
- Error Information Leakage: Development vs production error details
- CORS: Properly configured origin restrictions
Before deploying to production:
- Set
NODE_ENV=productionin environment - Configure proper
FRONTEND_URL - Adjust rate limits based on expected traffic
- Consider adding authentication/API keys
- Set up proper logging (Winston, Morgan)
- Add monitoring and alerting
- Consider using Redis for distributed rate limiting
Potential future enhancements:
- Add unit tests for middleware
- Add integration tests
- Implement API key authentication
- Add request logging
- Add metrics collection
- Implement caching for repeated requests
- Add database for storing user resumes
- Add WebSocket support for real-time compilation