Skip to content

JavaScript: private workspace packages are treated as library input (slow js/prototype-polluting-assignment, false positives) #23163

Backlog

Description

@kolacheee

Description of the issue

PackageExports::getALibraryInputParameter() treats every parameter of a function exported from a named package.json as untrusted library input, including packages marked "private": true, which npm refuses to publish. In a pnpm monorepo, a private workspace package that the app's own server and client import becomes thousands of sources for js/prototype-polluting-assignment and js/polynomial-redos.

In Pasta-Devs/Marinara-Engine (CodeQL 2.27.4, build-mode: none, default query suite):

  • @marinara-engine/shared is private and re-exports its API from src/index.ts. 4,459 of the 7,316 sources of js/prototype-polluting-assignment are its function parameters.
  • js/prototype-polluting-assignment takes about 26 minutes on a GitHub-hosted runner, more than half of the full scan. Flow::Stage4::fwdFlow1 reaches 215 million tuples.
  • The query is diff-informed, so a pull request scan runs it in full whenever the diff touches one of its sources or sinks. That holds for every scan of such a PR, which takes 20 to 38 minutes each time instead of about 4. Over five days, 30 of 215 PRs (14%) ended with a slow scan; for one contributor whose PRs often touch server code, 9 of 31. Each new push cancels the running scan, so one PR spent 118 minutes on 7 cancelled scans before its final 22-minute scan.
  • All 5 of its alerts are false positives; 4 have a library input as their source.
  • Query filters don't help: codeql-action enables overlay analysis for JavaScript only with the default query suite, so excluding the query makes every PR scan a full scan.

NPM.qll already has PackageJson.isPrivate(). Skipping private packages in PackageExports.qll:

-    getAnExportFromModule(any(PackageJson pack | exists(pack.getPackageName())).getExportedModule(_))
+    getAnExportFromModule(any(PackageJson pack | exists(pack.getPackageName()) and not pack.isPrivate()).getExportedModule(_))
-    func.getFile() = any(PackageJsonEx pack).getMainFileOrBestGuess()
+    func.getFile() = any(PackageJsonEx pack | not pack.isPrivate()).getMainFileOrBestGuess()

Measured on the same database with --threads=4 --ram=14500, the limits codeql-action uses on a hosted runner:

Query Before After
js/prototype-polluting-assignment 586 s, 5 results 43 s, 0 results
js/polynomial-redos 165 s, 0 results 34 s, 0 results

The change also removes the one alert whose source is a remote flow source (req.body in packages/server/src/routes/connections.routes.ts:825, sink in packages/server/src/utils/stored-secrets.ts:179). That alert is a false positive: the property name comes from a constant list stored in the same tuple array as the tainted object. I couldn't find why removing library-input sources removes a path that starts at a remote source.

To reproduce, at commit 77c60cce8d798f5b885f81ffab42ae8794123aa9:

codeql database create db --language=javascript --build-mode=none --source-root=. --codescanning-config=config.yml
codeql database run-queries db codeql/javascript-queries:Security/CWE-915/PrototypePollutingAssignment.ql --threads=4 --ram=14500

with config.yml:

paths-ignore:
  - scripts/regressions
  - e2e

Activity

  1. jketema commented on Nov 19, 2026

    @jketema
    Contributor

    Hi @kolacheee,

    Thanks for the report. I've passed this on to the responsible team.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions