Skip to content

Commit

Permalink
Merge pull request #50 from UFGInsurance/fix/check-pom-for-sensitive
Browse files Browse the repository at this point in the history
Check POM for sensitive property values
  • Loading branch information
TrueWill authored Dec 10, 2018
2 parents 34a45fc + 3187f37 commit ff7263d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion mulint.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const validateLog4j = require("./validateLog4j");
const assert = require("./assert");

program
.version("1.8.0")
.version("1.9.0")
.description("Mule project linter")
.arguments("<apiBasePath>")
.on("--help", () => {
Expand Down
22 changes: 22 additions & 0 deletions sensitive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { propertyPlaceholderRegEx } = require("./constants");

const sensitiveKeyRegEx = /password|pwd/i;

// Primarily for Microsoft SQL Server connection strings
// Negative lookahead - "password=" not followed by "replace" or "${"
// (Case-insensitive, ignoring whitespace)
const sensitiveValueRegEx = /password\s*=(?!\s*(?:replace|\${))/i;

const securedPropertyRegEx = /^!\[.+\]$/;

const isSensitive = (key, value) =>
(sensitiveKeyRegEx.test(key) &&
value &&
!value.toUpperCase().includes("REPLACE") &&
!securedPropertyRegEx.test(value) &&
!propertyPlaceholderRegEx.test(value)) ||
sensitiveValueRegEx.test(value);

module.exports = {
isSensitive
};
7 changes: 7 additions & 0 deletions validatePom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
cloudCIOnlyMavenProperties
} = require("./constants");
const assert = require("./assert");
const sensitive = require("./sensitive");

const domainProjectName = "api-gateway";
const expectedDomainProjectVersionRegEx = /^1\.0\.[3-9]$/;
Expand Down Expand Up @@ -108,6 +109,12 @@ const validatePom = (folderInfo, pomInfo) => {
distributionManagement[0].repository[0].url[0] === mavenRepository,
"POM: Maven repository (Artifactory) not configured"
);

pomInfo.properties.forEach((value, key) => {
if (sensitive.isSensitive(key, value)) {
assert.fail(`POM: ${key} may contain sensitive information`);
}
});
};

module.exports = validatePom;
24 changes: 3 additions & 21 deletions validateProperties.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
const {
propertyPlaceholderRegEx,
cloudCIOnlyMavenProperties,
encoding
} = require("./constants");
const { cloudCIOnlyMavenProperties, encoding } = require("./constants");
const fs = require("fs");
const path = require("path");
const os = require("os");
const assert = require("./assert");

const sensitiveKeyRegEx = /password|pwd/i;

// Primarily for Microsoft SQL Server connection strings
// Negative lookahead - "password=" not followed by "replace" or "${"
// (Case-insensitive, ignoring whitespace)
const sensitiveValueRegEx = /password\s*=(?!\s*(?:replace|\${))/i;

const securedPropertyRegEx = /^!\[.+\]$/;
const sensitive = require("./sensitive");

// Loads a Java .properties file into a Map.
const loadProperties = fileName =>
Expand Down Expand Up @@ -102,13 +90,7 @@ const validateProperties = (folderInfo, pomInfo) => {
`${serverContext}: ${key} from ${localContext} not found`
);

if (
(sensitiveKeyRegEx.test(key) &&
!value.toUpperCase().includes("REPLACE") &&
!securedPropertyRegEx.test(value) &&
!propertyPlaceholderRegEx.test(value)) ||
sensitiveValueRegEx.test(value)
) {
if (sensitive.isSensitive(key, value)) {
assert.fail(`${localContext}: ${key} may contain sensitive information`);
}
});
Expand Down

0 comments on commit ff7263d

Please # to comment.