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: avoid leak of tenant token on the logs #1620

Draft
wants to merge 1 commit into
base: 3.5.x
Choose a base branch
from

Conversation

MuchoLucho
Copy link
Member

Changelog: None
Ticket: None

External Contributor Checklist

🚨 Please review the guidelines for contributing to this repository.

  • Make sure that all commits follow the conventional commit specification for the Mender project.

The majority of our contributions are fixes, which means your commit should have
the form below:

fix: <SHORT DESCRIPTION OF FIX>

<OPTIONAL LONGER DESCRIPTION>

Changelog: <USER-FRIENDLY-CHANGE-DESCRIPTION> or <None>
Ticket: <TICKET NUMBER> or <None>
  • Make sure that all commits are signed with git --signoff. Also note that the signoff author must match the author of the commit.

Description

Please describe your pull request.

Thank you!

Changelog: None
Ticket: None

Signed-off-by: Luis Ramirez <[email protected]>
@MuchoLucho
Copy link
Member Author

I am not a Go guy, so I am sure it can be made more elegant. Open to suggestions

@buentead
Copy link

buentead commented May 1, 2024

@MuchoLucho : Thanks for the change. From a security point of view a must have. It will be easier to share the debug logs. Very much appreciated!

Copy link
Contributor

@lluiscampos lluiscampos left a comment

Choose a reason for hiding this comment

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

Great first start in golang, @MuchoLucho ! See my comments below I think we can brush this up and merge it.

Also please add a good changelog entry, this is clearly user facing and we will release it.

Comment on lines +679 to +686
tentok4Log := tentok

// Truncates the tenant token for avoid any leak
if len(tentok) > 4 {
tentok4Log = tentok[0:2] + "..." + tentok[len(tentok)-2:]
}

log.Debugf("Tenant token: %s", tentok4Log)
Copy link
Contributor

Choose a reason for hiding this comment

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

With regards to the general logic. It won't happen in practice, but look at the following:

  • do a copy of tenok to tenok4log
  • if something something, then redact tenok4log for sercure logging
  • log unconditionally

See the issue? If the if is false then you log the original secret tenok.

There are many ways to solve this. One way:

Suggested change
tentok4Log := tentok
// Truncates the tenant token for avoid any leak
if len(tentok) > 4 {
tentok4Log = tentok[0:2] + "..." + tentok[len(tentok)-2:]
}
log.Debugf("Tenant token: %s", tentok4Log)
tentok4Log := ""
// Truncates the tenant token for avoid any leak
if len(tentok) > 4 {
tentok4Log = tentok[0:2] + "..." + tentok[len(tentok)-2:]
}
log.Debugf("Tenant token: %s", tentok4Log)

and a simpler one:

Suggested change
tentok4Log := tentok
// Truncates the tenant token for avoid any leak
if len(tentok) > 4 {
tentok4Log = tentok[0:2] + "..." + tentok[len(tentok)-2:]
}
log.Debugf("Tenant token: %s", tentok4Log)
// Truncates the tenant token for avoid any leak
if len(tentok) > 4 {
log.Debugf("Tenant token: %s..%s", tentok[0:2], tentok[len(tentok)-2:])
}

tentok4Log = tentok[0:2] + "..." + tentok[len(tentok)-2:]
}

log.Debugf("Tenant token: %s", tentok4Log)

// fill tenant token
authd.TenantToken = string(tentok)
Copy link
Contributor

Choose a reason for hiding this comment

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

Two lines below we have log.Debugf("Authorization data: %v", authd) which also will leak the token, right?

@lluiscampos lluiscampos self-assigned this May 2, 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.

3 participants