Skip to content
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

feat: Prevent Parse Server start in case of unknown option in server configuration #8987

Merged
merged 33 commits into from
Apr 7, 2024
Merged

Conversation

vivekjoshi556
Copy link
Contributor

Pull Request

Issue

Closes: #8938

Approach

Created a simple function that checks provided configuration keys against a list of possible keys (retrieved from the definitions file at src/Options/Definition.js). If any provided key is not valid, the function logs a warning message.

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

Copy link

Thanks for opening this pull request!

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

Could you please separate the test into distinct tests, each with their own specific description, for example these scenarios:
a) no warning logged if no unknown option is set
b) warning logged if unknown option is set on root { unknown: 1 }
c) ... on sub object { a: { unknown: 1 }}
d) 2 warnings logged on 2 invalid options

Could you also please rename the warning msg to:

“The following Parse Server option is not recognized”, instead of “key”.

Also, I believe the server shouldn’t even start up if an invalid option has been set, because it is likely configured incorrectly, which could affect data integrity, security, app performance or user experience.

@vivekjoshi556
Copy link
Contributor Author

Hello @mtrezza,

For tests, the given test includes these 3 conditions that you mentioned.
b) warning logged if unknown option is set on root { unknown: 1 }
c) ... on sub object { a: { unknown: 1 }}
d) 2 warnings logged on 2 invalid options

Is there something else that you want me to do in that respect?
I'll make other changes ASAP.

@mtrezza
Copy link
Member

mtrezza commented Mar 6, 2024

Yes, could you please refactor the test into individual tests, one for reach scenario? The purpose of a test is to test a specific scenario that is described in the test title. So that it's easier to debug if a specific test fails, than a composite test that contains many smaller tests. The repetitive code can be moved into the describe section, like the spies.

@vivekjoshi556
Copy link
Contributor Author

vivekjoshi556 commented Mar 9, 2024

Hi @mtrezza,

Before I was checking for config variables based on the keys of defnitions from Definitions.js, but now I realize that there are several other keys that are being used that are not mentioned in those defnitions: level, loggerController, filesController, userController, pushController, pushWorker, ....
To handle all these cases is there a single place where I can get name of all these variables that need to be handled?

@mtrezza
Copy link
Member

mtrezza commented Mar 9, 2024

Not sure, I think all these options should be somewhere in the code; but I'm not sure if there is a comprehensive list of all options. Maybe the definitions file of the Parse Server options is the best source for that?

@vivekjoshi556
Copy link
Contributor Author

Not sure, I think all these options should be somewhere in the code; but I'm not sure if there is a comprehensive list of all options. Maybe the definitions file of the Parse Server options is the best source for that?

The definitions files doesn't give most of the variables.
I can look at all the warnings that I am getting and add them manually. Do you think that it would be right way to go here?

@mtrezza
Copy link
Member

mtrezza commented Mar 9, 2024

I believe we need a solution that doesn't require maintaining a separate list if we already have a list, like the definitions. What is missing in the definitions file, for example?

@vivekjoshi556
Copy link
Contributor Author

vivekjoshi556 commented Mar 9, 2024

I believe we need a solution that doesn't require maintaining a separate list if we already have a list, like the definitions. What is missing in the definitions file, for example?

state, loggerController, hasPushScheduledSupport, authDataManager, masterKeyIpsStore, maintenanceKeyIpsStore

to name some.

@mtrezza
Copy link
Member

mtrezza commented Mar 9, 2024

Are these really Parse Server options?

I mean the main issue is, if they are not in the definitions file, then they are not (poorly) documented Parse Server options, because the docs for them is auto generated from the definitions file.

If they are really undocumented then I suggest to add them to the definitions file, which is fairly easy to do. You could take a look at the existing options and then just add them. There are instructions on how to do that here.

@vivekjoshi556
Copy link
Contributor Author

Yes, I understand but at one point or another they are expected in the config variable. They are also used in test files as well which is causing a lot of log messages during tests.
hasPushScheduledSupport -> src/StatusHandler.js

@mtrezza
Copy link
Member

mtrezza commented Mar 10, 2024

Yes, so I believe the definitions file is the actual source to determine whether an option key is valid or not. If an options is missing there then that's likely a bug and we could simply add it, as part of this feature. I assume they are not many?

@vivekjoshi556
Copy link
Contributor Author

