You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CLP (Read only) and write request using master key: #1976
According to the Parse Docs, using the master key for an action should bypass all security checks:
The master key, on the other hand, is definitely a security mechanism. Using the master key allows you to bypass all of your app's security mechanisms, such as class-level permissions and ACLs. Having the master key is like having root access to your app's servers, and you should guard your master key with the same zeal with which you would guard your production machines' root password.
Steps to reproduce
Create a Custom Table, set CLP to read only
Use this code to create a new entry:
exports.createNewEntry = function(param) {
const ParseEntry = Parse.Object.extend('Yourname');
let parseEntry = new ParseEntry();
parseEntry.set('param', param);
let acl = new Parse.ACL();
acl.setPublicReadAccess(true);
acl.setPublicWriteAccess(false);
parseEntry.setACL(acl);
return parseEntry.save({}, { useMasterKey: true })
.then(parseEntry => {
...
});
};
Result: ERROR: ParseError { code: 119, message: 'Permission denied for this action.' }
When I edit the CLP and allow write permission (or only the Create in the advanced section) this code works.
Where are you calling createNewEntry - in Cloud Code or client side JS? Cloud Code is trusted so the master key will be set when the SDK is initialized. You can also pass this to the JS SDK if initializing yourself but must only do so if the code is in a trusted environment.
Might be worth testing the same code with the ACL modification removed so you can see if there is a problem with just CLP and standard saving using the master key.
You could also try passing null as the first parameter to save instead of {}. I think either should work but have only tested null.
I call this function from client side js. i initialized the sdk with the mater key. I also tried the null param instead the {} variant with the same result.
when i change the clp permission and add write permission it works.
hi. i dont deploy rhe master key with my app. i only use it for admin tasks. but I think When Im using cloud code and do security checks there it should work aswell.
To make it works, you will have to save your function as a cloud function in your parse server cloud code and then call it from client (your workstation).
In our main.js, create samething like:
Parse.Cloud.define("createNewEntry", function (request, response) {
const ParseEntry = Parse.Object.extend('Yourname');
let parseEntry = new ParseEntry();
parseEntry.set('param', request.params.param);
let acl = new Parse.ACL();
acl.setPublicReadAccess(true);
acl.setPublicWriteAccess(false);
parseEntry.setACL(acl);
parseEntry.save({}, { useMasterKey: true })
.then(parseEntry => {
...
response.success(parseEntry);
}).catch(response.error);
});
/**
* Call this method first to set up your authentication tokens for Parse.
* You can get your keys from the Data Browser on parse.com.
* @method initialize
* @param {String} applicationId Your Parse Application ID.
* @param {String} javaScriptKey (optional) Your Parse JavaScript Key (Not needed for parse-server)
* @param {String} masterKey (optional) Your Parse Master Key. (Node.js only!)
* @static
*/
initialize: function initialize(applicationId, javaScriptKey) {
Parse._initialize(applicationId, javaScriptKey);
},
_initialize: function _initialize(applicationId, javaScriptKey, masterKey) {
_CoreManager2['default'].set('APPLICATION_ID', applicationId);
_CoreManager2['default'].set('JAVASCRIPT_KEY', javaScriptKey);
_CoreManager2['default'].set('MASTER_KEY', masterKey);
_CoreManager2['default'].set('USE_MASTER_KEY', false);
}
...
Parse.initialize = Parse._initialize;
I just saw that the Parse.initialize = Parse._initialize; is available on node.js only. So correction: this should work when initializing with the master key...
Just want to pop in and say that this works for me only if I call Parse.Cloud.useMasterKey() in addition to passing { useMasterKey: true } as an option to each operation that needs to bypass CLPs/ACLs.
Activity
steven-supersolid commentedon Jun 4, 2016
Where are you calling createNewEntry - in Cloud Code or client side JS? Cloud Code is trusted so the master key will be set when the SDK is initialized. You can also pass this to the JS SDK if initializing yourself but must only do so if the code is in a trusted environment.
Might be worth testing the same code with the ACL modification removed so you can see if there is a problem with just CLP and standard saving using the master key.
You could also try passing null as the first parameter to save instead of {}. I think either should work but have only tested null.
neophob commentedon Jun 4, 2016
I call this function from client side js. i initialized the sdk with the mater key. I also tried the null param instead the {} variant with the same result.
when i change the clp permission and add write permission it works.
flovilmart commentedon Jun 4, 2016
I'll have a look tomorrow. Do you confirm the behavior is different than on parse.com?
flovilmart commentedon Jun 4, 2016
Something is sure, that should pass with the masterKey
flovilmart commentedon Jun 5, 2016
This is plain wrong... You should not let your masterKey in the client SDK!
flovilmart commentedon Jun 5, 2016
I just ran some tests, and this behaves correctly, the masterKey is correctly processed when running from the server.
Again, the masterKey SHOULD NEVER EVER EVER been sent to the client.
Also, if you look at the code here: https://github.com/ParsePlatform/Parse-SDK-JS/blob/master/src/Parse.js#L32
The masterKey is completely ignored when Parse is used in the Client SDK.
neophob commentedon Jun 5, 2016
hi. i dont deploy rhe master key with my app. i only use it for admin tasks. but I think When Im using cloud code and do security checks there it should work aswell.
thanks
flovilmart commentedon Jun 5, 2016
Can you provide the logs when running parse-server with VERBOSE=1
neophob commentedon Jun 6, 2016
sure, clientcode:
server code (hint: log direction is upside down):
flovilmart commentedon Jun 6, 2016
When you say client code, from where is that code run from?
neophob commentedon Jun 6, 2016
from my workstation (aka. NOT cloud code and NOT on the same device as the server runns)
flovilmart commentedon Jun 6, 2016
How do you
requireparse? Withrequire("parse/node")?neophob commentedon Jun 6, 2016
correct yes:
(the master key is obsolete but doesn't hurt)
sdf611097 commentedon Jun 8, 2016
How you do this step?
davimacedo commentedon Jun 8, 2016
To make it works, you will have to save your function as a cloud function in your parse server cloud code and then call it from client (your workstation).
In our main.js, create samething like:
In your client call just function like:
neophob commentedon Jun 8, 2016
@davimacedo thanks for your reply. I don't think having admin related tasks in cloud code make sense - security wise and user wise.
@flovilmart any hints from your side?
davimacedo commentedon Jun 8, 2016
@neophob you can first check in your cloud function if user is 'admin'
Actually it is the unique way to make it works since sending master key from client (admin is also client) is not recommended/allowed anymore as you can see in the link @flovilmart sent:
https://github.com/ParsePlatform/Parse-SDK-JS/blob/master/src/Parse.js#L32
neophob commentedon Jun 8, 2016
Hmm I'm a bit confused now. In a recent parse SDK commit (parse-community/Parse-SDK-JS@8a3d011) the documentation was updated, the changed text:
So it looks like the docs clearly say we can use the masterKey from node, but how do we actually SET the master key?
davimacedo commentedon Jun 9, 2016
Hi @neophob I've just realized that you are using in a Node.js environment and there userMarterKey: true should be working. Sorry about that.
When you pasted your initialization code, you said: "(the master key is obsolete but doesn't hurt)"
What do you mean?
neophob commentedon Jun 9, 2016
From parse.js sdk (node)
I just saw that the
Parse.initialize = Parse._initialize;is available on node.js only. So correction: this should work when initializing with the master key...neophob commentedon Jun 22, 2016
any news on this issue?
neophob commentedon Jun 22, 2016
seems to work with latest parse server now (v2.2.13)
11k commentedon Jul 19, 2016
Just want to pop in and say that this works for me only if I call
Parse.Cloud.useMasterKey()in addition to passing{ useMasterKey: true }as an option to each operation that needs to bypass CLPs/ACLs.haroot commentedon Aug 15, 2018
here is how you override CLPs/ACLs for protected Collections starting with a "_" persay like "_User" aka "User"
flovilmart commentedon Aug 15, 2018
@haroot I edited the snippet to remove inaccuracies with the latest and future versions of the server
haroot commentedon Aug 15, 2018
@flovilmart thanks ill replace the old one in the morning . A lot cleaner, thank you!