JS: Improve Express middleware taint tracking#19784
Merged
Napalys merged 5 commits intogithub:mainfrom Jun 20, 2025
Merged
Conversation
4918962 to
7252874
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
Implements enhanced taint tracking in Express middleware by leveraging getALocalSource() and adding req._parsedUrl as an input source.
- Introduce a test (
serverSide2.js) to validate default-value and_parsedUrlhandling. - Update QL library to recognize
_parsedUrlproperties and usegetALocalSource()in routing analysis. - Refresh expected outputs and add change notes for these enhancements.
Reviewed Changes
Copilot reviewed 7 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| javascript/ql/test/query-tests/Security/CWE-918/serverSide2.js | New test exercising middleware flows with req._parsedUrl and defaults |
| javascript/ql/test/query-tests/Security/CWE-918/RequestForgery.expected | Updated expected alerts/provenance for the new test |
| javascript/ql/lib/semmle/javascript/frameworks/Express.qll | Extended remote input source matching to include _parsedUrl |
| javascript/ql/lib/semmle/javascript/Routing.qll | Added getALocalSource() to the middleware data-flow assignment rule |
| javascript/ql/lib/change-notes/2025-06-16-middleware-express.md | Documented the middleware taint-tracking improvements |
Comments suppressed due to low confidence (2)
javascript/ql/test/query-tests/Security/CWE-918/serverSide2.js:10
- req.parsedQuery is never initialized before assigning to its url property, which will cause a runtime error. Consider adding
req.parsedQuery = {}before this line.
req.parsedQuery.url = req.url || {}; // $Source[js/request-forgery]
javascript/ql/test/query-tests/Security/CWE-918/serverSide2.js:11
- req.SomeObject is undefined when assigning to its url property, leading to a TypeError. Initialize
req.SomeObject = {}before this assignment.
req.SomeObject.url = req.url; // $Source[js/request-forgery]
tausbn
previously approved these changes
Jun 20, 2025
Contributor
tausbn
left a comment
There was a problem hiding this comment.
One small suggestion, otherwise LGTM. 👍
Co-authored-by: Taus <tausbn@github.com>
tausbn
approved these changes
Jun 20, 2025
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.
Improves Express middleware taint tracking by:
getALocalSource()to better handle default value expressions and similar patterns in middleware data flowreq._parsedUrlas a remote input source