Skip to content

Conversation

@shadowsocks69420
Copy link
Contributor

ACL rules are likely not written for fake IPs.

One of the major selling point of using the fake-dns feature is to be able to make use of ACL rules that are based on domain names instead of purely IP addresses. Passing fake IPs to ACL nullifies this benefit, which is likely not expected from users.

Closes #2028

ACL rules are likely not written for fake IPs.

One of the major selling point of using the `fake-dns` feature is to be
able to make use of ACL rules that are based on domain names instead of
purely IP addresses. Passing fake IPs to ACL nullifies this benefit,
which is likely not expected from users.

Closes shadowsocks#2028
@shadowsocks69420
Copy link
Contributor Author

shadowsocks69420 commented Oct 11, 2025

Because I'm lacking thorough understanding of the codebase, I wasn't confident to remove the same mapping logic in the functions that immediately get called, as I'm worried that there might be other direct calls to these functions that expects it to map the fake-dns IPs.

/// Connect directly to target `addr`
pub async fn connect_bypassed_with_opts<A>(
context: Arc<ServiceContext>,
addr: A,
connect_opts: &ConnectOpts,
) -> io::Result<Self>
where
A: Into<Address>,
{
// Connect directly.
#[cfg_attr(not(feature = "local-fake-dns"), allow(unused_mut))]
let mut addr = addr.into();
#[cfg(feature = "local-fake-dns")]
if let Some(mapped_addr) = context.try_map_fake_address(&addr).await {
addr = mapped_addr;
}
let stream = TcpStream::connect_remote_with_opts(context.context_ref(), &addr, connect_opts).await?;
Ok(Self::Bypassed(stream))
}

/// Connect to target `addr` via shadowsocks' server configured by `svr_cfg`
pub async fn connect_proxied_with_opts<A>(
context: Arc<ServiceContext>,
server: &ServerIdent,
addr: A,
connect_opts: &ConnectOpts,
) -> io::Result<Self>
where
A: Into<Address>,
{
#[cfg_attr(not(feature = "local-fake-dns"), allow(unused_mut))]
let mut addr = addr.into();
#[cfg(feature = "local-fake-dns")]
if let Some(mapped_addr) = context.try_map_fake_address(&addr).await {
addr = mapped_addr;
}

Also, I did not remove the trace log as I think might be helpful for debugging purposes, I couldn't find other trace logs that provide the ACL decision.

@zonyitoo
Copy link
Collaborator

Why not make a private function like connect_bypassed_with_opts_impl to prevent mapping fake ips twice.

@zonyitoo zonyitoo merged commit e2ffb9c into shadowsocks:master Oct 12, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACL checks should based on associated domain when fake-dns is enabled

2 participants