vivekjoshi556 commented Mar 10, 2024

I ran tests, some of them didn't pass, but I got warning messages for these keys:

cacheController, loggerController, filesController, 3, masterKeyIpsStore, pushController, exampleKey, rateLimits, 5, userController, state, hasPushScheduledSupport, version, _mount, retryWrites, 4, databaseController, authDataManager, parseGraphQLController, schemaCache, RateLimitZone, 0, liveQueryController, database, generateEmailVerifyTokenExpiresAt, generateSessionExpiresAt, analyticsController, maintenanceKeyIpsStore, patternValidator, 2, hooksController, SchemaCacheTtl, level, hasPushSupport, pushWorker, applicationId, 1, pushControllerQueue

@mtrezza
Copy link
Member

mtrezza commented Mar 10, 2024

The items _mount and the numbers 0, etc make me think that the keys you are checking are not the right ones.

@vivekjoshi556
Copy link
Contributor Author

Sorry for late reply. You were right there was a slight mistake that numbers were getting printed. But I looked into other keys and the locations they are set:

_mount
level
Controllers, hasPushSupport, pushWorker, pushControllerQueue, authDataManager, schemaCache
state
masterKeyIpsStore
maintenanceKeyIpsStore
rateLimits

and some others keys.

@vivekjoshi556 vivekjoshi556 marked this pull request as draft March 12, 2024 17:43
@mtrezza
Copy link
Member

mtrezza commented Mar 12, 2024

Yes, so whatever is missing and is really a Parse Server option may need to to be added to the definitions file. That's easy, see the link I shared previously. I doubt that _mount is a Parse Server option, it looks more like an internal variable. You may need to add a list for excluded keys because we know these are internal keys.

…nfig variables | fixed issues with initial validations
@vivekjoshi556
Copy link
Contributor Author

Hey @mtrezza,

I'm done with this one. Please review and let me know if something else needs to be changed.

@mtrezza
Copy link
Member

mtrezza commented Mar 14, 2024

Could you resolve the conflicts?

@vivekjoshi556 vivekjoshi556 reopened this Mar 14, 2024
@vivekjoshi556 vivekjoshi556 marked this pull request as ready for review March 14, 2024 13:52
@vivekjoshi556
Copy link
Contributor Author

@mtrezza, Conflicts resolved.

src/Config.js Outdated Show resolved Hide resolved
Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 97.22222% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 94.14%. Comparing base (f1469c6) to head (7ac43a5).

Files Patch % Lines
src/Config.js 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #8987   +/-   ##
=======================================
  Coverage   94.13%   94.14%           
=======================================
  Files         186      186           
  Lines       14687    14722   +35     
=======================================
+ Hits        13826    13860   +34     
- Misses        861      862    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mtrezza
Copy link
Member

mtrezza commented Apr 6, 2024

Yes, sounds good!

src/Config.js Outdated Show resolved Hide resolved
src/Config.js Outdated Show resolved Hide resolved
src/Config.js Outdated Show resolved Hide resolved
src/Config.js Outdated Show resolved Hide resolved
src/Config.js Outdated Show resolved Hide resolved
src/Config.js Outdated Show resolved Hide resolved
src/Config.js Outdated Show resolved Hide resolved
src/Config.js Outdated Show resolved Hide resolved
Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

Very nice! This looks much cleaner now. Let's wait for the CI to pass, then this is good to merge?

@vivekjoshi556
Copy link
Contributor Author

Very nice! This looks much cleaner now. Let's wait for the CI to pass, then this is good to merge?

yes it is done from my end.

@mtrezza mtrezza changed the title feat: Prevent server start in case of a unknown options in Parse Server configuration feat: Prevent Parse Server start in case of unknown option in server configuration Apr 7, 2024
@mtrezza mtrezza merged commit 8758e6a into parse-community:alpha Apr 7, 2024
24 of 26 checks passed
parseplatformorg pushed a commit that referenced this pull request Apr 7, 2024
# [7.1.0-alpha.5](7.1.0-alpha.4...7.1.0-alpha.5) (2024-04-07)

### Features

