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

refactor(query): deprecate explain without master key #7521

Open
wants to merge 5 commits into
base: alpha
Choose a base branch
from

Conversation

mstniy
Copy link
Contributor

@mstniy mstniy commented Aug 24, 2021

New Pull Request Checklist

Issue Description

Currently, any user is able to run a query with the explain parameter and obtain the raw result returned by MongoDB. This discloses too much information to the clients, nor is it of great utility to them.

Related issue: #7519

Approach

rest.js now prints a deprecation warning if a non-master user tries to run an explain query. Client-facing behaviour is intact.

TODOs before merging

  • Add test cases
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

…on warning

Added pending tests that ensure non-master users cannot run explain queries
Added the change to the CHANGELOG
@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #7521 (3577c96) into master (1e0d408) will increase coverage by 0.00%.
The diff coverage is 80.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #7521   +/-   ##
=======================================
  Coverage   93.92%   93.92%           
=======================================
  Files         181      181           
  Lines       13273    13278    +5     
=======================================
+ Hits        12467    12472    +5     
  Misses        806      806           
Impacted Files Coverage Δ
src/rest.js 97.84% <80.00%> (-1.02%) ⬇️
src/batch.js 91.37% <0.00%> (-1.73%) ⬇️
src/RestWrite.js 93.78% <0.00%> (-0.16%) ⬇️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 93.02% <0.00%> (+0.65%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e0d408...3577c96. Read the comment docs.

DEPRECATIONS.md Outdated Show resolved Hide resolved
@mtrezza mtrezza changed the title security(query): deprecate explain without master key refactor(query): deprecate explain without master key Aug 25, 2021
@mtrezza
Copy link
Member

mtrezza commented Aug 26, 2021

@mstniy Please feel free to request a review once this is ready.

@mstniy mstniy requested a review from mtrezza August 26, 2021 18:18
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.

Apologies for the long wait time, it has slipped through my notifications...

If you rebase this on master, you'll find a new deprecation ID in the deprecation table. you can just increment the last one for this deprecation.

@@ -6,6 +6,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h
|-------------------------------------------------|----------------------------------------------------------------------|---------------------------------|---------------------------------|-----------------------|-------|
| Native MongoDB syntax in aggregation pipeline | [#7338](https://github.com/parse-community/parse-server/issues/7338) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
| Config option `directAccess` defaults to `true` | [#6636](https://github.com/parse-community/parse-server/pull/6636) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
| `explain` queries used by non-master users | [#7519](https://github.com/parse-community/parse-server/issues/7519) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
Copy link
Member

Choose a reason for hiding this comment

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

Can you rephrase that as

Execute explain queries without masterkey

And can you add an ID for this deprecation, after you merge master into this PR

@@ -5218,4 +5218,36 @@ describe('Parse.Query testing', () => {
// Validate
expect(result.executionStats).not.toBeUndefined();
});

xit('users cannot use explain queries', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

I assume this is in preparation for after the deprecation?

Could you add a short comment above?

Deprecation DEPPS3: enable this test after deprecation

Assuming that DEPPS3 is the ID of this deprecation

equal(e.message, 'Cannot explain');
}
}).pend('Disabled until non-master explains are disabled');
it('the master key can use explain queries', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

newline between tests

@@ -108,6 +108,7 @@ ___
- Added Deprecation Policy to govern the introduction of breaking changes in a phased pattern that is more predictable for developers (Manuel Trezza) [#7199](https://github.com/parse-community/parse-server/pull/7199)
- Add REST API endpoint `/loginAs` to create session of any user with master key; allows to impersonate another user. (GormanFletcher) [#7406](https://github.com/parse-community/parse-server/pull/7406)
- Add official support for MongoDB 5.0 (Manuel Trezza) [#7469](https://github.com/parse-community/parse-server/pull/7469)
- Deprecated ``explain` queries run by non-master users (Kartal Kaan Bozdogan) [#7519](https://github.com/parse-community/parse-server/issues/7519)
Copy link
Member

Choose a reason for hiding this comment

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

Can you rephrase this as:

Deprecated executing explain queries without masterkey

@@ -26,6 +27,12 @@ function checkLiveQuery(className, config) {
// Returns a promise for an object with optional keys 'results' and 'count'.
function find(config, auth, className, restWhere, restOptions, clientSDK, context) {
enforceRoleSecurity('find', className, auth);
if (restOptions && restOptions.explain && !auth.isMaster) {
//throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, 'Cannot explain');
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a comment here please, similar to the one above Deprecation DEPPS3: ...

@@ -57,6 +64,12 @@ function find(config, auth, className, restWhere, restOptions, clientSDK, contex
const get = (config, auth, className, objectId, restOptions, clientSDK, context) => {
var restWhere = { objectId };
enforceRoleSecurity('get', className, auth);
if (restOptions && restOptions.explain && !auth.isMaster) {
//throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, 'Cannot explain');
Deprecator.logRuntimeDeprecation({
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a comment here please, similar to the one above Deprecation DEPPS3: ...

@mtrezza
Copy link
Member

mtrezza commented Sep 30, 2021

@mstniy Do you think you could resolve the conflicts so we can prepare this PR for merge?

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.

2 participants