Skip to content

Commit

Permalink
fix: sanitize CR env data in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaron Schwimmer committed Jan 5, 2021
1 parent f874951 commit 48d967a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ function sanitise(raw) {
raw = sanitiseConfigVariable(raw, 'ARTIFACTORY_URL');
}

if (config.CR_CREDENTIALS) {
raw = sanitiseConfigVariable(raw, 'CR_CREDENTIALS');
}

if (config.CR_AGENT_URL) {
raw = sanitiseConfigVariable(raw, 'CR_AGENT_URL');
}

return raw;
}

Expand Down
9 changes: 9 additions & 0 deletions test/unit/log.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ describe('log', () => {
const azureReposToken = (process.env.AZURE_REPOS_TOKEN = 'AZURE_TOKEN');
const artifactoryUrl = (process.env.ARTIFACTORY_URL =
'http://basic:[email protected]');
const crAgentUrl = (process.env.CR_AGENT_URL =
'CONTAINER_REGISTRY_AGENT_URL');
const crCredentials = (process.env.CR_CREDENTIALS = 'CR_CREDS');

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

Expand All @@ -25,12 +28,15 @@ describe('log', () => {
jiraUser,
jiraPass,
artifactoryUrl,
crAgentUrl,
crCredentials,
].join();
const sanitizedTokens =
'${BROKER_TOKEN},${GITHUB_TOKEN},${GITLAB_TOKEN},${AZURE_REPOS_TOKEN}';
const sanitizedBitBucket = '${BITBUCKET_USERNAME},${BITBUCKET_PASSWORD}';
const sanitizedJira = '${JIRA_USERNAME},${JIRA_PASSWORD}';
const sanitizedArtifactory = '${ARTIFACTORY_URL}';
const sanitizedCRData = '${CR_AGENT_URL},${CR_CREDENTIALS}';

// setup logger output capturing
const logs: string[] = [];
Expand Down Expand Up @@ -64,11 +70,14 @@ describe('log', () => {
expect(logged).not.toMatch(jiraPass);
expect(logged).not.toMatch(azureReposToken);
expect(logged).not.toMatch(artifactoryUrl);
expect(logged).not.toMatch(crAgentUrl);
expect(logged).not.toMatch(crCredentials);

// assert sensitive data is masked
expect(logged).toMatch(sanitizedBitBucket);
expect(logged).toMatch(sanitizedTokens);
expect(logged).toMatch(sanitizedJira);
expect(logged).toMatch(sanitizedArtifactory);
expect(logged).toMatch(sanitizedCRData);
});
});

0 comments on commit 48d967a

Please sign in to comment.