Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ensure Database Password Security Check Covers All Possible URIs #9078

Open
wants to merge 6 commits into
base: alpha
Choose a base branch
from
38 changes: 32 additions & 6 deletions spec/SecurityCheckGroups.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const Config = require('../lib/Config');

Check failure on line 3 in spec/SecurityCheckGroups.spec.js

View workflow job for this annotation

GitHub Actions / Lint

'Config' is assigned a value but never used
const { CheckState } = require('../lib/Security/Check');
const CheckGroupServerConfig = require('../lib/Security/CheckGroups/CheckGroupServerConfig');
const CheckGroupDatabase = require('../lib/Security/CheckGroups/CheckGroupDatabase');
Expand Down Expand Up @@ -62,17 +62,43 @@
expect(group.checks().length).toBeGreaterThan(0);
});

it('checks succeed correctly', async () => {
const config = Config.get(Parse.applicationId);
config.database.adapter._uri = 'protocol://user:[email protected]';
it('checks succeed correctly with database adapter defined', async () => {
const databaseAdapter = {
_uri: 'protocol://user:[email protected]'
};
const config = {

Check failure on line 69 in spec/SecurityCheckGroups.spec.js

View workflow job for this annotation

GitHub Actions / Lint

'config' is assigned a value but never used
database: { adapter: databaseAdapter }
};
const group = new CheckGroupDatabase();
await group.run();
expect(group.checks()[0].checkState()).toBe(CheckState.success);
});

it('checks fail correctly', async () => {
const config = Config.get(Parse.applicationId);
config.database.adapter._uri = 'protocol://user:[email protected]';
it('checks succeed correctly with databaseURI defined', async () => {
const config = {

Check failure on line 78 in spec/SecurityCheckGroups.spec.js

View workflow job for this annotation

GitHub Actions / Lint

'config' is assigned a value but never used
databaseURI: 'protocol://user:[email protected]'
};
const group = new CheckGroupDatabase();
await group.run();
expect(group.checks()[0].checkState()).toBe(CheckState.success);
});

it('checks fail correctly with database adapter defined', async () => {
const databaseAdapter = {
_uri: 'protocol://user:[email protected]'
};
const config = {

Check failure on line 90 in spec/SecurityCheckGroups.spec.js

View workflow job for this annotation

GitHub Actions / Lint

'config' is assigned a value but never used
database: { adapter: databaseAdapter }
};
const group = new CheckGroupDatabase();
await group.run();
expect(group.checks()[0].checkState()).toBe(CheckState.fail);
});

it('checks fail correctly with databaseURI defined', async () => {
const config = {

Check failure on line 99 in spec/SecurityCheckGroups.spec.js

View workflow job for this annotation

GitHub Actions / Lint

'config' is assigned a value but never used
databaseURI: 'protocol://user:[email protected]'
};
const group = new CheckGroupDatabase();
await group.run();
expect(group.checks()[0].checkState()).toBe(CheckState.fail);
Expand Down
12 changes: 11 additions & 1 deletion src/Security/CheckGroups/CheckGroupDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ class CheckGroupDatabase extends CheckGroup {
}
setChecks() {
const config = Config.get(Parse.applicationId);
let databaseUrl;
const databaseAdapter = config.database.adapter;
const databaseUrl = databaseAdapter._uri;
if (databaseAdapter) {
// If database adapter is defined, use its URI
databaseUrl = databaseAdapter._uri;
} else if (config.databaseURI) {
// If database adapter is not defined, fallback to config.databaseURI
databaseUrl = config.databaseURI;
} else {
// Handle the case where neither database adapter nor databaseURI is defined
throw 1;
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
}
return [
new Check({
title: 'Secure database password',
Expand Down