Skip to content

Commit 484c2e8

Browse files
authored
fix: improve security by deprecating creating users with public access by default (#7319)
1 parent 2b5bf22 commit 484c2e8

File tree

10 files changed

+86
-28
lines changed

10 files changed

+86
-28
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ ___
114114
- 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)
115115
- 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)
116116
- Add official support for MongoDB 5.0 (Manuel Trezza) [#7469](https://github.com/parse-community/parse-server/pull/7469)
117+
- Added Parse Server Configuration `enforcePrivateUsers`, which will remove public access by default on new Parse.Users (dblythy) [#7319](https://github.com/parse-community/parse-server/pull/7319)
117118

118119
### Other Changes
119120
- Support native mongodb syntax in aggregation pipelines (Raschid JF Rafeally) [#7339](https://github.com/parse-community/parse-server/pull/7339)

Diff for: DEPRECATIONS.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h
66
|--------|-------------------------------------------------|----------------------------------------------------------------------|---------------------------------|---------------------------------|-----------------------|-------|
77
| DEPPS1 | 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 | - |
88
| DEPPS2 | 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 | - |
9+
| DEPPS3 | Config option `enforcePrivateUsers` defaults to `true` | [#7319](https://github.com/parse-community/parse-server/pull/7319) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
910

1011
[i_deprecation]: ## "The version and date of the deprecation."
1112
[i_removal]: ## "The version and date of the planned removal."

Diff for: spec/ParseUser.spec.js

+36-15
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ const passwordCrypto = require('../lib/password');
1313
const Config = require('../lib/Config');
1414
const cryptoUtils = require('../lib/cryptoUtils');
1515

16-
function verifyACL(user) {
17-
const ACL = user.getACL();
18-
expect(ACL.getReadAccess(user)).toBe(true);
19-
expect(ACL.getWriteAccess(user)).toBe(true);
20-
expect(ACL.getPublicReadAccess()).toBe(true);
21-
expect(ACL.getPublicWriteAccess()).toBe(false);
22-
const perms = ACL.permissionsById;
23-
expect(Object.keys(perms).length).toBe(2);
24-
expect(perms[user.id].read).toBe(true);
25-
expect(perms[user.id].write).toBe(true);
26-
expect(perms['*'].read).toBe(true);
27-
expect(perms['*'].write).not.toBe(true);
28-
}
29-
3016
describe('Parse.User testing', () => {
3117
it('user sign up class method', async done => {
3218
const user = await Parse.User.signUp('asdf', 'zxcv');
@@ -146,7 +132,17 @@ describe('Parse.User testing', () => {
146132
await Parse.User.signUp('asdf', 'zxcv');
147133
const user = await Parse.User.logIn('asdf', 'zxcv');
148134
equal(user.get('username'), 'asdf');
149-
verifyACL(user);
135+
const ACL = user.getACL();
136+
expect(ACL.getReadAccess(user)).toBe(true);
137+
expect(ACL.getWriteAccess(user)).toBe(true);
138+
expect(ACL.getPublicReadAccess()).toBe(true);
139+
expect(ACL.getPublicWriteAccess()).toBe(false);
140+
const perms = ACL.permissionsById;
141+
expect(Object.keys(perms).length).toBe(2);
142+
expect(perms[user.id].read).toBe(true);
143+
expect(perms[user.id].write).toBe(true);
144+
expect(perms['*'].read).toBe(true);
145+
expect(perms['*'].write).not.toBe(true);
150146
done();
151147
});
152148

@@ -3934,6 +3930,31 @@ describe('Parse.User testing', () => {
39343930
}
39353931
});
39363932

3933+
it('should throw when enforcePrivateUsers is invalid', async () => {
3934+
const options = [[], 'a', 0, {}];
3935+
for (const option of options) {
3936+
await expectAsync(reconfigureServer({ enforcePrivateUsers: option })).toBeRejected();
3937+
}
3938+
});
3939+
3940+
it('user login with enforcePrivateUsers', async done => {
3941+
await reconfigureServer({ enforcePrivateUsers: true });
3942+
await Parse.User.signUp('asdf', 'zxcv');
3943+
const user = await Parse.User.logIn('asdf', 'zxcv');
3944+
equal(user.get('username'), 'asdf');
3945+
const ACL = user.getACL();
3946+
expect(ACL.getReadAccess(user)).toBe(true);
3947+
expect(ACL.getWriteAccess(user)).toBe(true);
3948+
expect(ACL.getPublicReadAccess()).toBe(false);
3949+
expect(ACL.getPublicWriteAccess()).toBe(false);
3950+
const perms = ACL.permissionsById;
3951+
expect(Object.keys(perms).length).toBe(1);
3952+
expect(perms[user.id].read).toBe(true);
3953+
expect(perms[user.id].write).toBe(true);
3954+
expect(perms['*']).toBeUndefined();
3955+
done();
3956+
});
3957+
39373958
describe('issue #4897', () => {
39383959
it_only_db('mongo')('should be able to login with a legacy user (no ACL)', async () => {
39393960
// This issue is a side effect of the locked users and legacy users which don't have ACL's

Diff for: src/Config.js

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class Config {
7575
fileUpload,
7676
pages,
7777
security,
78+
enforcePrivateUsers,
7879
}) {
7980
if (masterKey === readOnlyMasterKey) {
8081
throw new Error('masterKey and readOnlyMasterKey should be different');
@@ -111,6 +112,13 @@ export class Config {
111112
this.validateIdempotencyOptions(idempotencyOptions);
112113
this.validatePagesOptions(pages);
113114
this.validateSecurityOptions(security);
115+
this.validateEnforcePrivateUsers(enforcePrivateUsers);
116+
}
117+
118+
static validateEnforcePrivateUsers(enforcePrivateUsers) {
119+
if (typeof enforcePrivateUsers !== 'boolean') {
120+
throw 'Parse Server option enforcePrivateUsers must be a boolean.';
121+
}
114122
}
115123

116124
static validateSecurityOptions(security) {

Diff for: src/Deprecator/Deprecations.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* The deprecations.
33
*
44
* Add deprecations to the array using the following keys:
5-
* - `optionKey`: The option key incl. its path, e.g. `security.enableCheck`.
6-
* - `envKey`: The environment key, e.g. `PARSE_SERVER_SECURITY`.
7-
* - `changeNewKey`: Set the new key name if the current key will be replaced,
5+
* - `optionKey` {String}: The option key incl. its path, e.g. `security.enableCheck`.
6+
* - `envKey` {String}: The environment key, e.g. `PARSE_SERVER_SECURITY`.
7+
* - `changeNewKey` {String}: Set the new key name if the current key will be replaced,
88
* or set to an empty string if the current key will be removed without replacement.
9-
* - `changeNewDefault`: Set the new default value if the key's default value
9+
* - `changeNewDefault` {String}: Set the new default value if the key's default value
1010
* will change in a future version.
1111
* - `solution`: The instruction to resolve this deprecation warning. Optional. This
1212
* instruction must not include the deprecation warning which is auto-generated.
@@ -22,4 +22,5 @@ module.exports = [
2222
solution:
2323
"Additionally, the environment variable 'PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS' will be deprecated and renamed to 'PARSE_SERVER_DIRECT_ACCESS' in a future version; it is currently possible to use either one.",
2424
},
25+
{ optionKey: 'enforcePrivateUsers', changeNewDefault: 'true' },
2526
];

Diff for: src/Options/Definitions.js

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ module.exports.ParseServerOptions = {
154154
env: 'PARSE_SERVER_ENCRYPTION_KEY',
155155
help: 'Key for encrypting your files',
156156
},
157+
enforcePrivateUsers: {
158+
env: 'PARSE_SERVER_ENFORCE_PRIVATE_USERS',
159+
help: 'Set to true if new users should be created without public read and write access.',
160+
action: parsers.booleanParser,
161+
default: false,
162+
},
157163
expireInactiveSessions: {
158164
env: 'PARSE_SERVER_EXPIRE_INACTIVE_SESSIONS',
159165
help:

Diff for: src/Options/docs.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* @property {Boolean} enableAnonymousUsers Enable (or disable) anonymous users, defaults to true
2929
* @property {Boolean} enableExpressErrorHandler Enables the default express error handler for all errors
3030
* @property {String} encryptionKey Key for encrypting your files
31+
* @property {Boolean} enforcePrivateUsers Set to true if new users should be created without public read and write access.
3132
* @property {Boolean} expireInactiveSessions Sets whether we should expire the inactive sessions, defaults to true. If false, all new sessions are created with no expiration date.
3233
* @property {String} fileKey Key for your files
3334
* @property {Adapter<FilesAdapter>} filesAdapter Adapter module for the files sub-system

Diff for: src/Options/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ export interface ParseServerOptions {
246246
/* The security options to identify and report weak security settings.
247247
:DEFAULT: {} */
248248
security: ?SecurityOptions;
249+
/* Set to true if new users should be created without public read and write access.
250+
:DEFAULT: false */
251+
enforcePrivateUsers: ?boolean;
249252
}
250253

251254
export interface SecurityOptions {

Diff for: src/RestWrite.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,9 @@ RestWrite.prototype.runDatabaseOperation = function () {
14081408
// default public r/w ACL
14091409
if (!ACL) {
14101410
ACL = {};
1411-
ACL['*'] = { read: true, write: false };
1411+
if (!this.config.enforcePrivateUsers) {
1412+
ACL['*'] = { read: true, write: false };
1413+
}
14121414
}
14131415
// make sure the user is not locked down
14141416
ACL[this.data.objectId] = { read: true, write: true };

Diff for: src/Security/CheckGroups/CheckGroupServerConfig.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import Config from '../../Config';
88
import Parse from 'parse/node';
99

1010
/**
11-
* The security checks group for Parse Server configuration.
12-
* Checks common Parse Server parameters such as access keys.
13-
*/
11+
* The security checks group for Parse Server configuration.
12+
* Checks common Parse Server parameters such as access keys.
13+
*/
1414
class CheckGroupServerConfig extends CheckGroup {
1515
setName() {
1616
return 'Parse Server Configuration';
@@ -21,7 +21,8 @@ class CheckGroupServerConfig extends CheckGroup {
2121
new Check({
2222
title: 'Secure master key',
2323
warning: 'The Parse Server master key is insecure and vulnerable to brute force attacks.',
24-
solution: 'Choose a longer and/or more complex master key with a combination of upper- and lowercase characters, numbers and special characters.',
24+
solution:
25+
'Choose a longer and/or more complex master key with a combination of upper- and lowercase characters, numbers and special characters.',
2526
check: () => {
2627
const masterKey = config.masterKey;
2728
const hasUpperCase = /[A-Z]/.test(masterKey);
@@ -40,8 +41,9 @@ class CheckGroupServerConfig extends CheckGroup {
4041
}),
4142
new Check({
4243
title: 'Security log disabled',
43-
warning: 'Security checks in logs may expose vulnerabilities to anyone access to logs.',
44-
solution: 'Change Parse Server configuration to \'security.enableCheckLog: false\'.',
44+
warning:
45+
'Security checks in logs may expose vulnerabilities to anyone with access to logs.',
46+
solution: "Change Parse Server configuration to 'security.enableCheckLog: false'.",
4547
check: () => {
4648
if (config.security && config.security.enableCheckLog) {
4749
throw 1;
@@ -50,14 +52,26 @@ class CheckGroupServerConfig extends CheckGroup {
5052
}),
5153
new Check({
5254
title: 'Client class creation disabled',
53-
warning: 'Attackers are allowed to create new classes without restriction and flood the database.',
54-
solution: 'Change Parse Server configuration to \'allowClientClassCreation: false\'.',
55+
warning:
56+
'Attackers are allowed to create new classes without restriction and flood the database.',
57+
solution: "Change Parse Server configuration to 'allowClientClassCreation: false'.",
5558
check: () => {
5659
if (config.allowClientClassCreation || config.allowClientClassCreation == null) {
5760
throw 1;
5861
}
5962
},
6063
}),
64+
new Check({
65+
title: 'Users are created without public access',
66+
warning:
67+
'Users with public read access are exposed to anyone who knows their object IDs, or to anyone who can query the Parse.User class.',
68+
solution: "Change Parse Server configuration to 'enforcePrivateUsers: true'.",
69+
check: () => {
70+
if (!config.enforcePrivateUsers) {
71+
throw 1;
72+
}
73+
},
74+
}),
6175
];
6276
}
6377
}

0 commit comments

Comments
 (0)