Skip to content

Commit 1a1467f

Browse files
iequidoolink2xt
authored andcommitted
fix: Remove unsigned Chat-Group-* headers from Autocrypt-encrypted messages
These headers are opportunistically protected, so if they appear in the unencrypted part, they are probably added by a malicious server.
1 parent 8d09291 commit 1a1467f

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/mimeparser.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,20 @@ impl MimeMessage {
348348
gossip_headers,
349349
)
350350
.await?;
351-
// Remove unsigned subject from messages displayed with padlock.
352-
// See <https://github.com/deltachat/deltachat-core-rust/issues/1790>.
353-
headers.remove("subject");
351+
// Remove unsigned opportunistically protected headers from messages considered
352+
// Autocrypt-encrypted / displayed with padlock.
353+
// For "Subject" see <https://github.com/deltachat/deltachat-core-rust/issues/1790>.
354+
for h in [
355+
HeaderDef::Subject,
356+
HeaderDef::ChatGroupId,
357+
HeaderDef::ChatGroupName,
358+
HeaderDef::ChatGroupNameChanged,
359+
HeaderDef::ChatGroupAvatar,
360+
HeaderDef::ChatGroupMemberRemoved,
361+
HeaderDef::ChatGroupMemberAdded,
362+
] {
363+
headers.remove(h.get_headername());
364+
}
354365
}
355366

356367
// let known protected headers from the decrypted

src/receive_imf/tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,6 +3547,32 @@ async fn test_mua_user_adds_recipient_to_single_chat() -> Result<()> {
35473547
Ok(())
35483548
}
35493549

3550+
/// If a message is Autocrypt-encrypted, unsigned Chat-Group-* headers have no effect.
3551+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
3552+
async fn test_unsigned_chat_group_hdr() -> Result<()> {
3553+
let mut tcm = TestContextManager::new();
3554+
let alice = &tcm.alice().await;
3555+
let bob = &tcm.bob().await;
3556+
let bob_addr = bob.get_config(Config::Addr).await?.unwrap();
3557+
let bob_id = Contact::create(alice, "Bob", &bob_addr).await?;
3558+
let alice_chat_id = create_group_chat(alice, ProtectionStatus::Unprotected, "foos").await?;
3559+
add_contact_to_chat(alice, alice_chat_id, bob_id).await?;
3560+
send_text_msg(alice, alice_chat_id, "populate".to_string()).await?;
3561+
let sent_msg = alice.pop_sent_msg().await;
3562+
let bob_chat_id = bob.recv_msg(&sent_msg).await.chat_id;
3563+
bob_chat_id.accept(bob).await?;
3564+
send_text_msg(bob, bob_chat_id, "hi all!".to_string()).await?;
3565+
let mut sent_msg = bob.pop_sent_msg().await;
3566+
sent_msg.payload = sent_msg.payload.replace(
3567+
"Chat-Version:",
3568+
&format!("Chat-Group-Member-Removed: {bob_addr}\r\nChat-Version:"),
3569+
);
3570+
let chat_id = alice.recv_msg(&sent_msg).await.chat_id;
3571+
assert_eq!(chat_id, alice_chat_id);
3572+
assert_eq!(get_chat_contacts(alice, alice_chat_id).await?.len(), 2);
3573+
Ok(())
3574+
}
3575+
35503576
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
35513577
async fn test_sync_member_list_on_rejoin() -> Result<()> {
35523578
let mut tcm = TestContextManager::new();

0 commit comments

Comments
 (0)