From b3def46ed1ab1def266a1c5509f7efd3c2752e7d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 31 Oct 2026 22:33:51 -0700 Subject: [PATCH 1/3] fix: redact credential diagnostics on release Port the diagnostic redaction from moq-dev/moq#7200 while retaining release types and wire encoding. Also redact malformed-message dumps and duplicate GOAWAY redirects. Co-Authored-By: GPT-6.1 Sol --- Cargo.lock | 2 + rs/moq-auth/Cargo.toml | 1 + rs/moq-auth/src/error.rs | 4 +- rs/moq-auth/src/request.rs | 31 ++++++- rs/moq-auth/src/serve.rs | 59 ++++++++++++- rs/moq-net/Cargo.toml | 1 + rs/moq-net/src/goaway.rs | 11 ++- rs/moq-net/src/ietf/goaway.rs | 12 ++- rs/moq-net/src/ietf/message.rs | 3 +- rs/moq-net/src/ietf/parameters.rs | 19 +++- rs/moq-net/src/lite/goaway.rs | 9 +- rs/moq-net/src/lite/message.rs | 3 +- rs/moq-net/src/lite/parameters.rs | 10 ++- rs/moq-net/src/lite/publisher.rs | 4 +- rs/moq-net/src/lite/setup.rs | 18 +++- rs/moq-net/src/setup.rs | 140 +++++++++++++++++++++++++++++- rs/moq-net/tests/goaway.rs | 25 ++++-- rs/moq-relay/src/auth.rs | 4 +- rs/moq-relay/src/cluster.rs | 28 +++--- rs/moq-relay/src/connection.rs | 8 +- 20 files changed, 347 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2ff0c9b6d2..97666e43d20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4229,6 +4229,7 @@ dependencies = [ "thiserror 2.0.21", "tokio", "tracing", + "tracing-test", "url", "wiremock", ] @@ -4517,6 +4518,7 @@ dependencies = [ "thiserror 2.0.21", "tokio", "tracing", + "tracing-test", "wasm-bindgen-test", "web-async", "web-transport-trait", diff --git a/rs/moq-auth/Cargo.toml b/rs/moq-auth/Cargo.toml index e4718dd1d52..00e9a5f02d5 100644 --- a/rs/moq-auth/Cargo.toml +++ b/rs/moq-auth/Cargo.toml @@ -44,4 +44,5 @@ moq-auth = { path = ".", features = ["client", "serve"] } moq-token = "0.7" tempfile = { workspace = true } tokio = { workspace = true, features = ["macros", "rt-multi-thread", "test-util"] } +tracing-test = { workspace = true } wiremock = "0.6" diff --git a/rs/moq-auth/src/error.rs b/rs/moq-auth/src/error.rs index 6825f063084..058a1051020 100644 --- a/rs/moq-auth/src/error.rs +++ b/rs/moq-auth/src/error.rs @@ -72,10 +72,10 @@ pub enum Error { #[error("no publish or subscribe allowed; token is useless")] UselessToken, - #[error("path `{0}` does not overlap the token root")] + #[error("path {0:?} does not overlap the token root")] RootMismatch(String), - #[error("token grants no access to path `{0}`")] + #[error("token grants no access to path {0:?}")] NoAccess(String), #[error("no publish or subscribe allowed; key scope is useless")] diff --git a/rs/moq-auth/src/request.rs b/rs/moq-auth/src/request.rs index 59628467da5..59bf0af06ec 100644 --- a/rs/moq-auth/src/request.rs +++ b/rs/moq-auth/src/request.rs @@ -14,7 +14,7 @@ use crate::lease::Reason; /// query parameter is special and a credential can be whatever the server understands. The same shape carries /// every [`Event`]; an `end` adds what the session did. #[serde_with::skip_serializing_none] -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Serialize, Deserialize, PartialEq)] #[non_exhaustive] pub struct Request { /// Random 128-bit hex, unique per session; the key every event for it shares. @@ -58,6 +58,27 @@ pub struct Request { pub tls: Option, } +impl std::fmt::Debug for Request { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Request") + .field("id", &self.id) + .field("event", &self.event) + .field("node", &self.node) + .field("transport", &self.transport) + .field("remote", &self.remote) + .field("local", &self.local) + .field("server_name", &self.server_name) + .field("alpn", &self.alpn) + .field("path", &self.path) + // The contract permits credentials under any query key. + .field("query", &self.query.as_ref().map(|_| "...")) + .field("token", &self.token) + .field("role", &self.role) + .field("tls", &self.tls) + .finish() + } +} + impl Request { /// A `connect` for a fresh session, minting a random 128-bit hex id. /// @@ -87,7 +108,7 @@ impl Request { /// A credential from a moq-transport SETUP's `AUTHORIZATION TOKEN` option, unparsed. #[serde_as] -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Token { /// The moq-transport Token Type, naming how [`value`](Self::value) is encoded. pub kind: u64, @@ -96,6 +117,12 @@ pub struct Token { pub value: Vec, } +impl std::fmt::Debug for Token { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Token(kind={}, <{} bytes>)", self.kind, self.value.len()) + } +} + impl Token { /// Token Type 0: a format negotiated out of band; `moq auth serve` reads it as a JWT. pub const OUT_OF_BAND: u64 = 0x0; diff --git a/rs/moq-auth/src/serve.rs b/rs/moq-auth/src/serve.rs index 9f7475fdc1f..53755080496 100644 --- a/rs/moq-auth/src/serve.rs +++ b/rs/moq-auth/src/serve.rs @@ -103,9 +103,9 @@ pub enum Refusal { UnknownKey, #[error("the token is invalid: {0}")] InvalidToken(String), - #[error("the token root `{root}` does not overlap the dialed path `{path}`")] + #[error("the token root {root:?} does not overlap the dialed path {path:?}")] RootMismatch { root: String, path: String }, - #[error("nothing is granted at `{path}`")] + #[error("nothing is granted at {path:?}")] NoAccess { path: String }, #[error("a certificate was presented but nothing is granted to certificates")] NoMtlsGrant, @@ -394,7 +394,7 @@ async fn handle(State(server): State, Json(request): Json) -> R // The reason rides in the body, so an operator reading the relay's log knows // which rule refused without the server saying anything to the client. Err(refusal) => { - tracing::debug!(id = %request.id, path = %request.path, %refusal, "refused"); + tracing::debug!(id = ?request.id, path = ?request.path, ?refusal, "refused"); (StatusCode::FORBIDDEN, refusal.to_string()).into_response() } } @@ -425,6 +425,59 @@ mod tests { request } + #[tokio::test(start_paused = true)] + #[tracing_test::traced_test] + async fn refusal_fields_are_escaped_and_credentials_are_redacted() { + let secret = "credential-that-must-not-be-logged"; + let mut facts = with_token(request("/room\nforged-record\r\x1b[31m"), secret); + facts.id = "id\nforged-id".into(); + facts.token = Some(Token { + kind: Token::OUT_OF_BAND, + value: secret.as_bytes().to_vec(), + }); + tracing::trace!(request = ?facts, "admission diagnostics"); + let response = handle(State(Server::new(Policy::default()).unwrap()), Json(facts)).await; + assert_eq!(response.status(), StatusCode::FORBIDDEN); + assert!(logs_contain("refused")); + assert!(!logs_contain(secret)); + let decimal = format!("{:?}", secret.as_bytes()); + assert!(!logs_contain(&decimal[1..decimal.len() - 1])); + assert!(!logs_contain("\nforged-record")); + assert!(!logs_contain("\nforged-id")); + + let (dir, key) = key_dir(); + let root = "root\nforged-root\r\x1b[31m"; + let jwt = sign(&key, root, &["**"], &[], None); + let policy = Policy { + keys: Some(Keys::Dir(dir.path().into())), + ..Default::default() + }; + let response = handle( + State(Server::new(policy).unwrap()), + Json(with_token(request("/elsewhere"), &jwt)), + ) + .await; + assert_eq!(response.status(), StatusCode::FORBIDDEN); + assert!(logs_contain("RootMismatch")); + assert!(!logs_contain(&jwt)); + assert!(!logs_contain("\nforged-root")); + for err in [ + Refusal::RootMismatch { + root: root.into(), + path: "path\nforged-path".into(), + } + .to_string(), + Refusal::NoAccess { + path: "path\nforged-path".into(), + } + .to_string(), + crate::Error::RootMismatch("path\nforged-path".into()).to_string(), + crate::Error::NoAccess("path\nforged-path".into()).to_string(), + ] { + assert!(!err.contains('\n')); + } + } + fn with_peer(mut request: Request, expires: Option) -> Request { request.tls = Some(Peer { name: "edge0".into(), diff --git a/rs/moq-net/Cargo.toml b/rs/moq-net/Cargo.toml index c9510cfe781..90ada4daadb 100644 --- a/rs/moq-net/Cargo.toml +++ b/rs/moq-net/Cargo.toml @@ -41,6 +41,7 @@ serde_json = { workspace = true } # test-util (tokio::time::pause/advance) is test-only and is NOT supported on # wasm, so it must not leak into the normal dependency feature set. tokio = { workspace = true, features = ["macros", "io-util", "sync", "test-util", "time", "rt"] } +tracing-test = { workspace = true, features = ["no-env-filter"] } # Model checks for the kio-backed model layer (tests/loom.rs). `cfg(loom)` is only # set by `just rs loom`, and the whole test file compiles away without it. diff --git a/rs/moq-net/src/goaway.rs b/rs/moq-net/src/goaway.rs index 714d15d1fc0..e0e1a655548 100644 --- a/rs/moq-net/src/goaway.rs +++ b/rs/moq-net/src/goaway.rs @@ -30,7 +30,7 @@ const MAX_TIMEOUT_MS: u64 = (1 << 62) - 1; /// A GOAWAY: the sender intends to close the session soon and the peer should /// migrate its subscriptions elsewhere. -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Default, PartialEq, Eq)] pub struct Goaway { /// Where the peer should reconnect, including any credentials it needs. /// Empty means reconnect to the same endpoint. @@ -44,6 +44,15 @@ pub struct Goaway { pub(crate) timeout: Option, } +impl std::fmt::Debug for Goaway { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Goaway") + .field("uri_len", &self.uri.len()) + .field("timeout", &self.timeout) + .finish() + } +} + impl Goaway { /// Tell the peer to reconnect to the same endpoint. pub fn new() -> Self { diff --git a/rs/moq-net/src/ietf/goaway.rs b/rs/moq-net/src/ietf/goaway.rs index 5df6c3cdf9f..b02ac808f2a 100644 --- a/rs/moq-net/src/ietf/goaway.rs +++ b/rs/moq-net/src/ietf/goaway.rs @@ -9,13 +9,23 @@ use super::Message; use super::Version; /// GoAway message (0x10) -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct GoAway<'a> { pub new_session_uri: Cow<'a, str>, /// Draft-17: timeout in milliseconds before closing the session pub timeout: u64, } +impl std::fmt::Debug for GoAway<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // The new session URI carries whatever credentials the peer needs to dial it. + f.debug_struct("GoAway") + .field("new_session_uri_len", &self.new_session_uri.len()) + .field("timeout", &self.timeout) + .finish() + } +} + impl Message for GoAway<'_> { const ID: u64 = 0x10; diff --git a/rs/moq-net/src/ietf/message.rs b/rs/moq-net/src/ietf/message.rs index 88feed27a85..9657eb60bb8 100644 --- a/rs/moq-net/src/ietf/message.rs +++ b/rs/moq-net/src/ietf/message.rs @@ -101,7 +101,8 @@ impl Decode for T { Ok(result) } Err(e) => { - tracing::warn!(%e, ?raw, "decode failed"); + // A malformed message can contain credentials too. + tracing::warn!(%e, "decode failed"); Err(e) } } diff --git a/rs/moq-net/src/ietf/parameters.rs b/rs/moq-net/src/ietf/parameters.rs index b51ff749623..62f66834564 100644 --- a/rs/moq-net/src/ietf/parameters.rs +++ b/rs/moq-net/src/ietf/parameters.rs @@ -55,12 +55,29 @@ pub enum ParameterBytes { Unknown(u64), } -#[derive(Default, Debug, Clone)] +#[derive(Default, Clone)] pub struct Parameters { vars: HashMap, bytes: HashMap>, } +impl std::fmt::Debug for Parameters { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Parameters") + .field("vars", &self.vars) + // Values can carry credentials, so only their lengths. + .field( + "bytes", + &self + .bytes + .iter() + .map(|(kind, value)| (kind, value.len())) + .collect::>(), + ) + .finish() + } +} + impl Decode for Parameters { fn decode(mut r: &mut R, version: Version) -> Result { let mut vars = HashMap::new(); diff --git a/rs/moq-net/src/lite/goaway.rs b/rs/moq-net/src/lite/goaway.rs index bca47b5e41e..d617e56d492 100644 --- a/rs/moq-net/src/lite/goaway.rs +++ b/rs/moq-net/src/lite/goaway.rs @@ -7,11 +7,18 @@ use super::{Message, Version}; /// Sent to gracefully shut down a session and optionally redirect to a new URI. /// /// Lite04+ only. -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct Goaway<'a> { pub uri: Cow<'a, str>, } +impl std::fmt::Debug for Goaway<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // The redirect carries whatever credentials the peer needs to dial it. + f.debug_struct("Goaway").field("uri_len", &self.uri.len()).finish() + } +} + impl Message for Goaway<'_> { const CONTROL: Option = Some(crate::stats::Control::Goaway); fn decode_msg(r: &mut R, version: Version) -> Result { diff --git a/rs/moq-net/src/lite/message.rs b/rs/moq-net/src/lite/message.rs index 2385882a08c..e6dad923894 100644 --- a/rs/moq-net/src/lite/message.rs +++ b/rs/moq-net/src/lite/message.rs @@ -82,7 +82,8 @@ impl Decode for T { Ok(result) } Err(e) => { - tracing::warn!(%e, ?raw, "decode failed"); + // A malformed message can contain credentials too. + tracing::warn!(%e, "decode failed"); Err(e) } } diff --git a/rs/moq-net/src/lite/parameters.rs b/rs/moq-net/src/lite/parameters.rs index b7930a6c747..a30dff77247 100644 --- a/rs/moq-net/src/lite/parameters.rs +++ b/rs/moq-net/src/lite/parameters.rs @@ -9,9 +9,17 @@ const MAX_PARAMS: u64 = 64; /// A bag of `id -> raw bytes` parameters, the body shared by SETUP (and any other /// parameterized message). Encoded as a varint count followed by `id, length, value` /// triples; duplicate ids are rejected on decode. -#[derive(Default, Debug, Clone)] +#[derive(Default, Clone)] pub struct Parameters(HashMap>); +impl std::fmt::Debug for Parameters { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_map() + .entries(self.0.iter().map(|(kind, value)| (kind, value.len()))) + .finish() + } +} + impl Parameters { /// Set a parameter to a raw byte value, replacing any existing entry. pub fn set_bytes(&mut self, id: u64, value: Vec) { diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index c18974705bc..e3d08408d6d 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -324,7 +324,7 @@ impl Control { // malformed GOAWAY must not tear down the session it is trying to drain. let mut cx = Context::from_waker(waiter.waker()); let msg = ready!(stream.reader.poll_decode::(&mut cx))?; - tracing::info!(uri = %msg.uri, "received goaway"); + tracing::info!(uri_len = msg.uri.len(), "received goaway"); let uri = msg.uri.into_owned(); let goaway = crate::goaway::Goaway { @@ -337,7 +337,7 @@ impl Control { // A second Goaway stream is a protocol violation. The control loop only // logs per-stream errors, so close the session here rather than letting a // peer silently replace a redirect an observer may already be acting on. - tracing::warn!(%uri, "duplicate GOAWAY received; closing session"); + tracing::warn!(uri_len = uri.len(), "duplicate GOAWAY received; closing session"); self.shared .session .clone() diff --git a/rs/moq-net/src/lite/setup.rs b/rs/moq-net/src/lite/setup.rs index b0b7758aea7..712b4486540 100644 --- a/rs/moq-net/src/lite/setup.rs +++ b/rs/moq-net/src/lite/setup.rs @@ -155,7 +155,7 @@ impl std::fmt::Display for Role { /// lite-05+ only. The two endpoints' SETUP messages are independent: neither side /// blocks on the peer's before opening other streams, but a stream whose encoding /// depends on a negotiated capability (e.g. PROBE) must wait for it. -#[derive(Debug, Clone, Default, PartialEq, Eq)] +#[derive(Clone, Default, PartialEq, Eq)] pub struct Setup { /// The probe capability this endpoint supports. [`ProbeLevel::None`] when absent. pub probe: ProbeLevel, @@ -184,6 +184,22 @@ pub struct Setup { pub hop: Option, } +impl std::fmt::Debug for Setup { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Setup") + .field("probe", &self.probe) + // Native transports carry the JWT in this request target. + .field( + "path", + &self.path.as_deref().map(|path| path.split('?').next().unwrap()), + ) + .field("role", &self.role) + .field("cost", &self.cost) + .field("hop", &self.hop) + .finish() + } +} + impl Message for Setup { const CONTROL: Option = Some(crate::stats::Control::Session); const MAX_SIZE: usize = crate::setup::MAX_SETUP_SIZE; diff --git a/rs/moq-net/src/setup.rs b/rs/moq-net/src/setup.rs index 970169b2492..7d1efc64684 100644 --- a/rs/moq-net/src/setup.rs +++ b/rs/moq-net/src/setup.rs @@ -22,7 +22,7 @@ pub(crate) const SETUP_V17: u64 = 0x2F00; /// A credential a moq-transport peer presented in its SETUP's `AUTHORIZATION TOKEN` option. /// /// The transport never reads the bytes; verifying them is the application's job. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] pub struct Token { /// The wire Token Type, naming how [`value`](Self::value) is encoded. pub kind: u64, @@ -30,6 +30,12 @@ pub struct Token { pub value: Vec, } +impl std::fmt::Debug for Token { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Token(kind={}, <{} bytes>)", self.kind, self.value.len()) + } +} + impl Token { /// Token Type 0: a format the endpoints agreed on out of band, such as a JWT. pub const OUT_OF_BAND: u64 = 0x0; @@ -38,11 +44,20 @@ impl Token { } /// Draft-17+ unified SETUP message, with the same encoding for both client and server. -#[derive(Debug, Clone)] +#[derive(Clone)] pub(crate) struct Setup { pub parameters: Bytes, } +impl std::fmt::Debug for Setup { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // Opaque parameters can contain credentials, even before we recognize an option. + f.debug_struct("Setup") + .field("parameters_len", &self.parameters.len()) + .finish() + } +} + impl Setup { fn check_version(v: Version) { match v { @@ -121,7 +136,7 @@ impl SetupVersion { } /// A version-agnostic setup message sent by the client. -#[derive(Debug, Clone)] +#[derive(Clone)] pub(crate) struct Client { /// The list of supported versions in preferred order. pub versions: coding::Versions, @@ -130,6 +145,15 @@ pub(crate) struct Client { pub parameters: Bytes, } +impl std::fmt::Debug for Client { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Client") + .field("versions", &self.versions) + .field("parameters_len", &self.parameters.len()) + .finish() + } +} + impl Client { fn encode_inner(&self, w: &mut W, v: Version) -> Result<(), EncodeError> { match SetupVersion::from_version(v) { @@ -224,7 +248,7 @@ impl Encode for Client { } /// Sent by the server in response to a client setup. -#[derive(Debug, Clone)] +#[derive(Clone)] pub(crate) struct Server { /// The list of supported versions in preferred order. pub version: coding::Version, @@ -233,6 +257,15 @@ pub(crate) struct Server { pub parameters: Bytes, } +impl std::fmt::Debug for Server { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Server") + .field("version", &self.version) + .field("parameters_len", &self.parameters.len()) + .finish() + } +} + impl Server { fn encode_inner(&self, w: &mut W, v: Version) -> Result<(), EncodeError> { match SetupVersion::from_version(v) { @@ -327,6 +360,105 @@ impl Decode for Server { mod tests { use super::*; + #[test] + #[tracing_test::traced_test] + fn credentials_stay_out_of_traces() { + let secret = "credential-that-must-not-be-logged"; + let token = Token { + kind: Token::OUT_OF_BAND, + value: secret.as_bytes().to_vec(), + }; + let setup = lite::Setup { + path: Some(format!("/room?jwt={secret}")), + ..Default::default() + }; + let wire = setup.encode_bytes(lite::Version::Lite06).unwrap(); + let decoded = lite::Setup::decode(&mut wire.as_ref(), lite::Version::Lite06).unwrap(); + assert_eq!(decoded, setup); + + let version = ietf::Version::Draft22; + let mut params = ietf::Parameters::default(); + ietf::token::into_setup(&mut params, &token, version).unwrap(); + params.set_bytes(ietf::ParameterBytes::Path, format!("/room?jwt={secret}").into_bytes()); + let setup = Setup { + parameters: params.encode_bytes(version).unwrap(), + }; + let wire = setup.encode_bytes(Version::Ietf(version)).unwrap(); + let decoded = Setup::decode(&mut wire.as_ref(), Version::Ietf(version)).unwrap(); + let params = ietf::Parameters::decode(&mut decoded.parameters.as_ref(), version).unwrap(); + assert_eq!(ietf::token::from_setup(¶ms, version).unwrap(), Some(token.clone())); + let client = Client { + versions: coding::Versions::from([Version::Ietf(version).into()]), + parameters: setup.parameters.clone(), + }; + let server = Server { + version: Version::Ietf(version).into(), + parameters: setup.parameters.clone(), + }; + let mut lite_params = lite::Parameters::default(); + lite_params.set_bytes(999, secret.as_bytes().to_vec()); + tracing::trace!( + ?token, + ?setup, + ?decoded, + ?params, + ?client, + ?server, + ?lite_params, + "SETUP diagnostics" + ); + + let uri = format!("https://relay.example/room?jwt={secret}"); + let goaway = lite::Goaway { + uri: uri.as_str().into(), + }; + let wire = goaway.encode_bytes(lite::Version::Lite06).unwrap(); + assert_eq!( + lite::Goaway::decode(&mut wire.as_ref(), lite::Version::Lite06) + .unwrap() + .uri, + uri + ); + let goaway = ietf::GoAway { + new_session_uri: uri.as_str().into(), + timeout: 0, + }; + let wire = goaway.encode_bytes(version).unwrap(); + assert_eq!( + ietf::GoAway::decode(&mut wire.as_ref(), version) + .unwrap() + .new_session_uri, + uri + ); + tracing::trace!(goaway = ?crate::goaway::Goaway::redirect(uri), "GOAWAY diagnostics"); + + // A malformed message can still contain a valid credential before the error. + let mut body = Vec::new(); + (secret.len() + 1).encode(&mut body, lite::Version::Lite06).unwrap(); + body.extend_from_slice(secret.as_bytes()); + let mut malformed = Vec::new(); + body.len().encode(&mut malformed, lite::Version::Lite06).unwrap(); + malformed.extend_from_slice(&body); + assert!(lite::Goaway::decode(&mut malformed.as_slice(), lite::Version::Lite06).is_err()); + let mut body = Vec::new(); + // The required timeout is absent. + format!("https://relay.example/?jwt={secret}") + .encode(&mut body, version) + .unwrap(); + let mut malformed = Vec::new(); + (body.len() as u16).encode(&mut malformed, version).unwrap(); + malformed.extend_from_slice(&body); + assert!(ietf::GoAway::decode(&mut malformed.as_slice(), version).is_err()); + + assert!(logs_contain("encoding")); + assert!(logs_contain("decoded")); + assert!(logs_contain("SETUP diagnostics")); + assert!(logs_contain("GOAWAY diagnostics")); + assert!(!logs_contain(secret)); + let decimal = format!("{:?}", secret.as_bytes()); + assert!(!logs_contain(&decimal[1..decimal.len() - 1])); + } + /// Never emit a legacy SETUP our own receiver would refuse. #[test] fn encode_enforces_the_setup_limit() { diff --git a/rs/moq-net/tests/goaway.rs b/rs/moq-net/tests/goaway.rs index bc407c2a493..810ef0c90d6 100644 --- a/rs/moq-net/tests/goaway.rs +++ b/rs/moq-net/tests/goaway.rs @@ -38,7 +38,8 @@ const GOAWAY_VERSIONS: &[&str] = &[ /// Server drains with a redirect URI; the client observes it through /// `Session::draining()`. Exercises every GOAWAY channel in the version /// matrix, in both directions. -#[tokio::test] +#[tokio::test(start_paused = true)] +#[tracing_test::traced_test] async fn goaway_send_receive_all_versions() { for version in GOAWAY_VERSIONS { tokio::time::timeout(TEST_TIMEOUT, async { @@ -48,7 +49,7 @@ async fn goaway_send_receive_all_versions() { // Server -> client. pair.server .drain() - .send(Goaway::redirect("https://new.example.com")) + .send(Goaway::redirect("https://new.example.com/?jwt=redirect-secret")) .expect("send goaway"); let goaway = pair @@ -57,7 +58,11 @@ async fn goaway_send_receive_all_versions() { .recv() .await .expect("session closed before GOAWAY"); - assert_eq!(goaway.uri(), "https://new.example.com", "version {version}"); + assert_eq!( + goaway.uri(), + "https://new.example.com/?jwt=redirect-secret", + "version {version}" + ); assert!(pair.client.draining().peek().is_some(), "version {version}"); // No deadline was advertised. assert_eq!(goaway.timeout(), None, "version {version}"); @@ -78,6 +83,8 @@ async fn goaway_send_receive_all_versions() { .await .unwrap_or_else(|_| panic!("test timed out on {version} (likely a mock deadlock)")); } + assert!(logs_contain("received goaway")); + assert!(!logs_contain("redirect-secret")); } /// The IETF draft-17+ GOAWAY carries a timeout on the wire; the receiver @@ -229,14 +236,14 @@ async fn goaway_timeout_force_close_moq_transport_17() { .expect("test timed out (likely a mock deadlock)"); } -/// Regression: a duplicate GOAWAY (a protocol violation; a peer sends at most -/// one per session) is ignored rather than replacing the first payload, since -/// an observer may already be acting on the first URI. +/// A duplicate GOAWAY closes the session without replacing its first payload +/// or logging credentials from the replacement URI. /// /// The public API's drain claim only ever sends one GOAWAY per session, so the /// handshake is hand-rolled to keep a raw transport clone for injecting /// wire-level GOAWAY control streams. -#[tokio::test] +#[tokio::test(start_paused = true)] +#[tracing_test::traced_test] async fn duplicate_goaway_keeps_first_payload_moq_lite_04() { /// Open a raw lite Goaway control stream: /// `[ControlType::Goaway][message size][uri length][uri bytes]`. @@ -297,7 +304,7 @@ async fn duplicate_goaway_keeps_first_payload_moq_lite_04() { // Second GOAWAY: once the client has fully processed the stream, the // observed payload must still carry the FIRST URI. - let recv_b = send_goaway_raw(&mut server_raw, "bb").await; + let recv_b = send_goaway_raw(&mut server_raw, "https://relay.example/?jwt=duplicate-secret").await; wait_processed(recv_b).await; let goaway = client_session @@ -309,6 +316,8 @@ async fn duplicate_goaway_keeps_first_payload_moq_lite_04() { }) .await .expect("test timed out (likely a mock deadlock)"); + assert!(logs_contain("duplicate GOAWAY received")); + assert!(!logs_contain("duplicate-secret")); } /// After a received GOAWAY, new subscriptions are rejected with `GoingAway` diff --git a/rs/moq-relay/src/auth.rs b/rs/moq-relay/src/auth.rs index 1c659bae416..285a5da9652 100644 --- a/rs/moq-relay/src/auth.rs +++ b/rs/moq-relay/src/auth.rs @@ -559,7 +559,7 @@ impl Decider { // Nothing here can verify a token, so one is refused rather than ignored: // its holder expects it to count, and the public grant is not what it says. Self::Public(_) if presents_token(&admission.request) => { - tracing::debug!(path = %admission.request.path, "a token was presented to public rules"); + tracing::debug!(path = ?admission.request.path, "a token was presented to public rules"); admission.refuse(Error::Refused); } Self::Public(rules) => match rules.authorize(&admission.request.path) { @@ -570,7 +570,7 @@ impl Decider { // A path the rules don't reach is a refusal, never an outage a // client would retry. Err(err) => { - tracing::debug!(path = %admission.request.path, %err, "public rules refused"); + tracing::debug!(path = ?admission.request.path, ?err, "public rules refused"); admission.refuse(Error::Refused); } }, diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index d97cf7bdade..27db85d946f 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -49,11 +49,12 @@ pub struct Peer { } impl std::fmt::Debug for Peer { - /// Redact `token`: [`crate::Config::load`] traces the whole resolved config, + /// Redact credentials: [`crate::Config::load`] traces the whole resolved config, /// so a derived `Debug` would print cluster credentials into logs. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let url = peer_url(&self.url).ok(); f.debug_struct("Peer") - .field("url", &self.url) + .field("url", &url.as_ref().map(moq_tokio::RedactedUrl::new)) .field("cost", &self.cost) .field("egress", &self.egress) .field("token", &self.token.as_ref().map(|_| "...")) @@ -1140,7 +1141,7 @@ impl Cluster { origin = match origin.mount(token.root.join(at), target) { Ok(origin) => origin, Err(err) => { - tracing::warn!(root = %token.root, %at, %target, %err, "grant mount refused"); + tracing::warn!(root = ?token.root, ?at, ?target, ?err, "grant mount refused"); return None; } }; @@ -2556,13 +2557,20 @@ mod tests { /// credential from `Debug` instead of printing it into logs. #[test] fn peer_debug_redacts_token() { - let peer = Peer::new("https://peer.example/").with_cost(2).with_token("secret"); - let debug = format!("{peer:?}"); - assert!(!debug.contains("secret"), "Debug must not leak the credential: {debug}"); - assert!( - debug.contains("https://peer.example/"), - "Debug keeps the address: {debug}" - ); + for peer in [ + Peer::new("https://peer.example/").with_cost(2).with_token("secret"), + Peer::new("https://user:secret@peer.example/?jwt=secret#secret"), + Peer::new("https://peer.example:bad/?jwt=secret"), + ] { + let debug = format!("{peer:?}"); + assert!(!debug.contains("secret"), "Debug must not leak the credential: {debug}"); + if peer_url(peer.url()).is_ok() { + assert!( + debug.contains("https://peer.example/"), + "Debug keeps the address: {debug}" + ); + } + } } /// Static `--cluster-connect` entries get the same all-or-nothing diff --git a/rs/moq-relay/src/connection.rs b/rs/moq-relay/src/connection.rs index 9acaa58039f..6f7d7d7733c 100644 --- a/rs/moq-relay/src/connection.rs +++ b/rs/moq-relay/src/connection.rs @@ -221,18 +221,18 @@ pub(crate) fn authorize( }; if !authorized { let wanted = role.map_or("any", moq_net::Role::as_str); - anyhow::bail!("grant does not allow {wanted} access to {}", token.root); + anyhow::bail!("grant does not allow {wanted} access to {:?}", token.root); } match (&publish, &subscribe) { (Some(publish), Some(subscribe)) => { - tracing::info!(%transport, ?role, tier = %token.tier, root = %token.root, publish = %publish.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), subscribe = %subscribe.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), "session accepted"); + tracing::info!(%transport, ?role, tier = %token.tier, root = ?token.root, publish = %publish.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), subscribe = %subscribe.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), "session accepted"); } (Some(publish), None) => { - tracing::info!(%transport, ?role, tier = %token.tier, root = %token.root, publish = %publish.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), "publisher accepted"); + tracing::info!(%transport, ?role, tier = %token.tier, root = ?token.root, publish = %publish.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), "publisher accepted"); } (None, Some(subscribe)) => { - tracing::info!(%transport, ?role, tier = %token.tier, root = %token.root, subscribe = %subscribe.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), "subscriber accepted"); + tracing::info!(%transport, ?role, tier = %token.tier, root = ?token.root, subscribe = %subscribe.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), "subscriber accepted"); } _ => unreachable!("authorized above guarantees at least one origin"), } From 85d5fde553e5f45e4135e8bd875bc96c82ca850b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 31 Oct 2026 22:35:28 -0700 Subject: [PATCH 2/3] fix(relay): escape granted permission diagnostics Co-Authored-By: GPT-6.1 Sol --- rs/moq-relay/src/connection.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rs/moq-relay/src/connection.rs b/rs/moq-relay/src/connection.rs index 6f7d7d7733c..3adf5982060 100644 --- a/rs/moq-relay/src/connection.rs +++ b/rs/moq-relay/src/connection.rs @@ -226,13 +226,13 @@ pub(crate) fn authorize( match (&publish, &subscribe) { (Some(publish), Some(subscribe)) => { - tracing::info!(%transport, ?role, tier = %token.tier, root = ?token.root, publish = %publish.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), subscribe = %subscribe.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), "session accepted"); + tracing::info!(%transport, ?role, tier = %token.tier, root = ?token.root, publish = ?publish.allowed(), subscribe = ?subscribe.allowed(), "session accepted"); } (Some(publish), None) => { - tracing::info!(%transport, ?role, tier = %token.tier, root = ?token.root, publish = %publish.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), "publisher accepted"); + tracing::info!(%transport, ?role, tier = %token.tier, root = ?token.root, publish = ?publish.allowed(), "publisher accepted"); } (None, Some(subscribe)) => { - tracing::info!(%transport, ?role, tier = %token.tier, root = ?token.root, subscribe = %subscribe.allowed().iter().map(|pattern| pattern.as_str()).collect::>().join(","), "subscriber accepted"); + tracing::info!(%transport, ?role, tier = %token.tier, root = ?token.root, subscribe = ?subscribe.allowed(), "subscriber accepted"); } _ => unreachable!("authorized above guarantees at least one origin"), } From d6c66b961cba3058abf712c04dfd66070bedda3d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 18:58:22 -0800 Subject: [PATCH 3/3] fix: require redacting web-transport-proto and redact moq-uring CONNECT Debug web-transport-proto 0.6.4 redacts ConnectRequest's Debug (URL userinfo, query, fragment, and header values), which web-transport-moq and web-transport-iroh log. Raise the workspace minimum so release builds cannot resolve 0.6.3. moq-uring's Request Debug printed the raw url::Url, query included; it now delegates to the redacted ConnectRequest. Tests pin both. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- rs/moq-uring/src/quic/web.rs | 24 +++++++++++++++++++++++- rs/moq-uring/tests/web.rs | 5 +++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d00a47facc..8fb0ef090f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9895,9 +9895,9 @@ dependencies = [ [[package]] name = "web-transport-proto" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2baf87f7a4701d964fd23529b440db3da535b1d7539289f7a463c3481dafcff" +checksum = "40d8e5dba9b14dbe25b116ac7e62ca82bf7c328d1c6072238bf0b9b47874c9d1" dependencies = [ "bytes", "http", diff --git a/Cargo.toml b/Cargo.toml index d7103216a95..c971caa8f8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -238,7 +238,7 @@ web-transport-iroh = "0.7" # aws-lc-rs / ring features. # The WebTransport adapter released with moq-noq, from the same repository. web-transport-moq = { version = "1.3.5", default-features = false } -web-transport-proto = "0.6" +web-transport-proto = "0.6.4" web-transport-trait = "0.4" web-transport-wasm = "0.6" x11rb = { version = "0.14.0", features = ["randr", "xfixes"] } diff --git a/rs/moq-uring/src/quic/web.rs b/rs/moq-uring/src/quic/web.rs index d2ed8515842..dbca9e24ef8 100644 --- a/rs/moq-uring/src/quic/web.rs +++ b/rs/moq-uring/src/quic/web.rs @@ -384,9 +384,12 @@ impl Rejected { } } +/// Safe to log: [`proto::ConnectRequest`]'s `Debug` redacts the URL's +/// userinfo, query, and fragment and every header value but `origin` and +/// `user-agent`, so a `?jwt=` or `Authorization` credential stays out. impl std::fmt::Debug for Request { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Request").field("url", &self.request.url).finish() + f.debug_struct("Request").field("connect", &self.request).finish() } } @@ -1475,6 +1478,25 @@ mod tests { )); } + /// The CONNECT request is logged here and by the `web-transport-moq` and + /// `web-transport-iroh` transports, so its `Debug` must keep credentials + /// out: `web-transport-proto` redacts them from 0.6.4. + #[test] + fn connect_debug_redacts_credentials() { + let url = url::Url::parse("https://user:hunter2@relay.example/anon?jwt=SECRET#SECRET").unwrap(); + let request = proto::ConnectRequest::new(url) + .with_header( + http::header::AUTHORIZATION, + http::HeaderValue::from_static("Bearer SECRET"), + ) + .with_header(http::header::COOKIE, http::HeaderValue::from_static("session=SECRET")); + let debug = format!("{request:?}"); + assert!(debug.contains("relay.example/anon"), "{debug}"); + for secret in ["SECRET", "hunter2", "jwt="] { + assert!(!debug.contains(secret), "{secret} leaked: {debug}"); + } + } + /// Wrap `payload` in an HTTP/3 frame of type `typ`. fn frame(typ: u64, payload: &[u8]) -> Vec { let mut buf = Vec::new(); diff --git a/rs/moq-uring/tests/web.rs b/rs/moq-uring/tests/web.rs index 689e7ff6935..d2d74753ac7 100644 --- a/rs/moq-uring/tests/web.rs +++ b/rs/moq-uring/tests/web.rs @@ -152,6 +152,11 @@ fn webtransport_echo_end_to_end() { let request = quic::web::Request::accept(conn).await.expect("handshake"); assert_eq!(request.url().path(), "/echo"); assert_eq!(request.url().query(), Some("token=abc")); + let debug = format!("{request:?}"); + assert!( + debug.contains("/echo") && !debug.contains("token=abc"), + "query leaked: {debug}" + ); assert_eq!(request.protocols(), [PROTO.to_string()]); let mut session = request .respond(quic::web::Response::default().with_protocol(PROTO))