feat: drop unknown typed frames instead of storing as chat
Some checks failed
ci / test (push) Has been cancelled
release / aarch64 (push) Failing after 2m8s

Classify decrypted plaintext before append_message so loc/prf/inv/rcp/png
and unknown xxx[space] prefixes never land in the message log.
This commit is contained in:
Sirius DevOps 2026-09-10 14:18:06 -04:00
commit c9d85d9ae5
No known key found for this signature in database
4 changed files with 105 additions and 18 deletions

View file

@ -9,6 +9,7 @@ use futures::io::{AsyncRead, AsyncWrite};
use tor_cell::relaycell::msg::Connected;
use tor_hsservice::{RunningOnionService, handle_rend_requests};
use crate::dispatch::{self, Kind};
use crate::frame;
use crate::hs::{self, Client, HS_PORT};
use crate::loc;
@ -308,26 +309,33 @@ impl Node {
.map_err(session_err)?;
let ct = frame::read_frame(stream).await.map_err(|e| e.to_string())?;
let pt = sess.decrypt(&ct).map_err(session_err)?;
if let Some(loc) = loc::decode(&pt) {
let applied = store.lock().map_err(|e| e.to_string())?.apply_loc(
&sess.peer_identity,
&loc.onion,
loc.ts,
&loc.sig,
);
match applied {
Ok(true) => {}
Ok(false) => eprintln!("loc dropped (bad sig, stale ts, or unknown friend)"),
Err(e) => return Err(e.to_string()),
match dispatch::classify(&pt) {
Kind::Loc => {
if let Some(loc) = loc::decode(&pt) {
let applied = store.lock().map_err(|e| e.to_string())?.apply_loc(
&sess.peer_identity,
&loc.onion,
loc.ts,
&loc.sig,
);
match applied {
Ok(true) => {}
Ok(false) => eprintln!("loc dropped (bad sig, stale ts, or unknown friend)"),
Err(e) => return Err(e.to_string()),
}
}
Ok(())
}
return Ok(());
Kind::Chat => {
store
.lock()
.map_err(|e| e.to_string())?
.append_message(&sess.peer_identity, "in", &pt)
.map_err(|e| e.to_string())?;
Ok(())
}
Kind::Profile | Kind::Invoice | Kind::Receipt | Kind::Ping | Kind::Drop => Ok(()),
}
store
.lock()
.map_err(|e| e.to_string())?
.append_message(&sess.peer_identity, "in", &pt)
.map_err(|e| e.to_string())?;
Ok(())
}
}