fix(js-express): resolve CodeQL rate limit, regex, and query findings#119
Merged
Conversation
Add rate limiting on movie routes, escape user genre input for regex filters, and validate batch filter/update fields before MongoDB writes. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses CodeQL findings in the JS Express MFlix server by hardening request handling around /api/movies through rate limiting, safer regex construction, and sanitization of MongoDB filter/update payloads before DB writes.
Changes:
- Added an
express-rate-limitmiddleware applied to all/api/moviesroutes. - Escaped user-supplied
genreinput before building a case-insensitive$regexfilter. - Introduced
mongoQueryutilities to whitelist allowed MongoDB filter fields/operators and update fields, and applied them in single/batch update and batch delete handlers.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| mflix/server/js-express/tests/controllers/movieController.test.ts | Updates batch update test data; (recommended) add a test covering newly rejected update operators. |
| mflix/server/js-express/src/utils/mongoQuery.ts | New query/update sanitization helpers + regex escaping utility. |
| mflix/server/js-express/src/routes/movies.ts | Applies the movies rate limiter middleware to all movie routes. |
| mflix/server/js-express/src/middleware/rateLimiter.ts | New rate limiter configuration for movie routes. |
| mflix/server/js-express/src/controllers/movieController.ts | Uses regex escaping for genre and sanitizes batch/single update + batch delete filters/updates. |
| mflix/server/js-express/package.json | Adds express-rate-limit dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use createErrorResponse for rate limits, validate update payload shape, return 400 for invalid ObjectId filters, skip whitespace-only genres, and add tests for rejected batch update payloads. Co-authored-by: Cursor <cursoragent@cursor.com>
dacharyc
reviewed
Jun 5, 2026
dacharyc
reviewed
Jun 5, 2026
dacharyc
reviewed
Jun 5, 2026
dacharyc
reviewed
Jun 5, 2026
dacharyc
approved these changes
Jun 5, 2026
dacharyc
left a comment
Collaborator
There was a problem hiding this comment.
Couple of small suggested fixups for JS idiomaticity and consistency with the other apps, but otherwise LGTM ✅
Consolidate movie field allowlists, use generic filter/update error messages, replace as-never assignment, and configure rate limit via RATE_LIMIT_MAX env var in test setup. Co-authored-by: Cursor <cursoragent@cursor.com>
Collaborator
Author
|
Addressed review feedback in
|
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.
Summary
Resolves 20 open CodeQL findings in the JS Express MFlix server by adding API rate limiting, escaping user genre input for regex queries, and validating MongoDB filter/update payloads before database writes.
Changes
express-rate-limitmiddleware on all/api/moviesroutes viamoviesRateLimiter$regexfiltersmongoQuery.tsTesting
npm run test:unit— 58/58 passednpm run build— TypeScript compiles cleanlyRelated
Made with Cursor