Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: sanitize all path on the user's proxy #946

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ utoipa = { workspace = true }
utoipa-swagger-ui = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
x509-parser = "0.14.0"
tower-sanitize-path = "0.1.2"

[dependencies.shuttle-common]
workspace = true
Expand Down
22 changes: 18 additions & 4 deletions gateway/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use opentelemetry_http::HeaderInjector;
use shuttle_common::backends::headers::XShuttleProject;
use tokio::sync::mpsc::Sender;
use tower::{Service, ServiceBuilder};
use tower_sanitize_path::SanitizePath;
use tracing::{debug_span, error, field, trace};
use tracing_opentelemetry::OpenTelemetrySpanExt;

Expand Down Expand Up @@ -84,6 +85,18 @@ impl<'r> AsResponderTo<&'r AddrStream> for UserProxy {
}
}

impl<S, R> AsResponderTo<R> for SanitizePath<S>
where
S: AsResponderTo<R> + Clone,
{
fn as_responder_to(&self, req: R) -> Self {
let responder = self.clone();
responder.inner().as_responder_to(req);

responder
}
}

impl UserProxy {
async fn proxy(
self,
Expand Down Expand Up @@ -300,12 +313,13 @@ impl UserServiceBuilder {
.user_binds_to
.expect("a socket address to bind to is required");

let user_proxy = UserProxy {
let user_proxy = SanitizePath::sanitize_paths(UserProxy {
gateway: service.clone(),
task_sender,
remote_addr: "127.0.0.1:80".parse().unwrap(),
public: public.clone(),
};
})
.into_make_service();

let bouncer = self.bouncer_binds_to.as_ref().map(|_| Bouncer {
gateway: service.clone(),
Expand Down Expand Up @@ -335,7 +349,7 @@ impl UserServiceBuilder {

let user_with_tls = axum_server::Server::bind(user_binds_to)
.acceptor(tls_acceptor)
.serve(user_proxy.into_make_service())
.serve(user_proxy)
.map(|handle| ("user proxy (with TLS)", handle))
.boxed();
futs.push(user_with_tls);
Expand All @@ -351,7 +365,7 @@ impl UserServiceBuilder {
}

let user_without_tls = axum_server::Server::bind(user_binds_to)
.serve(user_proxy.into_make_service())
.serve(user_proxy)
.map(|handle| ("user proxy (no TLS)", handle))
.boxed();
futs.push(user_without_tls);
Expand Down