Skip to content

Commit 270bb42

Browse files
committed
fix: don't leak Group-ID in Message-ID
Chat assignment based on In-Reply-To and References works good enough even if the message cannot be decrypted.
1 parent 3e3de4a commit 270bb42

File tree

4 files changed

+14
-34
lines changed

4 files changed

+14
-34
lines changed

src/chat.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,13 +1795,7 @@ impl Chat {
17951795
let mut location_id = 0;
17961796

17971797
let from = context.get_primary_self_addr().await?;
1798-
let new_rfc724_mid = {
1799-
let grpid = match self.typ {
1800-
Chattype::Group => Some(self.grpid.as_str()),
1801-
_ => None,
1802-
};
1803-
create_outgoing_rfc724_mid(grpid, &from)
1804-
};
1798+
let new_rfc724_mid = create_outgoing_rfc724_mid(&from);
18051799

18061800
if self.typ == Chattype::Single {
18071801
if let Some(id) = context
@@ -4151,7 +4145,7 @@ pub async fn add_device_msg_with_importance(
41514145
if let Some(msg) = msg {
41524146
chat_id = ChatId::get_for_contact(context, ContactId::DEVICE).await?;
41534147

4154-
let rfc724_mid = create_outgoing_rfc724_mid(None, "@device");
4148+
let rfc724_mid = create_outgoing_rfc724_mid("@device");
41554149
prepare_msg_blob(context, msg).await?;
41564150

41574151
let timestamp_sent = create_smeared_timestamp(context);
@@ -4291,7 +4285,7 @@ pub(crate) async fn add_info_msg_with_cmd(
42914285
parent: Option<&Message>,
42924286
from_id: Option<ContactId>,
42934287
) -> Result<MsgId> {
4294-
let rfc724_mid = create_outgoing_rfc724_mid(None, "@device");
4288+
let rfc724_mid = create_outgoing_rfc724_mid("@device");
42954289
let ephemeral_timer = chat_id.get_ephemeral_timer(context).await?;
42964290

42974291
let mut param = Params::new();
@@ -5932,11 +5926,11 @@ mod tests {
59325926
// Alice has an SMTP-server replacing the `Message-ID:`-header (as done eg. by outlook.com).
59335927
let sent_msg = alice.pop_sent_msg().await;
59345928
let msg = sent_msg.payload();
5935-
assert_eq!(msg.match_indices("Message-ID: <Gr.").count(), 2);
5936-
assert_eq!(msg.match_indices("References: <Gr.").count(), 1);
5937-
let msg = msg.replace("Message-ID: <Gr.", "Message-ID: <XXX");
5938-
assert_eq!(msg.match_indices("Message-ID: <Gr.").count(), 0);
5939-
assert_eq!(msg.match_indices("References: <Gr.").count(), 1);
5929+
assert_eq!(msg.match_indices("Message-ID: <Mr.").count(), 2);
5930+
assert_eq!(msg.match_indices("References: <Mr.").count(), 1);
5931+
let msg = msg.replace("Message-ID: <Mr.", "Message-ID: <XXX");
5932+
assert_eq!(msg.match_indices("Message-ID: <Mr.").count(), 0);
5933+
assert_eq!(msg.match_indices("References: <Mr.").count(), 1);
59405934

59415935
// Bob receives this message, he may detect group by `References:`- or `Chat-Group:`-header
59425936
receive_imf(&bob, msg.as_bytes(), false).await.unwrap();
@@ -5953,7 +5947,7 @@ mod tests {
59535947
send_text_msg(&bob, bob_chat.id, "ho!".to_string()).await?;
59545948
let sent_msg = bob.pop_sent_msg().await;
59555949
let msg = sent_msg.payload();
5956-
let msg = msg.replace("Message-ID: <Gr.", "Message-ID: <XXX");
5950+
let msg = msg.replace("Message-ID: <Mr.", "Message-ID: <XXX");
59575951
let msg = msg.replace("Chat-", "XXXX-");
59585952
assert_eq!(msg.match_indices("Chat-").count(), 0);
59595953

src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ mod tests {
13591359
\n\
13601360
hello\n",
13611361
contact.get_addr(),
1362-
create_outgoing_rfc724_mid(None, contact.get_addr())
1362+
create_outgoing_rfc724_mid(contact.get_addr())
13631363
);
13641364
println!("{msg}");
13651365
receive_imf(t, msg.as_bytes(), false).await.unwrap();

src/mimefactory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl<'a> MimeFactory<'a> {
551551

552552
let rfc724_mid = match self.loaded {
553553
Loaded::Message { .. } => self.msg.rfc724_mid.clone(),
554-
Loaded::Mdn { .. } => create_outgoing_rfc724_mid(None, &self.from_addr),
554+
Loaded::Mdn { .. } => create_outgoing_rfc724_mid(&self.from_addr),
555555
};
556556
let rfc724_mid_headervalue = render_rfc724_mid(&rfc724_mid);
557557
let rfc724_mid_header = Header::new("Message-ID".into(), rfc724_mid_headervalue);

src/tools.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,12 @@ pub(crate) fn create_id() -> String {
281281
/// - this function is called for all outgoing messages.
282282
/// - the message ID should be globally unique
283283
/// - do not add a counter or any private data as this leaks information unnecessarily
284-
pub(crate) fn create_outgoing_rfc724_mid(grpid: Option<&str>, from_addr: &str) -> String {
284+
pub(crate) fn create_outgoing_rfc724_mid(from_addr: &str) -> String {
285285
let hostname = from_addr
286286
.find('@')
287287
.and_then(|k| from_addr.get(k..))
288288
.unwrap_or("@nohost");
289-
match grpid {
290-
Some(grpid) => format!("Gr.{}.{}{}", grpid, create_id(), hostname),
291-
None => format!("Mr.{}.{}{}", create_id(), create_id(), hostname),
292-
}
289+
format!("Mr.{}.{}{}", create_id(), create_id(), hostname)
293290
}
294291

295292
/// Extract the group id (grpid) from a message id (mid)
@@ -1013,21 +1010,10 @@ DKIM Results: Passed=true, Works=true, Allow_Keychange=true";
10131010

10141011
#[test]
10151012
fn test_create_outgoing_rfc724_mid() {
1016-
// create a normal message-id
1017-
let mid = create_outgoing_rfc724_mid(None, "foo@bar.de");
1013+
let mid = create_outgoing_rfc724_mid("foo@bar.de");
10181014
assert!(mid.starts_with("Mr."));
10191015
assert!(mid.ends_with("bar.de"));
10201016
assert!(extract_grpid_from_rfc724_mid(mid.as_str()).is_none());
1021-
1022-
// create a message-id containing a group-id
1023-
let grpid = create_id();
1024-
let mid = create_outgoing_rfc724_mid(Some(&grpid), "foo@bar.de");
1025-
assert!(mid.starts_with("Gr."));
1026-
assert!(mid.ends_with("bar.de"));
1027-
assert_eq!(
1028-
extract_grpid_from_rfc724_mid(mid.as_str()),
1029-
Some(grpid.as_str())
1030-
);
10311017
}
10321018

10331019
#[test]

0 commit comments

Comments
 (0)