Skip to content

Commit 60c6cbf

Browse files
committed
added database checks
1 parent 5c0053f commit 60c6cbf

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @module SecurityCheck
3+
*/
4+
5+
import { Check } from '../Check';
6+
import CheckGroup from '../CheckGroup';
7+
import Config from '../../Config';
8+
import Parse from 'parse/node';
9+
10+
/**
11+
* The security checks group for Parse Server configuration.
12+
* Checks common Parse Server parameters such as access keys.
13+
*/
14+
class CheckGroupDatabase extends CheckGroup {
15+
setName() {
16+
return 'Database';
17+
}
18+
setChecks() {
19+
const config = Config.get(Parse.applicationId);
20+
const databaseAdapter = config.database.adapter;
21+
const databaseUrl = databaseAdapter._uri;
22+
const MongoClient = require('mongodb').MongoClient;
23+
return [
24+
new Check({
25+
title: `Database requires authentication`,
26+
warning: 'Database requires no authentication to connect which allows anyone to connect and potentially access data.',
27+
solution: 'Change database access settings.',
28+
check: async () => {
29+
try {
30+
const urlWithoutCredentials = databaseUrl.replace(/\/\/(\S+:\S+)@/, '//');
31+
const client = await MongoClient.connect(urlWithoutCredentials, { useNewUrlParser: true });
32+
await client.db("admin").command({ ping: 1 });
33+
throw 1;
34+
} catch {
35+
return;
36+
}
37+
},
38+
}),
39+
new Check({
40+
title: 'Secure database password',
41+
warning: 'The Parse Server master key is insecure and vulnerable to brute force attacks.',
42+
solution: 'Choose a more complex master key with a combination of upper- and lowercase characters, numbers and special characters.',
43+
check: () => {
44+
const masterKey = config.masterKey;
45+
const hasUpperCase = /[A-Z]/.test(masterKey);
46+
const hasLowerCase = /[a-z]/.test(masterKey);
47+
const hasNumbers = /\d/.test(masterKey);
48+
const hasNonAlphasNumerics = /\W/.test(masterKey);
49+
// Ensure length
50+
if (masterKey.length < 14) {
51+
throw 1;
52+
}
53+
// Ensure at least 3 out of 4 requirements passed
54+
if (hasUpperCase + hasLowerCase + hasNumbers + hasNonAlphasNumerics < 3) {
55+
throw 1;
56+
}
57+
},
58+
}),
59+
];
60+
}
61+
}
62+
63+
module.exports = CheckGroupDatabase;

src/Security/CheckGroups/CheckGroups.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/**
66
* The list of security check groups.
77
*/
8+
export { default as CheckGroupDatabase } from './CheckGroupDatabase';
89
export { default as CheckGroupServerConfig } from './CheckGroupServerConfig';

0 commit comments

Comments
 (0)