Skip to content

Commit

Permalink
fix(console): accept only file://, http://, https:// URI (#486)
Browse files Browse the repository at this point in the history
Tokio console can connect to a console subscriber over HTTP or
(on UNIX) via a socket. However, no check was performed to
ensure that the server string matched the HTTP(S) or FILE protocols.
This was reported to lead to strange behavior (#401).

This change adds an explicit check on the URI scheme to ensure that
it is one of `http`, `https`, or `file`.

closes: #401

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Nov 3, 2023
1 parent 528a4ca commit 031bddd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions tokio-console/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,22 @@ impl Config {
self.retain_for.unwrap_or_default().0
}

pub(crate) fn target_addr(&self) -> Uri {
self.target_addr
pub(crate) fn target_addr(&self) -> color_eyre::Result<Uri> {
let target_addr = self
.target_addr
.as_ref()
.unwrap_or(&default_target_addr())
.clone()
.clone();
match target_addr.scheme_str() {
Some("file" | "http" | "https") => {}
_ => {
return Err(color_eyre::eyre::eyre!(
"invalid scheme for target address {:?}, must be one of 'file', 'http', or 'https'",
target_addr
))
}
}
Ok(target_addr)
}

pub(crate) fn add_issue_metadata(
Expand Down
2 changes: 1 addition & 1 deletion tokio-console/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() -> color_eyre::Result<()> {
None => {}
}

let target = args.target_addr();
let target = args.target_addr()?;
tracing::info!(?target, "using target addr");

let retain_for = args.retain_for();
Expand Down

0 comments on commit 031bddd

Please sign in to comment.