Skip to content

refactor: Upgrade mongodb from 4.10.0 to 5.3.0 #8560

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

Closed
wants to merge 12 commits into from

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented May 22, 2023

Pull Request

Issue

Closes: #8550

Approach

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

@parse-github-assistant
Copy link

Thanks for opening this pull request!

@codecov
Copy link

codecov bot commented May 22, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.02 ⚠️

Comparison is base (967700b) 94.44% compared to head (328839f) 94.42%.

❗ Current head 328839f differs from pull request most recent head 7ff8fe1. Consider uploading reports for the commit 7ff8fe1 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #8560      +/-   ##
==========================================
- Coverage   94.44%   94.42%   -0.02%     
==========================================
  Files         183      183              
  Lines       14594    14593       -1     
==========================================
- Hits        13783    13780       -3     
- Misses        811      813       +2     
Impacted Files Coverage Δ
src/Adapters/Storage/Mongo/MongoCollection.js 97.43% <100.00%> (-0.24%) ⬇️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 92.16% <100.00%> (-0.04%) ⬇️
src/Adapters/Storage/Mongo/MongoTransform.js 88.61% <100.00%> (+0.08%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dblythy dblythy requested a review from a team May 22, 2023 08:03
@@ -457,6 +457,15 @@ const parseObjectKeyValueToMongoObjectKeyValue = (restKey, restValue, schema) =>
);
}
value = mapValues(restValue, transformInteriorValue);

if (
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain this a bit?

Copy link
Member Author

Choose a reason for hiding this comment

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

The updated mongodb seems to require a bson version when writing bson directly to the database

Copy link
Member

Choose a reason for hiding this comment

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

Do you have a docs reference? We may need to expose this in the DB adapter options if it should be user-configurable.

Copy link
Member Author

Choose a reason for hiding this comment

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

https://github.com/mongodb/js-bson/blob/main/docs/upgrade-to-v5.md#explicit-cross-version-incompatibility

The code that fails is:

      const params = {
        headers: headers,
        method: 'POST',
        url: 'http://localhost:8378/1/classes/RCE',
        body: JSON.stringify({
          obj: {
            _bsontype: 'Code',
            code: 'delete Object.prototype.evalFunctions',
          },
        }),
      };
      const response = await request(params).catch(e => e);

With the error:

Unsupported BSON version, bson types must be from bson 5.

As obj[Symbol.for('@@mdb.bson.version')] is undefined

Copy link
Member

@mtrezza mtrezza May 25, 2023

Choose a reason for hiding this comment

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

So we are changing the product code only because of the tests in vulnerabilities.spec.js? I know we have some code parts where we do something like this, but this seems rather hacky, as if it could break if the MongoDB Node.js adapter changed internally, for example renames its internal symbols. Is there a way to add this in the tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the code so that if _bsontype is specified, it is converted to a bson code. this makes the tests pass, but it will mean that support for sending other bson types will need to be added in time (as we don't support nested $)

Copy link
Member

@mtrezza mtrezza Jun 9, 2023

Choose a reason for hiding this comment

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

Not sure what the implication of this is. Could you give an example of what kind of query currently works but would not work anymore after this PR has been merged? We don't seem to have anything like that in our tests, since they pass, but the MongoDB adapter is versatile and I think there are vast areas we do not cover in tests but are legitimate and possibly frequent uses; for example BSON types can be used in aggregation pipeline.

Copy link
Member Author

Choose a reason for hiding this comment

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

How do you think we should approach this then? I don't think it's too big of a risk as custom _bsontypes have been the cause of a few vulnerabilities here

Copy link
Member

@mtrezza mtrezza Jun 12, 2023

Choose a reason for hiding this comment

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

So you mean it's still possible to use bson types in the aggregation pipeline? Could you give an example of what would not work anymore? Then we can add this at least to the changelog as a note.

@pocketcolin
Copy link
Contributor

👋 it would be awesome to get this merged. We've been having some issues with the older Mongo driver and think the updated mongo driver would fix it. What else is left to do before we can merge this?

@mtrezza
Copy link
Member

mtrezza commented Sep 25, 2023

We are working on it, see #8761 (comment)

@mtrezza mtrezza mentioned this pull request Sep 25, 2023
1 task
@mtrezza
Copy link
Member

mtrezza commented Feb 18, 2024

Closing via #8761

@mtrezza mtrezza closed this Feb 18, 2024
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.

4 participants