Compare commits

...

1 Commits

Author SHA1 Message Date
David Wiesen
292ce9580c fix(windows-sandbox): skip remote ports on protocol any 2026-04-17 18:21:19 -07:00

View File

@@ -317,14 +317,16 @@ fn configure_rule(rule: &INetFwRule3, spec: &BlockRuleSpec<'_>) -> Result<()> {
format!("SetRemoteAddresses failed: {err:?}"),
))
})?;
let remote_ports = spec.remote_ports.unwrap_or("*");
rule.SetRemotePorts(&BSTR::from(remote_ports))
.map_err(|err| {
anyhow::Error::new(SetupFailure::new(
SetupErrorCode::HelperFirewallRuleCreateOrAddFailed,
format!("SetRemotePorts failed: {err:?}"),
))
})?;
if protocol_supports_remote_ports(spec.protocol) {
let remote_ports = spec.remote_ports.unwrap_or("*");
rule.SetRemotePorts(&BSTR::from(remote_ports))
.map_err(|err| {
anyhow::Error::new(SetupFailure::new(
SetupErrorCode::HelperFirewallRuleCreateOrAddFailed,
format!("SetRemotePorts failed: {err:?}"),
))
})?;
}
rule.SetLocalUserAuthorizedList(&BSTR::from(spec.local_user_spec))
.map_err(|err| {
anyhow::Error::new(SetupFailure::new(
@@ -354,6 +356,10 @@ fn configure_rule(rule: &INetFwRule3, spec: &BlockRuleSpec<'_>) -> Result<()> {
Ok(())
}
fn protocol_supports_remote_ports(protocol: i32) -> bool {
protocol == NET_FW_IP_PROTOCOL_TCP.0 || protocol == NET_FW_IP_PROTOCOL_UDP.0
}
fn blocked_loopback_tcp_remote_ports(proxy_ports: &[u16]) -> Option<String> {
let mut allowed_ports = proxy_ports
.iter()
@@ -400,3 +406,15 @@ fn log_line(log: &mut File, msg: &str) -> Result<()> {
writeln!(log, "[{ts}] {msg}")?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn remote_ports_are_only_configured_for_tcp_and_udp_rules() {
assert!(protocol_supports_remote_ports(NET_FW_IP_PROTOCOL_TCP.0));
assert!(protocol_supports_remote_ports(NET_FW_IP_PROTOCOL_UDP.0));
assert!(!protocol_supports_remote_ports(NET_FW_IP_PROTOCOL_ANY.0));
}
}