Skip to content

Do not allow to protect default fields #6439

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions spec/ProtectedFields.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ describe('ProtectedFields', function() {
object.set('revision', 0);
object.set('test', 'test');

await object.save({ useMasterKey: true });
await object.save(null, { useMasterKey: true });
}

beforeEach(async () => {
Expand Down Expand Up @@ -812,6 +812,24 @@ describe('ProtectedFields', function() {
})
).toBeResolved();
});

it('should not allow protecting default fields', async () => {
const defaultFields = ['objectId', 'createdAt', 'updatedAt', 'ACL'];
for (const field of defaultFields) {
await expectAsync(
updateCLP({
protectedFields: {
'*': [field],
},
})
).toBeRejectedWith(
new Parse.Error(
Parse.Error.INVALID_JSON,
`Default field '${field}' can not be protected`
)
);
}
});
});

describe('targeting public access', () => {
Expand Down Expand Up @@ -1310,10 +1328,10 @@ describe('ProtectedFields', function() {

// admin supersets moder role
moder.relation('roles').add(admin);
await moder.save({ useMasterKey: true });
await moder.save(null, { useMasterKey: true });

tester.relation('roles').add(moder);
await tester.save({ useMasterKey: true });
await tester.save(null, { useMasterKey: true });

const roleAdmin = `role:${admin.get('name')}`;
const roleModer = `role:${moder.get('name')}`;
Expand Down
7 changes: 7 additions & 0 deletions src/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ function validateCLP(

// if the field is in form of array
for (const field of protectedFields) {
// do not alloow to protect default fields
if (defaultColumns._Default[field]) {
throw new Parse.Error(
Parse.Error.INVALID_JSON,
`Default field '${field}' can not be protected`
);
}
// field should exist on collection
if (!Object.prototype.hasOwnProperty.call(fields, field)) {
throw new Parse.Error(
Expand Down