-
Notifications
You must be signed in to change notification settings - Fork 197
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
base: 3.5.x
Are you sure you want to change the base?
Conversation
Changelog: None Ticket: None Signed-off-by: Luis Ramirez <[email protected]>
I am not a Go guy, so I am sure it can be made more elegant. Open to suggestions |
@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! |
There was a problem hiding this 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.
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) |
There was a problem hiding this comment.
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:
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:
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) |
There was a problem hiding this comment.
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?
Changelog: None
Ticket: None
External Contributor Checklist
🚨 Please review the guidelines for contributing to this repository.
The majority of our contributions are fixes, which means your commit should have
the form below:
git --signoff
. Also note that the signoff author must match the author of the commit.Description
Please describe your pull request.
Thank you!