Repository: lettre/lettre (language: rust)

Issue:
Email addresses are logged in clear text by default
For many applications, client-identifying information can be sensitive, and should not be exposed in log files.

**Describe the bug**
Email addresses are logged at the "info" level and visible in clear text.

**To Reproduce**
Set log level to "info" and send an email with lettre.

**Expected behavior**
Email addresses are private and should not be shown in logs by default, regardless of global log settings.




Discussion / hints:
Indeed, we should make logging configurable and disable address logging by default

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 8cbb96385..b32fa4f2c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,7 +23,7 @@ hostname = { version = "0.3", optional = true }
 hyperx = { version = "1", optional = true, features = ["headers"] }
 idna = "0.2"
 line-wrap = "0.1"
-log = "0.4"
+log = { version = "0.4", optional = true }
 mime = { version = "0.3", optional = true }
 native-tls = { version = "0.2", optional = true }
 nom = { version = "5", optional = true }
diff --git a/src/transport/sendmail/mod.rs b/src/transport/sendmail/mod.rs
index 9d8f066be..0e8f8a796 100644
--- a/src/transport/sendmail/mod.rs
+++ b/src/transport/sendmail/mod.rs
@@ -1,8 +1,7 @@
 //! The sendmail transport sends the email using the local sendmail command.
 //!
 
-use crate::Envelope;
-use crate::{transport::sendmail::error::SendmailResult, Transport};
+use crate::{transport::sendmail::error::SendmailResult, Envelope, Transport};
 use std::{
     convert::AsRef,
     io::prelude::*,
diff --git a/src/transport/smtp/client/mod.rs b/src/transport/smtp/client/mod.rs
index d32ca8479..d4d10d63d 100644
--- a/src/transport/smtp/client/mod.rs
+++ b/src/transport/smtp/client/mod.rs
@@ -1,15 +1,18 @@
 //! SMTP client
 
-use crate::transport::smtp::{
-    authentication::{Credentials, Mechanism},
-    client::net::{NetworkStream, TlsParameters},
-    commands::*,
-    error::{Error, SmtpResult},
-    extension::{ClientId, Extension, MailBodyParameter, MailParameter, ServerInfo},
-    response::Response,
+use crate::{
+    transport::smtp::{
+        authentication::{Credentials, Mechanism},
+        client::net::{NetworkStream, TlsParameters},
+        commands::*,
+        error::{Error, SmtpResult},
+        extension::{ClientId, Extension, MailBodyParameter, MailParameter, ServerInfo},
+        response::Response,
+    },
+    Envelope,
 };
-use crate::Envelope;
 use bufstream::BufStream;
+#[cfg(feature = "log")]
 use log::debug;
 #[cfg(feature = "serde")]
 use std::fmt::Debug;
@@ -75,6 +78,7 @@ impl ClientCodec {
 
 /// Returns the string replacing all the CRLF with "\<CRLF\>"
 /// Used for debug displays
+#[cfg(feature = "log")]
 fn escape_crlf(string: &str) -> String {
     string.replace("\r\n", "<CRLF>")
 }
@@ -129,6 +133,7 @@ impl SmtpConnection {
             Some(addr) => addr,
             None => return_err!("Could not resolve hostname", self),
         };
+        #[cfg(feature = "log")]
         debug!("connecting to {}", server_addr);
 
         let stream = BufStream::new(NetworkStream::connect(
@@ -148,6 +153,7 @@ impl SmtpConnection {
         conn.ehlo(hello_name)?;
 
         // Print server information
+        #[cfg(feature = "log")]
         debug!("server {}", conn.server_info);
         Ok(conn)
     }
@@ -197,6 +203,7 @@ impl SmtpConnection {
             {
                 try_smtp!(self.command(Starttls), self);
                 try_smtp!(self.stream.get_mut().upgrade_tls(tls_parameters), self);
+                #[cfg(feature = "log")]
                 debug!("connection encrypted");
                 // Send EHLO again
                 try_smtp!(self.ehlo(hello_name), self);
@@ -309,6 +316,7 @@ impl SmtpConnection {
         self.stream.write_all(string)?;
         self.stream.flush()?;
 
+        #[cfg(feature = "log")]
         debug!(
             "Wrote: {}",
             escape_crlf(String::from_utf8_lossy(string).as_ref())
@@ -338,6 +346,7 @@ impl SmtpConnection {
             response = raw_response.parse::<Response>();
         }
 
+        #[cfg(feature = "log")]
         debug!("Read: {}", escape_crlf(raw_response.as_ref()));
 
         let final_response = response?;
@@ -352,7 +361,7 @@ impl SmtpConnection {
 
 #[cfg(test)]
 mod test {
-    use super::{escape_crlf, ClientCodec};
+    use super::*;
 
     #[test]
     fn test_codec() {
@@ -375,6 +384,7 @@ mod test {
     }
 
     #[test]
+    #[cfg(feature = "log")]
     fn test_escape_crlf() {
         assert_eq!(escape_crlf("\r\n"), "<CRLF>");
         assert_eq!(escape_crlf("EHLO my_name\r\n"), "EHLO my_name<CRLF>");
diff --git a/src/transport/smtp/commands.rs b/src/transport/smtp/commands.rs
index 6cee1eba8..5a35c8627 100644
--- a/src/transport/smtp/commands.rs
+++ b/src/transport/smtp/commands.rs
@@ -9,6 +9,7 @@ use crate::{
     },
     Address,
 };
+#[cfg(feature = "log")]
 use log::debug;
 use std::{
     convert::AsRef,
@@ -274,9 +275,11 @@ impl Auth {
         let encoded_challenge = response
             .first_word()
             .ok_or(Error::ResponseParsing("Could not read auth challenge"))?;
+        #[cfg(feature = "log")]
         debug!("auth encoded challenge: {}", encoded_challenge);
 
         let decoded_challenge = String::from_utf8(base64::decode(&encoded_challenge)?)?;
+        #[cfg(feature = "log")]
         debug!("auth decoded challenge: {}", decoded_challenge);
 
         let response = Some(mechanism.response(&credentials, Some(decoded_challenge.as_ref()))?);
diff --git a/src/transport/stub/mod.rs b/src/transport/stub/mod.rs
index a24fb96a6..5d4e28de8 100644
--- a/src/transport/stub/mod.rs
+++ b/src/transport/stub/mod.rs
@@ -2,8 +2,7 @@
 //! testing purposes.
 //!
 
-use crate::Envelope;
-use crate::Transport;
+use crate::{Envelope, Transport};
 
 /// This transport logs the message envelope and returns the given response
 #[derive(Debug, Clone, Copy)]


Test patch: