Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Conversation

@njhale
Copy link
Member

@njhale njhale commented Aug 1, 2023

This prevents credential leakage when using higher log levels during builds.

Addresses https://github.com/acorn-io/manager/issues/828


func (m *WebsocketMessages) Send(msg *Message) error {
logrus.Tracef("Send build message %s", msg)
logrus.Tracef("Send build message %s", redact(msg))
Copy link
Member Author

Choose a reason for hiding this comment

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

This could probably be achieved through a custom logrus formatter as well, but I think this is concise and works well enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, no need to right now unless you can think of other places that need redactions.

// redact removes sensitive information from a Message.
// Use this before logging a message.
func redact(msg *Message) *Message {
redacted := z.Dereference(msg)
Copy link
Member

Choose a reason for hiding this comment

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

This is really a gratuitous use of z.Deference, don't use this in place of a if msg != nil. Code tricks obscure the intention and decrease readibility. z.Dereference is mostly acceptable when dealing it native types (*int, *string, *bool) because they are very unnatural to interact with, but a struct pointer shouldn't fall into that bucket.

Copy link
Member Author

@njhale njhale Aug 1, 2023

Choose a reason for hiding this comment

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

That's reasonable, I'll amend this to something like

var redacted Message
if msg != nil {
    redacted = *msg
}

and update the godocs for z.Dereference to prevent future misuse

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.

acorn-io/z#6

This prevents credential leakage when using higher log levels during
builds.

Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
@njhale njhale merged commit 11b7b50 into acorn-io:main Aug 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants