|
| 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; |
0 commit comments