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

fix(sslocal): disallow HTTP/SOCKS4 proxying when authentication required #1765

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
26 changes: 18 additions & 8 deletions crates/shadowsocks-service/src/local/socks/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,13 @@ impl SocksTcpHandler {
match version_buffer[0] {
#[cfg(feature = "local-socks4")]
0x04 => {
let handler = Socks4TcpHandler::new(self.context, self.balancer, self.mode);
handler.handle_socks4_client(self.stream, self.peer_addr).await
if self.socks5_auth.auth_required() {
error!("SOCKS4 disabled when authentication is configured");
Err(io::Error::new(ErrorKind::Other, "SOCKS4 unsupported"))
} else {
let handler = Socks4TcpHandler::new(self.context, self.balancer, self.mode);
handler.handle_socks4_client(self.stream, self.peer_addr).await
}
}

0x05 => {
Expand All @@ -193,12 +198,17 @@ impl SocksTcpHandler {

#[cfg(feature = "local-http")]
b'G' | b'g' | b'H' | b'h' | b'P' | b'p' | b'D' | b'd' | b'C' | b'c' | b'O' | b'o' | b'T' | b't' => {
// GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH
match self.http_handler.serve_connection(self.stream, self.peer_addr).await {
Ok(..) => Ok(()),
Err(err) => {
error!("HTTP connection {} handler failed with error: {}", self.peer_addr, err);
Err(io::Error::new(ErrorKind::Other, err))
if self.socks5_auth.auth_required() {
error!("HTTP disabled when authentication is configured");
Err(io::Error::new(ErrorKind::Other, "HTTP unsupported"))
} else {
// GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH
match self.http_handler.serve_connection(self.stream, self.peer_addr).await {
Ok(..) => Ok(()),
Err(err) => {
error!("HTTP connection {} handler failed with error: {}", self.peer_addr, err);
Err(io::Error::new(ErrorKind::Other, err))
}
}
}
}
Expand Down
Loading