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
This commit is contained in:
Manuel
2021-03-10 20:19:28 +01:00
committed by GitHub
parent 36c2608400
commit bee889a329
17 changed files with 1096 additions and 2 deletions

85
src/Security/Check.js Normal file
View File

@@ -0,0 +1,85 @@
/**
* @module SecurityCheck
*/
import Utils from '../Utils';
import { isFunction, isString } from 'lodash';
/**
* A security check.
* @class Check
*/
class Check {
/**
* Constructs a new security check.
* @param {Object} params The parameters.
* @param {String} params.title The title.
* @param {String} params.warning The warning message if the check fails.
* @param {String} params.solution The solution to fix the check.
* @param {Promise} params.check The check as synchronous or asynchronous function.
*/
constructor(params) {
this._validateParams(params);
const { title, warning, solution, check } = params;
this.title = title;
this.warning = warning;
this.solution = solution;
this.check = check;
// Set default properties
this._checkState = CheckState.none;
this.error;
}
/**
* Returns the current check state.
* @return {CheckState} The check state.
*/
checkState() {
return this._checkState;
}
async run() {
// Get check as synchronous or asynchronous function
const check = this.check instanceof Promise ? await this.check : this.check;
// Run check
try {
check();
this._checkState = CheckState.success;
} catch (e) {
this.stateFailError = e;
this._checkState = CheckState.fail;
}
}
/**
* Validates the constructor parameters.
* @param {Object} params The parameters to validate.
*/
_validateParams(params) {
Utils.validateParams(params, {
group: { t: 'string', v: isString },
title: { t: 'string', v: isString },
warning: { t: 'string', v: isString },
solution: { t: 'string', v: isString },
check: { t: 'function', v: isFunction },
});
}
}
/**
* The check state.
*/
const CheckState = Object.freeze({
none: "none",
fail: "fail",
success: "success",
});
export default Check;
module.exports = {
Check,
CheckState,
};