Skip to content

JS: Improve Express middleware taint tracking #19784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Napalys
Copy link
Contributor

@Napalys Napalys commented Jun 16, 2025

Improves Express middleware taint tracking by:

  • Using getALocalSource() to better handle default value expressions and similar patterns in middleware data flow
  • Adding req._parsedUrl as a remote input source

@Napalys Napalys force-pushed the js/express_middleware branch from 4918962 to 7252874 Compare June 17, 2025 06:34
@Napalys Napalys marked this pull request as ready for review June 17, 2025 07:09
@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 07:09
@Napalys Napalys requested a review from a team as a code owner June 17, 2025 07:09
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _parsedUrl handling.
  • Update QL library to recognize _parsedUrl properties and use getALocalSource() 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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant