-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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: Ensure Database Password Security Check Covers All Possible URIs #9078
base: alpha
Are you sure you want to change the base?
feat: Ensure Database Password Security Check Covers All Possible URIs #9078
Conversation
Thanks for opening this pull request! |
…eature/8833-database-password-security-check' of github.com:pavan-dulam/parse-server into feature/8833-database-password-security-check
Hi @mtrezza, Please review at your earliest convenience. Please let me know in case of any improvements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI fails
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## alpha #9078 +/- ##
==========================================
- Coverage 94.15% 93.75% -0.40%
==========================================
Files 186 186
Lines 14687 14727 +40
==========================================
- Hits 13829 13808 -21
- Misses 858 919 +61 ☔ View full report in Codecov by Sentry. |
Please see CI and coverage report |
if (databaseAdapter) { | ||
// If database adapter is defined, use its URI | ||
databaseUrl = databaseAdapter._uri; | ||
} else if (config.databaseURI) { | ||
// If database adapter is not defined, fallback to config.databaseURI | ||
databaseUrl = config.databaseURI; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the behavior of Parse Server if both are defined? Is there a way to remove this logic and access the DB URI in another way? Because maybe no matter how the URI is defined, I would imagine it ends up in the same place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current implementation of both are defined then the adaptor uri will take precedence. And if the adapter uri is not defined then it will go for db uri.
Please let me know if the logic needs to change, And what will be the correct logic
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current implementation of both are defined then the adaptor uri will take precedence.
Is that so? It seems that Parse Server throws an error if both are defined:
parse-server/src/Controllers/index.js
Lines 155 to 161 in 2420024
if ( | |
(databaseOptions || | |
(databaseURI && databaseURI !== defaults.databaseURI) || | |
collectionPrefix !== defaults.collectionPrefix) && | |
databaseAdapter | |
) { | |
throw 'You cannot specify both a databaseAdapter and a databaseURI/databaseOptions/collectionPrefix.'; |
I think - if possible - we should not replicate the logic here that is already defined in the code above. I suggest to pull the DB URI directly from the database controller. Let getDatabaseController
handle the logic and only check the URI of the controller, so that it doesn't matter how it is set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse-server/src/Controllers/index.js
Lines 160 to 167 in 2420024
) { | |
throw 'You cannot specify both a databaseAdapter and a databaseURI/databaseOptions/collectionPrefix.'; | |
} else if (!databaseAdapter) { | |
databaseAdapter = getDatabaseAdapter(databaseURI, collectionPrefix, databaseOptions); | |
} else { | |
databaseAdapter = loadAdapter(databaseAdapter); | |
} | |
return new DatabaseController(databaseAdapter, options); |
Got it, so here's what I'm thinking: In the above else if condition we can add one more condition to check if adaptor is assigned, if not we can assign the database URI to the adapter. This way, regardless of how the URI is set, it'll be considered. What do you think? Sounds like a plan to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like duplicating the logic? If the other logic changes, then this security check won't be accurate anymore because the duplicated logic will be different. Why not just get the DB controller and check the URI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick question for clarification: I took a look at the DB Controller class, but I couldn't spot any DBURI
there. Could you help me understand how I should go about pulling the URI? Thanks for your help!
parse-server/src/Controllers/DatabaseController.js
Lines 387 to 403 in 2420024
class DatabaseController { | |
adapter: StorageAdapter; | |
schemaCache: any; | |
schemaPromise: ?Promise<SchemaController.SchemaController>; | |
_transactionalSession: ?any; | |
options: ParseServerOptions; | |
idempotencyOptions: any; | |
constructor(adapter: StorageAdapter, options: ParseServerOptions) { | |
this.adapter = adapter; | |
this.options = options || {}; | |
this.idempotencyOptions = this.options.idempotencyOptions || {}; | |
// Prevent mutable this.schema, otherwise one request could use | |
// multiple schemas, so instead use loadSchema to get a schema. | |
this.schemaPromise = null; | |
this._transactionalSession = null; | |
this.options = options; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try like it's already done: databaseAdapter._uri;
where _uri
is an internal var? But you would not get it from the config that is passed when initializing Parse Server but from the initialized Parse Server. Btw, the internal var _uri
is not on the superclass StorageAdapter
, but in the subclasses like MongoStorageAdapter
. I think for now we can just assume that every storage adapter has an internal _uri
var, because I at least cannot think of an adapter that would not require a URI. Even though it's not the superclass.
Pull Request
Issue
Closes: #8833
Approach
Addressed issue #8833 where the database password security check was not checking all possible URIs. Updated the CheckGroupDatabase class to handle cases where the database adapter is not defined in the configuration object, ensuring compatibility with configurations that use
config.databaseURI
instead. Added error handling with descriptive error messages for password security requirements. Updated issue tracker accordingly.