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

fix: fixes OTP leak in case of error #413

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

vikasbhandari2
Copy link
Contributor

What does this PR do?

Since the OTP is a confidential information, it should not be visible in the logs.

This PR fixes the leak and adds the code to redact the confidential arguments so it doesn't print on the Build Error Logs. The supporting tests have been added as well.

Copy link

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

Comment on lines 13 to 27
function removeConfidentialArguments(args) {
let skipItem = false

return (args ?? []).filter(arg => {
if (skipItem) {
skipItem = false

return false;
}

skipItem = CONFIDENTIAL_KEYWORDS_FOR_REDACTION.includes(arg?.toString().toLocaleUpperCase())

return !skipItem
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not very easy to follow what this code is doing, plus there are not tests for this function outside of the edge cases. let's please write this in a more idiomatic way so that understanding what it does it easier for a reader

@@ -111,3 +112,43 @@ tap.test('passes env vars excluding `INPUT_*` env vars', async t => {
// Its value will vary by test runner, so just check it is present.
t.hasProp(envInExec, 'NODE')
})

tap.test('Invalid arguments inputs should not fail', async t => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to test for normal cases here, not just edge cases

Comment on lines 125 to 127
t.equal(redactedBlankArray?.length, 0)
t.equal(redactedUndefinedArray?.length, 0)
t.equal(redactedNullArray?.length, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the conditional operator is unnecessary, you have already tested that it's an array

Comment on lines 149 to 152
t.ok(errorMessage1.message.indexOf('--otp') === -1 && errorMessage1.message.indexOf('publish') > -1)
t.ok(errorMessage2.message.indexOf('--otp') === -1 && errorMessage2.message.indexOf('publish') > -1)
t.ok(errorMessage3.message.indexOf('--otp') === -1 && errorMessage3.message.indexOf('publish') > -1)
t.ok(errorMessage4.message.indexOf('publish') > -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally test using the built in assertions, which will give you meaningful error messages when they fail. if you test way, the error message won't tell you anything about the nature of the failure, as it will only show you true or false

@simoneb simoneb merged commit 728c960 into nearform-actions:main Jan 29, 2024
0 of 2 checks passed
@github-actions github-actions bot mentioned this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants