Skip to content
Open
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
40 changes: 40 additions & 0 deletions proxy-lib-l4-macos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ fn flow_action(meta: &TransparentProxyFlowMeta) -> TransparentProxyFlowAction {
}

fn flow_action_tcp(meta: &TransparentProxyFlowMeta) -> TransparentProxyFlowAction {
if is_forti_startup_helper(meta) {
return TransparentProxyFlowAction::Passthrough;
}

tracing::debug!(
protocol = ?meta.protocol,
remote = ?meta.remote_endpoint,
Expand Down Expand Up @@ -200,6 +204,42 @@ fn is_ip_remote_host_passthrough(meta: &TransparentProxyFlowMeta) -> Option<Host
Some(target.clone())
}

fn is_forti_startup_helper(meta: &TransparentProxyFlowMeta) -> bool {
let matches_identifier = meta
.source_app_bundle_identifier
.as_deref()
.map(is_forti_startup_helper_identifier)
.unwrap_or_default()
|| meta
.source_app_signing_identifier
.as_deref()
.map(is_forti_startup_helper_identifier)
.unwrap_or_default();

if matches_identifier {
return true;
}

let Some(pid) = meta.source_app_pid else {
return false;
};

let Some(Some(path)) = (unsafe { apple_ne::process::pid_path(pid) }).ok() else {
return false;
};

let Ok(path) = path.into_os_string().into_string() else {
return false;
};

path.starts_with("/Library/Application Support/Fortinet/FortiClient/bin/")
&& (path.ends_with("/ztnafw") || path.ends_with("/epctrl") || path.ends_with("/fctupdate"))
Comment on lines +235 to +236
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final return uses a combined &&/|| expression; split into guard checks (check starts_with first, then return on ends_with cases) to clarify control flow.

Show fix
Suggested change
path.starts_with("/Library/Application Support/Fortinet/FortiClient/bin/")
&& (path.ends_with("/ztnafw") || path.ends_with("/epctrl") || path.ends_with("/fctupdate"))
if !path.starts_with("/Library/Application Support/Fortinet/FortiClient/bin/") {
return false;
}
path.ends_with("/ztnafw") || path.ends_with("/epctrl") || path.ends_with("/fctupdate")
Details

✨ AI Reasoning
​The function computes 'matches_identifier' and uses early returns for several failure cases, but ends with a compound boolean return that mixes starts_with and multiple ends_with checks. This creates a moderately complex final condition that would be easier to read if split into explicit guard clauses (e.g., early-return false when the path doesn't start with the prefix, then check ends_with variants). The problematic expression increases cognitive load compared to simple guard-style checks.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

}

fn is_forti_startup_helper_identifier(identifier: &str) -> bool {
any_starts_with_ignore_ascii_case(identifier, ["ztnafw", "epctrl2", "fctupdate"])
}

apple_ne::transparent_proxy_ffi! {
init = init,
config = proxy_config,
Expand Down
Loading