-
Notifications
You must be signed in to change notification settings - Fork 12
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: missing_debug_implementations
#46
fix: missing_debug_implementations
#46
Conversation
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 cryptographic algorithms we should be careful about unintentionally leaking sensitive information. You should not derive Debug
for things like CtrNonce*
, instead you should write a manual "opaque" implementation like here. Same for your similar PRs in other repositories.
I do not think these security concerns are valid. You cannot prevent a user of the library simply doing I do not think there are any reasonable security concerns that should lead to restricting implementation of |
@JonathanWoollett-Light the important part is to prevent users from accidentally leaking sensitive details like a cipher's internal state.
I think it's great to have this lint in place and |
@tarcieri My understanding is that the intended usage of
In the cases where the respective struct member is not public, deriving If to debug an issue a developer wants to view the all the data which may affect this or possibly suspects the issues involves some specific data they would need to write an awkward workaround.
I would consider an example like: #[derive(Debug)]
struct User {
username: String,
password: String
}
fn register(user: User) {
log::trace!("user: {user}");
// ...
} The logging here may log the user password to a file (or otherwise store it) which is not secure. A solution with a custom struct User {
username: String,
password: String
}
impl std::fmt::Debug for User {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("User ")
.field("username", &self.username)
.finish()
}
}
fn register(user: User) {
log::trace!("user: {user}");
// ...
} But this does not seem reasonable to me, the flaw is with If we implement I think here the default implementation is idiomatic and reasonable. I think it is reasonable that if someone prints a data-structure containing sensitive data, the sensitive data is printed. And vice-versa it would not be reasonable to print a data-structure containing sensitive data and expect this to not be printed. I think the default implementation is expected and simple. |
We already endeavor throughout the project to avoid accidentally logging secrets via custom In my time as an infosec professional for a PCI-DSS Level 1 environment, accidental logging of secrets through debugging was the largest vector of secret exfiltration by far. In fact, trying to armor applications against accidentally logging secrets this way was one of the main things I worked on at my time there.
Secrets can get accidentally logged to exception reporting systems this way, even if no explicit attempt was made to log debugging information, simply via things like panic messages. There may be absolutely no intent to print anything, and unless secrets are guarded from Beyond mere accidental secret logging, an attacker can also potentially get an application to log secrets to a crash reporting service this way. |
I think this is an exceptional case, I can only see this occurring when doing an assertion with
|
Again, a panic message can include an attempt to log a seemingly innocuous value, only for it to contain sensitive cryptographic secrets. If someone really wants to log a sensitive cryptographic secret, our philosophy is that should come with clear intent, and not be something you can accidentally do via traversing a much larger data structure which is mostly non-sensitive. |
619834d
to
591e500
Compare
Updated to use manual |
Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
591e500
to
40bc0ae
Compare
@newpavlov Could you please re-review. |
Thank you! |
Sets
missing_debug_implementations
to warn and adds missingstd::fmt::Debug
implementations.When tracing/logging/debugging a program it is common to debug print inputs and outputs of function, to do this generally dependencies need to offer
std::fmt::Debug
implementations.I won't repeat what is written under
missing_debug_implementations
which gives some more explanation.