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

Remove dangerous format specifiers #1566

Merged
merged 12 commits into from
Jun 15, 2021
Merged

Conversation

theunrepentantgeek
Copy link
Member

What this PR does / why we need it:

Removes all uses of the format specifiers %v and %+v as those dump entire objects into the log, which very likely will include secrets (e.g. credentials etc); we don't want those exposed in the logs.

Closes #1470

Special notes for your reviewer:

How does this PR make you feel:
gif

@@ -112,7 +112,13 @@ func TestOwnerNotFound_RemembersCause(t *testing.T) {

g.Expect(errors.Cause(err)).To(Equal(cause))

fmtedErr := fmt.Sprintf("%+v", err)
var builder strings.Builder
for err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this loop is necessary - the wrapper error should include the context of the errors it wraps. The stacktrace that's needed for the error line assertions can be retrieved using this technique.

Copy link
Member Author

Choose a reason for hiding this comment

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

The ReferenceNotFound error wasn't including the nested context, but now it does. I'll query the stack trace separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2021

Codecov Report

Merging #1566 (8dd7478) into master (a2d6835) will decrease coverage by 0.06%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1566      +/-   ##
==========================================
- Coverage   63.48%   63.41%   -0.07%     
==========================================
  Files         178      178              
  Lines       11739    11739              
==========================================
- Hits         7452     7444       -8     
- Misses       3620     3628       +8     
  Partials      667      667              
Impacted Files Coverage Δ
hack/generated/controllers/generic_controller.go 70.45% <0.00%> (ø)
...ted/pkg/reconcilers/azure_deployment_reconciler.go 56.90% <0.00%> (ø)
hack/generated/pkg/util/kubeclient/kube_client.go 85.71% <0.00%> (ø)
hack/generated/pkg/genruntime/errors.go 40.90% <50.00%> (-36.37%) ⬇️
.../generated/pkg/testcommon/counting_roundtripper.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2d6835...8dd7478. Read the comment docs.


// stackTracer allows access to the stack trace of an error
// This should be exposed by the errors package, but it is not
type stackTracer interface {
Copy link
Member

Choose a reason for hiding this comment

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

It would make more sense to define this in the test since it's the only place that's using it.

@theunrepentantgeek theunrepentantgeek merged commit 6bc381c into master Jun 15, 2021
@theunrepentantgeek theunrepentantgeek deleted the fix/dangerous-specifiers branch June 15, 2021 21:07
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.

Review use of Format Specifiers for potential information leakage
5 participants