Skip to content

Commit bee889a

Browse files
authored
Add security check (#7247)
* added Parse Server security option * added SecurityRouter * added Check class * added CheckGroup class * moved parameter validation to Utils * added CheckRunner class * added auto-run on server start * added custom security checks as Parse Server option * renamed script to check * reformat log output * added server config check * improved contributing guideline * improved contribution guide * added check security log * improved log format * added checks * fixed log fomat typo * added database checks * fixed database check * removed database auth check in initial version * improved contribution guide * added security check tests * fixed typo * improved wording guidelines * improved wording guidelines
1 parent 36c2608 commit bee889a

17 files changed

+1096
-2
lines changed

CONTRIBUTING.md

+51-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- [Postgres with Docker](#postgres-with-docker)
1414
- [Feature Considerations](#feature-considerations)
1515
- [Security Checks](#security-checks)
16+
- [Add Security Check](#add-security-check)
17+
- [Wording Guideline](#wording-guideline)
1618
- [Parse Error](#parse-error)
1719
- [Parse Server Configuration](#parse-server-configuration)
1820
- [Code of Conduct](#code-of-conduct)
@@ -162,7 +164,55 @@ A security check needs to be added for every new feature or enhancement that all
162164

163165
For example, allowing public read and write to a class may be useful to simplify development but should be disallowed in a production environment.
164166

165-
Security checks are added in [SecurityChecks.js](https://github.com/parse-community/parse-server/blob/master/src/SecurityChecks.js).
167+
Security checks are added in [CheckGroups](https://github.com/parse-community/parse-server/tree/master/src/Security/CheckGroups).
168+
169+
#### Add Security Check
170+
Adding a new security check for your feature is easy and fast:
171+
1. Look into [CheckGroups](https://github.com/parse-community/parse-server/tree/master/src/Security/CheckGroups) whether there is an existing `CheckGroup[Category].js` file for the category of check to add. For example, a check regarding the database connection is added to `CheckGroupDatabase.js`.
172+
2. If you did not find a file, duplicate an existing file and replace the category name in `setName()` and the checks in `setChecks()`:
173+
```js
174+
class CheckGroupNewCategory extends CheckGroup {
175+
setName() {
176+
return 'House';
177+
}
178+
setChecks() {
179+
return [
180+
new Check({
181+
title: 'Door locked',
182+
warning: 'Anyone can enter your house.',
183+
solution: 'Lock the door.',
184+
check: () => {
185+
return; // Example of a passing check
186+
}
187+
}),
188+
new Check({
189+
title: 'Camera online',
190+
warning: 'Security camera is offline.',
191+
solution: 'Check the camera.',
192+
check: async () => {
193+
throw 1; // Example of a failing check
194+
}
195+
}),
196+
];
197+
}
198+
}
199+
```
200+
201+
3. If you added a new file in the previous step, reference the file in [CheckGroups.js](https://github.com/parse-community/parse-server/blob/master/src/Security/CheckGroups/CheckGroups.js), which is the collector of all security checks:
202+
```
203+
export { default as CheckGroupNewCategory } from './CheckGroupNewCategory';
204+
```
205+
4. Add a test that covers the new check to [SecurityCheckGroups.js](https://github.com/parse-community/parse-server/blob/master/spec/SecurityCheckGroups.js) for the cases of success and failure.
206+
207+
#### Wording Guideline
208+
Consider the following when adding a new security check:
209+
- *Group.name*: The category name; ends without period as this is a headline.
210+
- *Check.title*: Is the positive hypothesis that should be checked, for example "Door locked" instead of "Door unlocked"; ends without period as this is a title.
211+
- *Check.warning*: The warning if the test fails; ends with period as this is a description.
212+
- *Check.solution*: The recommended solution if the test fails; ends with period as this is an instruction.
213+
- The wordings must not contain any sensitive information such as keys, as the security report may be exposed in logs.
214+
- The wordings should be concise and not contain verbose explanations, for example "Door locked" instead of "Door has been locked securely".
215+
- Do not use pronouns such as "you" or "your" because log files can have various readers with different roles. Do not use pronouns such as "I" or "me" because although we love it dearly, Parse Server is not a human.
166216

167217
### Parse Error
168218

resources/buildConfigDefinitions.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function getENVPrefix(iface) {
5252
'AccountLockoutOptions' : 'PARSE_SERVER_ACCOUNT_LOCKOUT_',
5353
'PasswordPolicyOptions' : 'PARSE_SERVER_PASSWORD_POLICY_',
5454
'FileUploadOptions' : 'PARSE_SERVER_FILE_UPLOAD_',
55+
'SecurityOptions': 'PARSE_SERVER_SECURITY_',
5556
}
5657
if (options[iface.id.name]) {
5758
return options[iface.id.name]
@@ -167,7 +168,7 @@ function parseDefaultValue(elt, value, t) {
167168
if (type == 'NumberOrBoolean') {
168169
literalValue = t.numericLiteral(parsers.numberOrBoolParser('')(value));
169170
}
170-
const literalTypes = ['Object', 'PagesRoute', 'IdempotencyOptions','FileUploadOptions','CustomPagesOptions', 'PagesCustomUrlsOptions', 'PagesOptions'];
171+
const literalTypes = ['Object', 'SecurityOptions', 'PagesRoute', 'IdempotencyOptions','FileUploadOptions','CustomPagesOptions', 'PagesCustomUrlsOptions', 'PagesOptions'];
171172
if (literalTypes.includes(type)) {
172173
const object = parsers.objectParser(value);
173174
const props = Object.keys(object).map((key) => {

0 commit comments

Comments
 (0)