Keep the channel password out of the text of an address no connector serves
Backends::connect handed an address that no plain connector serves to Connectors::connect, whose error names the whole address: "no connector for ts3server://host?port=9987&channelpassword=...". The text is shown to the user and may be logged, and a TeamSpeak link carries the channel password (and a voelin:// link a host pin) in its query and fragment. The registry now looks the connector up itself and cuts the address at ? and # in the text (without_query, which the "not a TeamSpeak server address" error of the TeamSpeak side uses too, so that one also loses a pin). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2d71903e8f
commit
080d8873bb
3 files changed
+26
-3
No files matched your search
@@ -208,7 +208,15 @@ impl Backends {
|
||||
if let Some(local) = self.locals.iter().find(|c| c.accepts(&scheme)) {
|
||||
return local.connect_local(params, ctx);
|
||||
}
|
||||
let connect = self.connectors.connect(params);
|
||||
// Not `Connectors::connect`, which names the whole address when none serves it:
|
||||
// the text is shown, and a TeamSpeak link carries a channel password.
|
||||
let Some(connector) = self.connectors.for_address(¶ms.address) else {
|
||||
let shown = without_query(¶ms.address).to_owned();
|
||||
return Box::pin(async move {
|
||||
Err(SessionError::Protocol(format!("no connector for {shown}")))
|
||||
});
|
||||
};
|
||||
let connect = connector.connect(params);
|
||||
Box::pin(async move {
|
||||
let connected = connect.await?;
|
||||
Ok(LocalConnected { connected, streams: None })
|
||||
@@ -216,6 +224,12 @@ impl Backends {
|
||||
}
|
||||
}
|
||||
|
||||
/// An address as it may be shown or logged: without its query and fragment,
|
||||
/// where a link keeps a channel password or a host pin.
|
||||
pub(crate) fn without_query(address: &str) -> &str {
|
||||
address.split(['?', '#']).next().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Refuses every host that asks to be trusted.
|
||||
struct RefuseUnknownHosts;
|
||||
|
||||
@@ -237,4 +251,11 @@ mod tests {
|
||||
assert_eq!(Backends::scheme("teamspeak://x"), "teamspeak");
|
||||
assert_eq!(Backends::scheme("voelin://host/i/code"), "voelin");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_address_is_shown_without_its_secrets() {
|
||||
assert_eq!(without_query("ts3server://h?port=1&channelpassword=hunter2"), "ts3server://h");
|
||||
assert_eq!(without_query("voelin://h/i/code#h=abcd"), "voelin://h/i/code");
|
||||
assert_eq!(without_query("host:9987"), "host:9987");
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,9 @@ mod session_link;
|
||||
mod tests;
|
||||
|
||||
pub use backends::Backends;
|
||||
pub(crate) use backends::{LocalConnected, LocalConnector, LocalCtx, StreamEvent, StreamPort};
|
||||
pub(crate) use backends::{
|
||||
LocalConnected, LocalConnector, LocalCtx, StreamEvent, StreamPort, without_query,
|
||||
};
|
||||
pub(crate) use session_link::SessionLink;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -148,7 +148,7 @@ fn inner_options(params: &ConnectParams, ctx: &LocalCtx) -> Result<ConnectOption
|
||||
Some(Link::Server(link)) => link,
|
||||
_ => {
|
||||
// Without the query: a channel password rides in it.
|
||||
let shown = params.address.split('?').next().unwrap_or_default();
|
||||
let shown = crate::link::without_query(¶ms.address);
|
||||
return Err(SessionError::Protocol(format!("not a TeamSpeak server address: {shown}")));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user