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
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,14 @@ func (m *menderAuthManagerService) MakeAuthRequest() (*client.AuthRequest, error

tentok := strings.TrimSpace(string(m.tenantToken))

log.Debugf("Tenant token: %s", tentok)
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)
Comment on lines +679 to +686
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:])
}


// 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?

Expand Down