* Prevent Parse Server start in case of unknown option in server configuration ([#8987](#8987)) ([8758e6a](8758e6a))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 7.1.0-alpha.5

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Apr 7, 2024
@vivekjoshi556 vivekjoshi556 deleted the issue_8938 branch April 7, 2024 13:33
parseplatformorg pushed a commit that referenced this pull request Jun 30, 2024
# [7.1.0-beta.1](7.0.0...7.1.0-beta.1) (2024-06-30)

### Bug Fixes

* `Parse.Cloud.startJob` and `Parse.Push.send` not returning status ID when setting Parse Server option `directAccess: true` ([#8766](#8766)) ([5b0efb2](5b0efb2))
* `Required` option not handled correctly for special fields (File, GeoPoint, Polygon) on GraphQL API mutations ([#8915](#8915)) ([907ad42](907ad42))
* Facebook Limited Login not working due to incorrect domain in JWT validation ([#9122](#9122)) ([9d0bd2b](9d0bd2b))
* Live query throws error when constraint `notEqualTo` is set to `null` ([#8835](#8835)) ([11d3e48](11d3e48))
* Parse Server option `extendSessionOnUse` not working for session lengths < 24 hours ([#9113](#9113)) ([0a054e6](0a054e6))
* Rate limiting can fail when using Parse Server option `rateLimit.redisUrl` with clusters ([#8632](#8632)) ([c277739](c277739))
* SQL injection when using Parse Server with PostgreSQL; fixes security vulnerability [GHSA-c2hr-cqg6-8j6r](GHSA-c2hr-cqg6-8j6r) ([#9167](#9167)) ([2edf1e4](2edf1e4))

### Features

* Add `silent` log level for Cloud Code ([#8803](#8803)) ([5f81efb](5f81efb))
* Add server security check status `security.enableCheck` to Features Router ([#8679](#8679)) ([b07ec15](b07ec15))
* Prevent Parse Server start in case of unknown option in server configuration ([#8987](#8987)) ([8758e6a](8758e6a))
* Upgrade to @parse/push-adapter 6.0.0 ([#9066](#9066)) ([18bdbf8](18bdbf8))
* Upgrade to @parse/push-adapter 6.2.0 ([#9127](#9127)) ([ca20496](ca20496))
* Upgrade to Parse JS SDK 5.2.0 ([#9128](#9128)) ([665b8d5](665b8d5))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 7.1.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Jun 30, 2024
parseplatformorg pushed a commit that referenced this pull request Jun 30, 2024
# [7.1.0](7.0.0...7.1.0) (2024-06-30)

### Bug Fixes

* `Parse.Cloud.startJob` and `Parse.Push.send` not returning status ID when setting Parse Server option `directAccess: true` ([#8766](#8766)) ([5b0efb2](5b0efb2))
* `Required` option not handled correctly for special fields (File, GeoPoint, Polygon) on GraphQL API mutations ([#8915](#8915)) ([907ad42](907ad42))
* Facebook Limited Login not working due to incorrect domain in JWT validation ([#9122](#9122)) ([9d0bd2b](9d0bd2b))
* Live query throws error when constraint `notEqualTo` is set to `null` ([#8835](#8835)) ([11d3e48](11d3e48))
* Parse Server option `extendSessionOnUse` not working for session lengths < 24 hours ([#9113](#9113)) ([0a054e6](0a054e6))
* Rate limiting can fail when using Parse Server option `rateLimit.redisUrl` with clusters ([#8632](#8632)) ([c277739](c277739))
* SQL injection when using Parse Server with PostgreSQL; fixes security vulnerability [GHSA-c2hr-cqg6-8j6r](GHSA-c2hr-cqg6-8j6r) ([#9167](#9167)) ([2edf1e4](2edf1e4))

### Features

* Add `silent` log level for Cloud Code ([#8803](#8803)) ([5f81efb](5f81efb))
* Add server security check status `security.enableCheck` to Features Router ([#8679](#8679)) ([b07ec15](b07ec15))
* Prevent Parse Server start in case of unknown option in server configuration ([#8987](#8987)) ([8758e6a](8758e6a))
* Upgrade to @parse/push-adapter 6.0.0 ([#9066](#9066)) ([18bdbf8](18bdbf8))
* Upgrade to @parse/push-adapter 6.2.0 ([#9127](#9127)) ([ca20496](ca20496))
* Upgrade to Parse JS SDK 5.2.0 ([#9128](#9128)) ([665b8d5](665b8d5))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 7.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log a warning in case of a unknown options
6 participants