Skip to content

fix: Prototype Pollution#54

Merged
tbo47 merged 3 commits intotbo47:mainfrom
shubhamparikh2704:fix/prototype-pollution
Oct 21, 2025
Merged

fix: Prototype Pollution#54
tbo47 merged 3 commits intotbo47:mainfrom
shubhamparikh2704:fix/prototype-pollution

Conversation

@shubhamparikh2704
Copy link
Contributor

@shubhamparikh2704 shubhamparikh2704 commented Oct 9, 2025

This PR addresses a prototype pollution vulnerability (CVE-2025-57347, CWE-1321) in the addConflict() function within src/dagre/position/bk.js. The vulnerability allowed attackers to inject malicious property keys like proto to modify the JavaScript Object prototype chain, potentially leading to denial of service, application crashes, or arbitrary code execution.

This approach:

  • Prevents prototype pollution by using explicit property descriptors
  • Allows legitimate use of proto, constructor, and prototype as node IDs in graphs
  • Maintains backward compatibility with existing functionality

Resolves #52

@shubhamparikh2704 shubhamparikh2704 changed the title fix: Add isSafeKey function to validate object property keys and prevent prototype pollution fix: Prototype Pollution Oct 9, 2025
@sh-shamsan
Copy link

LGTM

@npnsap
Copy link

npnsap commented Oct 14, 2025

Could we prioritize merging this?

Copy link
Collaborator

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

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

Looks good to me!

I think this new approach using Object.defineProperty is much better then what you had in ad80439, and it's less likely to break any existing code if it does happen to use __proto__ or constructor.

I think we can make the new prop writable too, to avoid potentially breaking anybody that is directly using the addConflict() function, but I doubt anybody is, and dagre doesn't seem to care if the created props are writable or not.

This won't affect any code that dagre uses, but it might affect third-party libraries.
@aloisklink
Copy link
Collaborator

@tbo47, I don't have publish permissions on NPM. Would you be up for merging this and making a 7.0.13 release?

I don't think anybody is using this addConflict function directly, but it's probably worth releasing it for anybody using an automated scanner that's complaining about this issue.

@tbo47 tbo47 merged commit dbe53cb into tbo47:main Oct 21, 2025
yhwang pushed a commit to prestodb/presto that referenced this pull request Oct 27, 2025
## Description
Upgrade the patch version of dagre-d3-es to the [latest
release](tbo47/dagre-es#54) to address a
critical vulnerability
([CVE-2025-57347](GHSA-cc8p-78qf-8p7q))
identified in recent security scans.

## Motivation and Context

## Impact
N/A
## Test Plan
Manual test

## Contributor checklist

- [x] Please make sure your submission complies with our [contributing
guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md),
in particular [code
style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style)
and [commit
standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [x] PR description addresses the issue accurately and concisely. If
the change is non-trivial, a GitHub Issue is referenced.
- [ ] Documented new properties (with its default value), SQL syntax,
functions, or other functionality.
- [ ] If release notes are required, they follow the [release notes
guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [ ] Adequate tests were added if applicable.
- [ ] CI passed.
- [ ] If adding new dependencies, verified they have an [OpenSSF
Scorecard](https://securityscorecards.dev/#the-checks) score of 5.0 or
higher (or obtained explicit TSC approval for lower scores).

## Release Notes
Please follow [release notes
guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines)
and fill in the release notes below.

```
== RELEASE NOTES ==

General Changes
* Upgrade dagre-d3-es to 7.0.13 in response to `CVE-2025-57347 <https://github.com/advisories/GHSA-cc8p-78qf-8p7q>`_.
@mrjono1
Copy link

mrjono1 commented Nov 6, 2025

This didn't seem to work so I have created this with the help of cursor #59

aloisklink added a commit to aloisklink/dagre-es that referenced this pull request Nov 19, 2025
This fixes any potential type errors when calling the `addConflict`
function in our unit tests, after the changes from
dbe53cb (fix: Prototype Pollution (tbo47#54), 2025-10-21).

Fixes: dbe53cb
tbo47 pushed a commit that referenced this pull request Dec 3, 2025
* test: type `var conflicts` vars in `bk.test.js`

This fixes any potential type errors when calling the `addConflict`
function in our unit tests, after the changes from
dbe53cb (fix: Prototype Pollution (#54), 2025-10-21).

Fixes: dbe53cb

* test: import missing `beforeEach` and `afterEach`

Vitest adds these automatically, so it didn't cause any issues when
running the tests, but it did cause issues with TypeScript.

* test: type `var g` with `Graph`

This lets TypeScript check that the functions we call on this type are
valid.

* build: change `tsconfig.json` to type-check tests

Update the `tsconfig.json` file to also type-check the tests, checking
for any potential mistakes we make in TypeScript.

The new `tsconfig.build.json` file is then used for actually building
the types.

* fix(types): improve horizontalCompaction type

* feat(types): improve `Graph` documented types

I've manually gone through the JSDoc references within the
`src/graphlib/graph.js` file and added JSDoc comments when TypeScript
couldn't automatically find detect the types.

I've tried to keep the types as backwards compatible as possible.

There's also an MIT-licensed [`@types/graphlib`][1] package that we can
copy code from, but I didn't do that since I noticed issues with it that
were causing our unit tests to fail type-checking (e.g. not allowing
`number`s as params for lots of functions, even though the test code
uses it a lot).

[1]: http://npmjs.com/package/@types/graphlib

* docs: copy over graphlib documentation for Graph

Update the Graph documentation with a mixture of:

1. API documentation from the graphlib wiki:
   https://github.com/dagrejs/graphlib/wiki/API-Reference
2. Documentation from
   https://github.com/dagrejs/graphlib/blob/64b31ef3df0270c9bda85b45cb338481ce25618d/lib/graph.js

Both of these are from the graphlib MIT license, which we're
already complying with.
@frenzymadness frenzymadness mentioned this pull request Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prototype Pollution in dagre-d3-es Prior to 7.0.11

6 participants