Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
feat(windows): localhost via proxy is now a per-rule option (replaces the global toggle)
AnoF-Cyber08c954dff9c4
diff --git a/Windows/README.md b/Windows/README.mdindex 4155b30..231553b 100644--- a/Windows/README.md+++ b/Windows/README.md@@ -151,7 +151,6 @@ ProxyBridge allows you to export selected rules to a `.pbprofile` JSON file and```json{"Version": "1.0",- "LocalhostViaProxy": false,"IsTrafficLoggingEnabled": true,"ProxyConfigs": [{@@ -179,6 +178,7 @@ ProxyBridge allows you to export selected rules to a `.pbprofile` JSON file and"Protocol": "TCP","Action": "PROXY","IsEnabled": true,+ "LocalhostViaProxy": false,"ProxyConfigId": 1},{@@ -188,6 +188,7 @@ ProxyBridge allows you to export selected rules to a `.pbprofile` JSON file and"Protocol": "BOTH","Action": "PROXY","IsEnabled": true,+ "LocalhostViaProxy": false,"ProxyConfigId": 2}]@@ -223,7 +224,7 @@ The CLI reads `.pbprofile` files exported directly from the GUI (**File → Expo|---|---|| `ProxyConfigs[]` | Array of proxy servers (SOCKS5 or HTTP, up to 16) || `ProxyRules[]` | Array of routing rules (up to 256) |-| `LocalhostViaProxy` | Whether to route `127.x.x.x` traffic through the proxy |+| `ProxyRules[].LocalhostViaProxy` | Per rule: also proxy `127.x.x.x` / `::1` traffic that matches this rule (default `false`) || `IsTrafficLoggingEnabled` | Enable/disable connection logging || `ProxyConfigId` | Per-rule proxy assignment (maps to `ProxyConfigs[].Id`) |@@ -298,12 +299,12 @@ Commands:## Things to Note-- **Localhost Traffic Handling**: Localhost traffic (`127.0.0.0/8` and IPv6 `::1`) requires special handling and is controlled by the **Localhost via Proxy** option in the Proxy menu (disabled by default):+- **Localhost Traffic Handling**: Localhost traffic (`127.0.0.0/8` and IPv6 `::1`) is handled **per rule** with the **Also proxy localhost traffic** checkbox in the rule editor (off by default):- **Default Behavior (Localhost via Proxy = Disabled):**- - ALL localhost traffic automatically uses direct connection- - Proxy rules matching `127.x.x.x` or `::1` addresses are automatically overridden to DIRECT- - This is the recommended setting for most users+ **Default Behavior (checkbox off):**+ - Connections to localhost that match the rule are sent directly, not through the proxy+ - Other traffic from the same application still follows the rule as usual+ - This is the recommended setting for most rules**Why localhost should stay local:**- **Security**: Most proxy servers reject localhost traffic to prevent SSRF (Server-Side Request Forgery) attacks@@ -314,13 +315,15 @@ Commands:- Inter-process communication (IPC) using TCP/UDP on `127.0.0.1`- **Routing Issues**: When localhost traffic goes to a remote proxy, the proxy server cannot reach services running on YOUR machine- **When to Enable Localhost via Proxy:**+ **When to tick "Also proxy localhost traffic" on a rule:**- ✅ Proxy server is running on the same machine (`127.0.0.1:1080`)- - ✅ Security testing: Intercepting localhost traffic in Burp Suite/InterceptSuite+ - ✅ Security testing: Intercepting that application's localhost traffic in Burp Suite/InterceptSuite- ✅ Your proxy is configured to handle localhost requests properly- - ❌ Do NOT enable if proxy is on a different machine/IP address+ - ❌ Do NOT tick it if the proxy is on a different machine/IP address- **CLI:** Controlled via the `LocalhostViaProxy` field in the `.pbprofile` file.+ Because the setting belongs to the rule, you can proxy localhost traffic for one application (for example your browser) while another (for example `curl.exe`) keeps its local connections direct.++ **CLI / profiles:** Controlled by the `LocalhostViaProxy` field of each rule in the `.pbprofile` file. Older profiles with a single global `LocalhostViaProxy` are still read; that value becomes the default for rules that have no setting of their own.- **Automatic Direct Routing**: Certain addresses and ports always bypass proxy rules and use direct connection to preserve network stability:diff --git a/Windows/cli/main.c b/Windows/cli/main.cindex 06611a8..8702296 100644--- a/Windows/cli/main.c+++ b/Windows/cli/main.c@@ -28,12 +28,11 @@ typedef uint32_t (*pfnAddProxyConfig)(int type, const char* ip, uint16_t port,typedef uint32_t (*pfnAddRule)(const char* process, const char* hosts,const char* ports, const char* domains,int protocol, int action,- uint32_t config_id);+ uint32_t config_id, int localhost_via_proxy);typedef int (*pfnDisableRule)(uint32_t rule_id);typedef void (*pfnSetLogCallback)(void (*cb)(const char*));typedef void (*pfnSetConnectionCallback)(void (*cb)(const char*, DWORD,const char*, uint16_t, const char*));-typedef void (*pfnSetLocalhostViaProxy)(int enable);typedef void (*pfnSetTrafficLogging)(int enable);typedef int (*pfnStart)(void);typedef int (*pfnStop)(void);@@ -43,7 +42,6 @@ static pfnAddRule g_AddRule = NULL;static pfnDisableRule g_DisableRule = NULL;static pfnSetLogCallback g_SetLog = NULL;static pfnSetConnectionCallback g_SetConn = NULL;-static pfnSetLocalhostViaProxy g_SetLocalhost = NULL;static pfnSetTrafficLogging g_SetTraffic = NULL;static pfnStart g_Start = NULL;static pfnStop g_Stop = NULL;@@ -69,10 +67,11 @@ typedef struct {int action; // 0=PROXY, 1=DIRECT, 2=BLOCKint is_enabled;uint32_t proxy_config_id; // maps to PBProxyConfig.profile_id+ int localhost_via_proxy; // 1 = localhost (127.x / ::1) traffic matching this rule is proxied too} PBRule;typedef struct {- int localhost_via_proxy;+ int localhost_via_proxy; // legacy global key; only the default for rules that lack their ownint traffic_logging;PBProxyConfig configs[MAX_PROXY_CONFIGS];int num_configs;@@ -476,6 +475,7 @@ static bool load_profile(const char* path, PBProfile* prof)else r->action = 0;r->is_enabled = jbool(buf, "IsEnabled", true) ? 1 : 0;+ r->localhost_via_proxy = jbool(buf, "LocalhostViaProxy", prof->localhost_via_proxy != 0) ? 1 : 0;r->proxy_config_id = (uint32_t)jint(buf, "ProxyConfigId", 0);free(buf);@@ -527,7 +527,6 @@ static bool load_dll(void)LOAD_FN(pfnDisableRule, g_DisableRule, "ProxyBridge_DisableRule");LOAD_FN(pfnSetLogCallback, g_SetLog, "ProxyBridge_SetLogCallback");LOAD_FN(pfnSetConnectionCallback, g_SetConn, "ProxyBridge_SetConnectionCallback");- LOAD_FN(pfnSetLocalhostViaProxy, g_SetLocalhost, "ProxyBridge_SetLocalhostViaProxy");LOAD_FN(pfnSetTrafficLogging, g_SetTraffic, "ProxyBridge_SetTrafficLoggingEnabled");LOAD_FN(pfnStart, g_Start, "ProxyBridge_Start");LOAD_FN(pfnStop, g_Stop, "ProxyBridge_Stop");@@ -961,7 +960,6 @@ int main(int argc, char* argv[])if (g_verbose != 0) outq_start();if (g_verbose == 1 || g_verbose == 3) g_SetLog(log_cb);if (g_verbose == 2 || g_verbose == 3) g_SetConn(conn_cb);- g_SetLocalhost(prof.localhost_via_proxy);g_SetTraffic(prof.traffic_logging);// ── Add proxy configs, map profile IDs to DLL-assigned IDs ───────────────@@ -1019,7 +1017,7 @@ int main(int argc, char* argv[])const char* domains = r->target_domains[0] ? r->target_domains : "*";uint32_t rid = g_AddRule(proc, hosts, ports, domains,- r->protocol, r->action, dll_cfg_id);+ r->protocol, r->action, dll_cfg_id, r->localhost_via_proxy);if (rid == 0){fprintf(stderr, " [%d] WARNING: Failed to add rule (%s)\n",diff --git a/Windows/gui/api/pb_api.h b/Windows/gui/api/pb_api.hindex e7a2f60..52f6c7e 100644--- a/Windows/gui/api/pb_api.h+++ b/Windows/gui/api/pb_api.h@@ -26,14 +26,13 @@ typedef BOOL (*PFN_DeleteProxyConfig)(UINT32);typedef int (*PFN_TestProxyConfig)(UINT32, const char*, unsigned short, char*, size_t);typedef void (*PBTestLogCallback)(const char* line, void* user);typedef int (*PFN_TestProxyConfigEx)(UINT32, const char*, unsigned short, PBTestLogCallback, void*);-typedef UINT32 (*PFN_AddRule)(const char*, const char*, const char*, const char*, PBRuleProtocol, PBRuleAction, UINT32);+typedef UINT32 (*PFN_AddRule)(const char*, const char*, const char*, const char*, PBRuleProtocol, PBRuleAction, UINT32, BOOL);typedef BOOL (*PFN_EnableRule)(UINT32);typedef BOOL (*PFN_DisableRule)(UINT32);typedef BOOL (*PFN_DeleteRule)(UINT32);-typedef BOOL (*PFN_EditRule)(UINT32, const char*, const char*, const char*, const char*, PBRuleProtocol, PBRuleAction, UINT32);+typedef BOOL (*PFN_EditRule)(UINT32, const char*, const char*, const char*, const char*, PBRuleProtocol, PBRuleAction, UINT32, BOOL);typedef BOOL (*PFN_MoveRuleToPosition)(UINT32, UINT32);typedef UINT32 (*PFN_GetRulePosition)(UINT32);-typedef void (*PFN_SetLocalhostViaProxy)(BOOL);typedef void (*PFN_SetLogCallback)(PBLogCallback);typedef void (*PFN_SetConnectionCallback)(PBConnectionCallback);typedef void (*PFN_SetTrafficLoggingEnabled)(BOOL);@@ -56,7 +55,6 @@ typedef struct {PFN_EditRule EditRule;PFN_MoveRuleToPosition MoveRuleToPosition;PFN_GetRulePosition GetRulePosition;- PFN_SetLocalhostViaProxy SetLocalhostViaProxy;PFN_SetLogCallback SetLogCallback;PFN_SetConnectionCallback SetConnectionCallback;PFN_SetTrafficLoggingEnabled SetTrafficLoggingEnabled;@@ -101,7 +99,6 @@ static BOOL PB_LoadDirect(PBApi* api)PB_BIND(EditRule, "EditRule");PB_BIND(MoveRuleToPosition, "MoveRuleToPosition");PB_BIND(GetRulePosition, "GetRulePosition");- PB_BIND(SetLocalhostViaProxy, "SetLocalhostViaProxy");PB_BIND(SetLogCallback, "SetLogCallback");PB_BIND(SetConnectionCallback, "SetConnectionCallback");PB_BIND(SetTrafficLoggingEnabled, "SetTrafficLoggingEnabled");diff --git a/Windows/gui/api/pb_ipc.h b/Windows/gui/api/pb_ipc.hindex 79d4807..8beeb41 100644--- a/Windows/gui/api/pb_ipc.h+++ b/Windows/gui/api/pb_ipc.h@@ -117,16 +117,15 @@ static int IpcTestProxyConfigEx(UINT32 id, const char* host, unsigned short portreturn rc;}-static UINT32 IpcAddRule(const char* proc, const char* hosts, const char* ports, const char* domains, PBRuleProtocol pr, PBRuleAction ac, UINT32 cfg)-{ PBIPC_BEGIN(PBOP_ADD_RULE); PbW_Str(&_w, proc); PbW_Str(&_w, hosts); PbW_Str(&_w, ports); PbW_Str(&_w, domains); PbW_U32(&_w, pr); PbW_U32(&_w, ac); PbW_U32(&_w, cfg); PBIPC_END(); }-static BOOL IpcEditRule(UINT32 id, const char* proc, const char* hosts, const char* ports, const char* domains, PBRuleProtocol pr, PBRuleAction ac, UINT32 cfg)-{ PBIPC_BEGIN(PBOP_EDIT_RULE); PbW_U32(&_w, id); PbW_Str(&_w, proc); PbW_Str(&_w, hosts); PbW_Str(&_w, ports); PbW_Str(&_w, domains); PbW_U32(&_w, pr); PbW_U32(&_w, ac); PbW_U32(&_w, cfg); PBIPC_END(); }+static UINT32 IpcAddRule(const char* proc, const char* hosts, const char* ports, const char* domains, PBRuleProtocol pr, PBRuleAction ac, UINT32 cfg, BOOL localhost)+{ PBIPC_BEGIN(PBOP_ADD_RULE); PbW_Str(&_w, proc); PbW_Str(&_w, hosts); PbW_Str(&_w, ports); PbW_Str(&_w, domains); PbW_U32(&_w, pr); PbW_U32(&_w, ac); PbW_U32(&_w, cfg); PbW_U32(&_w, localhost != 0); PBIPC_END(); }+static BOOL IpcEditRule(UINT32 id, const char* proc, const char* hosts, const char* ports, const char* domains, PBRuleProtocol pr, PBRuleAction ac, UINT32 cfg, BOOL localhost)+{ PBIPC_BEGIN(PBOP_EDIT_RULE); PbW_U32(&_w, id); PbW_Str(&_w, proc); PbW_Str(&_w, hosts); PbW_Str(&_w, ports); PbW_Str(&_w, domains); PbW_U32(&_w, pr); PbW_U32(&_w, ac); PbW_U32(&_w, cfg); PbW_U32(&_w, localhost != 0); PBIPC_END(); }static BOOL IpcEnableRule(UINT32 id) { PBIPC_BEGIN(PBOP_ENABLE_RULE); PbW_U32(&_w, id); PBIPC_END(); }static BOOL IpcDisableRule(UINT32 id) { PBIPC_BEGIN(PBOP_DISABLE_RULE); PbW_U32(&_w, id); PBIPC_END(); }static BOOL IpcDeleteRule(UINT32 id) { PBIPC_BEGIN(PBOP_DELETE_RULE); PbW_U32(&_w, id); PBIPC_END(); }static BOOL IpcMoveRule(UINT32 id, UINT32 pos) { PBIPC_BEGIN(PBOP_MOVE_RULE); PbW_U32(&_w, id); PbW_U32(&_w, pos); PBIPC_END(); }static UINT32 IpcGetRulePos(UINT32 id) { PBIPC_BEGIN(PBOP_GET_RULE_POS); PbW_U32(&_w, id); PBIPC_END(); }-static void IpcSetLocalhost(BOOL v) { PBIPC_BEGIN(PBOP_SET_LOCALHOST); PbW_U32(&_w, v != 0); PbIpcCall(_b, _w.len); }static void IpcSetTrafficLog(BOOL v) { PBIPC_BEGIN(PBOP_SET_TRAFFIC_LOG); PbW_U32(&_w, v != 0); PbIpcCall(_b, _w.len); }static void IpcClearConnLogs(void) { PBIPC_BEGIN(PBOP_CLEAR_CONN_LOGS); PbIpcCall(_b, _w.len); }static void IpcSetLogCallback(PBLogCallback cb) { g_ipcLogCb = cb; }@@ -243,7 +242,7 @@ static int PB_LoadService(PBApi* api)api->EnableRule = IpcEnableRule; api->DisableRule = IpcDisableRule;api->DeleteRule = IpcDeleteRule; api->EditRule = IpcEditRule;api->MoveRuleToPosition = IpcMoveRule; api->GetRulePosition = IpcGetRulePos;- api->SetLocalhostViaProxy = IpcSetLocalhost; api->SetLogCallback = IpcSetLogCallback;+ api->SetLogCallback = IpcSetLogCallback;api->SetConnectionCallback = IpcSetConnectionCallback;api->SetTrafficLoggingEnabled = IpcSetTrafficLog;api->ClearConnectionLogs = IpcClearConnLogs; api->Start = IpcStart; api->Stop = IpcStop;diff --git a/Windows/gui/loc/loc.h b/Windows/gui/loc/loc.hindex 06c99c6..77856df 100644--- a/Windows/gui/loc/loc.h+++ b/Windows/gui/loc/loc.h@@ -12,7 +12,7 @@enum {S_M_PROXY, S_M_PROXY_SETTINGS, S_M_PROXY_RULES,S_M_PROFILE, S_M_NEWPROFILE, S_M_DELPROFILE, S_M_IMPORT, S_M_EXPORT, S_M_SWITCH,- S_M_SETTINGS, S_M_LOCALHOST, S_M_TRAFFIC, S_M_TRAY, S_M_LANG, S_M_LANG_EN, S_M_LANG_ZH,+ S_M_SETTINGS, S_CHK_LOCALHOST, S_M_TRAFFIC, S_M_TRAY, S_M_LANG, S_M_LANG_EN, S_M_LANG_ZH,S_M_CLEARCONN, S_M_CLEARACT, S_M_HELP, S_M_ABOUT, S_M_DOCS, S_M_STARTUP,S_BTN_CLEARLOGS, S_SEARCH_CUE,S_TAB_CONN, S_TAB_ACT, S_TRAY_SHOW, S_TRAY_EXIT,@@ -29,7 +29,7 @@ enum {S_COL_ADDR, S_COL_TYPE, S_RULES_HINT,S_BTN_CHECK, S_TEST_OK, S_TEST_FAIL, S_TEST_TITLE,S_DLG_CHECKER, S_BTN_RETEST, S_TEST_RUNNING, S_CK_HOST, S_BTN_BROWSE,- S_EX_APPS, S_EX_HOSTS, S_EX_PORTS, S_EX_DOMAINS, S_UDP_NOTE,+ S_EX_APPS, S_EX_HOSTS, S_EX_PORTS, S_EX_DOMAINS, S_UDP_NOTE, S_EX_LOCALHOST,S_M_AUTOCLEAR, S_M_RENAME, S_M_LOGFILTERS, S_DLG_RENAME,S_DLG_FILTERS, S_DLG_FILTER, S_FL_DESC, S_L_MODE, S_L_PROC, S_L_IP,S_COL_MODE, S_COL_PROC, S_COL_IP, S_INFO_NORENAMEDEFAULT, S_ERR_RUNNING,@@ -54,7 +54,7 @@ static const wchar_t* const g_strings[S_COUNT][2] = {/* S_M_EXPORT */ { L"&Export Profile...", L"导出配置(&E)..." },/* S_M_SWITCH */ { L"&Switch Profile", L"切换配置(&S)" },/* S_M_SETTINGS */ { L"&Settings", L"设置(&S)" },- /* S_M_LOCALHOST */ { L"Localhost via Proxy", L"本地主机通过代理" },+ /* S_CHK_LOCALHOST */ { L"Also proxy localhost traffic", L"同时代理本地主机流量" },/* S_M_TRAFFIC */ { L"Enable Traffic Logging", L"启用流量日志" },/* S_M_TRAY */ { L"Close to Tray", L"关闭到系统托盘" },/* S_M_LANG */ { L"Language", L"语言" },@@ -154,6 +154,8 @@ static const wchar_t* const g_strings[S_COUNT][2] = {/* S_UDP_NOTE */ { L"\x26A0 UDP only works with SOCKS5 proxy. Not all SOCKS5 proxies support UDP by default. "L"SOCKS5 UDP support does not guarantee QUIC or HTTP/3 support, verify your proxy supports these protocols separately.",L"\x26A0 UDP 仅支持 SOCKS5 代理。并非所有 SOCKS5 代理默认支持 UDP。SOCKS5 UDP 支持并不保证支持 QUIC 或 HTTP/3 -- 请单独确认您的代理是否支持这些协议。" },+ /* S_EX_LOCALHOST */ { L"Off: this rule's connections to localhost (127.0.0.1, ::1) stay direct. On: they go through the proxy too (e.g. to intercept local traffic).",+ L"关闭: 此规则匹配的本地主机连接(127.0.0.1、::1)直连。开启: 同样通过代理(例如拦截本地流量)。" },/* S_M_AUTOCLEAR */ { L"Auto Clear Logs", L"自动清除日志" },/* S_M_RENAME */ { L"Rename Profile", L"重命名配置" },/* S_M_LOGFILTERS */ { L"Log Filters...", L"日志过滤器..." },diff --git a/Windows/gui/main.c b/Windows/gui/main.cindex d38d29c..7d73061 100644--- a/Windows/gui/main.c+++ b/Windows/gui/main.c@@ -125,7 +125,7 @@ static BOOL g_started = FALSE;static PBProfile g_profile;static wchar_t g_activeProfile[PB_NAME_MAX] = L"Default";-static BOOL g_localhost = FALSE, g_trafficLog = TRUE, g_closeToTray = TRUE;+static BOOL g_trafficLog = TRUE, g_closeToTray = TRUE;static BOOL g_startup = FALSE; // "Run at Startup" (schtasks logon task)static BOOL g_autoClear = TRUE; // auto-clear logs past a line threshold to save memory#define AUTO_CLEAR_LINES 500@@ -253,7 +253,7 @@ static void ApplyRules(void)W2Ux(r->ports, ports, sizeof(ports)); W2Ux(r->domains, domains, sizeof(domains));r->nativeId = g_api.AddRule(proc, hosts, ports, domains,(PBRuleProtocol)ProtoIdx(r->proto), (PBRuleAction)ActionIdx(r->action),- ResolveNativeCfg(r->cfgStoredId));+ ResolveNativeCfg(r->cfgStoredId), r->localhost != 0);if (r->nativeId && !r->enabled) g_api.DisableRule(r->nativeId);}}@@ -266,7 +266,7 @@ static UINT32 EngineAddRule(PBRule* r)W2Ux(r->ports, ports, sizeof(ports)); W2Ux(r->domains, domains, sizeof(domains));UINT32 id = g_api.AddRule(proc, hosts, ports, domains,(PBRuleProtocol)ProtoIdx(r->proto), (PBRuleAction)ActionIdx(r->action),- ResolveNativeCfg(r->cfgStoredId));+ ResolveNativeCfg(r->cfgStoredId), r->localhost != 0);if (id && !r->enabled) g_api.DisableRule(id);return id;}@@ -278,7 +278,7 @@ static void EngineEditRule(PBRule* r)W2Ux(r->ports, ports, sizeof(ports)); W2Ux(r->domains, domains, sizeof(domains));g_api.EditRule(r->nativeId, proc, hosts, ports, domains,(PBRuleProtocol)ProtoIdx(r->proto), (PBRuleAction)ActionIdx(r->action),- ResolveNativeCfg(r->cfgStoredId));+ ResolveNativeCfg(r->cfgStoredId), r->localhost != 0);if (r->enabled) g_api.EnableRule(r->nativeId); else g_api.DisableRule(r->nativeId);}@@ -294,13 +294,11 @@ static void SwitchToProfile(const wchar_t* name)PB_SetActiveProfile(name);lstrcpynW(g_activeProfile, name, PB_NAME_MAX);PB_ProfileLoad(name, &g_profile);- g_localhost = g_profile.localhostViaProxy;g_trafficLog = g_profile.trafficLogging;g_closeToTray = g_profile.closeToTray;g_autoClear = g_profile.autoClearLogs;if (g_profile.fontZoom != g_zoom) { g_zoom = g_profile.fontZoom; ApplyZoom(g_hMain); }ApplyFilterSnapshot();- g_api.SetLocalhostViaProxy(g_localhost);g_api.SetTrafficLoggingEnabled(g_trafficLog);ApplyConfigs();ApplyRules();@@ -354,7 +352,6 @@ static void BuildMainMenu(HWND hwnd)AppendTopMenu(bar, profile, T(S_M_PROFILE));HMENU settings = CreatePopupMenu();- AppendMenuW(settings, MF_STRING, IDM_SET_LOCALHOST, T(S_M_LOCALHOST));AppendMenuW(settings, MF_STRING, IDM_SET_TRAFFICLOG, T(S_M_TRAFFIC));AppendMenuW(settings, MF_STRING, IDM_SET_CLOSETOTRAY, T(S_M_TRAY));AppendMenuW(settings, MF_STRING, IDM_SET_STARTUP, T(S_M_STARTUP));@@ -537,7 +534,6 @@ static void SelectTab(int idx)static void SyncMenuChecks(HWND hwnd){HMENU m = GetMenu(hwnd);- CheckMenuItem(m, IDM_SET_LOCALHOST, MF_BYCOMMAND | (g_localhost ? MF_CHECKED : MF_UNCHECKED));CheckMenuItem(m, IDM_SET_TRAFFICLOG, MF_BYCOMMAND | (g_trafficLog ? MF_CHECKED : MF_UNCHECKED));CheckMenuItem(m, IDM_SET_CLOSETOTRAY, MF_BYCOMMAND | (g_closeToTray? MF_CHECKED : MF_UNCHECKED));CheckMenuItem(m, IDM_SET_STARTUP, MF_BYCOMMAND | (g_startup ? MF_CHECKED : MF_UNCHECKED));@@ -875,9 +871,6 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp){case IDM_PROXY_SETTINGS: DialogBoxW(g_hInst, MAKEINTRESOURCEW(IDD_SERVERS), hwnd, ServersDlgProc); return 0;case IDM_PROXY_RULES: DialogBoxW(g_hInst, MAKEINTRESOURCEW(IDD_RULES), hwnd, RulesDlgProc); return 0;- case IDM_SET_LOCALHOST:- g_localhost = !g_localhost; g_profile.localhostViaProxy = g_localhost;- g_api.SetLocalhostViaProxy(g_localhost); SaveActive(); SyncMenuChecks(hwnd); return 0;case IDM_SET_TRAFFICLOG:g_trafficLog = !g_trafficLog; g_profile.trafficLogging = g_trafficLog;g_api.SetTrafficLoggingEnabled(g_trafficLog); SaveActive(); SyncMenuChecks(hwnd); return 0;@@ -1093,7 +1086,6 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, PWSTR cmd, int show)// Load the active profile.PB_GetActiveProfile(g_activeProfile, PB_NAME_MAX);PB_ProfileLoad(g_activeProfile, &g_profile);- g_localhost = g_profile.localhostViaProxy;g_trafficLog = g_profile.trafficLogging;g_closeToTray = g_profile.closeToTray;g_zoom = g_profile.fontZoom;@@ -1168,7 +1160,6 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, PWSTR cmd, int show)// Wire callbacks + toggles, add configs (before Start so the UDP relay starts), start,// then add rules.- g_api.SetLocalhostViaProxy(g_localhost);g_api.SetTrafficLoggingEnabled(g_trafficLog);g_api.SetLogCallback(PBLogCb);g_api.SetConnectionCallback(PBConnCb);diff --git a/Windows/gui/profile/profile.c b/Windows/gui/profile/profile.cindex 930208b..92a35c5 100644--- a/Windows/gui/profile/profile.c+++ b/Windows/gui/profile/profile.c@@ -144,7 +144,6 @@ void PB_ProfileDefaults(PBProfile* p, const wchar_t* name){(void)name;ZeroMemory(p, sizeof(*p));- p->localhostViaProxy = 0;p->trafficLogging = 1;p->autoClearLogs = 1;p->closeToTray = 1;@@ -186,7 +185,9 @@ void PB_ProfileLoad(const wchar_t* name, PBProfile* p)JVal* root = json_parse(txt, len);if (root && root->type == J_OBJ){- p->localhostViaProxy = json_bool(root, "LocalhostViaProxy", 0);+ // Older profiles had one global "LocalhostViaProxy"; it is now per rule. Use the old value as+ // each rule's default so an upgraded profile keeps behaving the same.+ int oldGlobalLocalhost = json_bool(root, "LocalhostViaProxy", 0);p->trafficLogging = json_bool(root, "IsTrafficLoggingEnabled", 1);p->autoClearLogs = json_bool(root, "AutoClearConnectionLogs", 1);p->closeToTray = json_bool(root, "CloseToTray", 1);@@ -225,6 +226,7 @@ void PB_ProfileLoad(const wchar_t* name, PBProfile* p)u2w(json_str(r, "Protocol", "TCP"), ru->proto, 8);u2w(json_str(r, "Action", "PROXY"), ru->action, 16);ru->enabled = json_bool(r, "IsEnabled", 1);+ ru->localhost = json_bool(r, "LocalhostViaProxy", oldGlobalLocalhost);ru->cfgStoredId = (UINT32)json_long(r, "ProxyConfigId", 0);}@@ -263,7 +265,6 @@ BOOL PB_ProfileSave(const wchar_t* name, const PBProfile* p)sb_put(&b, "{\n");sb_put(&b, " \"Version\": \"1.0\",\n");put_kv_str(&b, " ", "Name", name, ",\n");- sb_put(&b, " \"LocalhostViaProxy\": "); sb_put(&b, p->localhostViaProxy ? "true" : "false"); sb_put(&b, ",\n");sb_put(&b, " \"IsTrafficLoggingEnabled\": "); sb_put(&b, p->trafficLogging ? "true" : "false"); sb_put(&b, ",\n");sb_put(&b, " \"AutoClearConnectionLogs\": "); sb_put(&b, p->autoClearLogs ? "true" : "false"); sb_put(&b, ",\n");put_kv_str(&b, " ", "Language", p->language, ",\n");@@ -302,6 +303,7 @@ BOOL PB_ProfileSave(const wchar_t* name, const PBProfile* p)put_kv_str(&b, " ", "Protocol", r->proto, ",\n");put_kv_str(&b, " ", "Action", r->action, ",\n");sb_put(&b, " \"IsEnabled\": "); sb_put(&b, r->enabled ? "true" : "false"); sb_put(&b, ",\n");+ sb_put(&b, " \"LocalhostViaProxy\": "); sb_put(&b, r->localhost ? "true" : "false"); sb_put(&b, ",\n");snprintf(tmp, sizeof(tmp), "%u", r->cfgStoredId);sb_put(&b, " \"ProxyConfigId\": "); sb_put(&b, tmp); sb_put(&b, "\n");sb_put(&b, " }");diff --git a/Windows/gui/profile/profile.h b/Windows/gui/profile/profile.hindex a4d2605..171a270 100644--- a/Windows/gui/profile/profile.h+++ b/Windows/gui/profile/profile.h@@ -39,6 +39,7 @@ typedef struct {wchar_t proto[8]; // "TCP" | "UDP" | "BOTH"wchar_t action[16]; // "PROXY" | "DIRECT" | "BLOCK"int enabled;+ int localhost; // 1 = connections to localhost (127.x / ::1) matching this rule are proxied tooUINT32 cfgStoredId; // ProxyConfigId as written in the profile} PBRule;@@ -53,7 +54,6 @@ typedef struct PBProfile PBProfile;UINT32 PB_AllocConfigId(PBProfile* p);typedef struct PBProfile {- int localhostViaProxy;int trafficLogging;int autoClearLogs;int closeToTray;diff --git a/Windows/gui/res/app.rc b/Windows/gui/res/app.rcindex 7ea904c..94343c4 100644--- a/Windows/gui/res/app.rc+++ b/Windows/gui/res/app.rc@@ -153,6 +153,9 @@ BEGINLTEXT "Action:", IDC_RE_L_ACTION, 8, 214, 80, 10COMBOBOX IDC_RE_ACTION, 92, 212, 380,160, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP+ AUTOCHECKBOX "Also proxy localhost traffic", IDC_RE_LOCALHOST, 92, 234, 380, 10+ LTEXT "", IDC_RE_EX_LOCAL, 92, 247, 380, 20+DEFPUSHBUTTON "OK", IDOK, 362, 272, 52, 14PUSHBUTTON "Cancel", IDCANCEL, 418, 272, 52, 14ENDdiff --git a/Windows/gui/res/resource.h b/Windows/gui/res/resource.hindex a4a12d1..eb726de 100644--- a/Windows/gui/res/resource.h+++ b/Windows/gui/res/resource.h@@ -18,7 +18,6 @@#define IDR_MAINMENU 200#define IDM_PROXY_SETTINGS 201#define IDM_PROXY_RULES 202-#define IDM_SET_LOCALHOST 210#define IDM_SET_TRAFFICLOG 211#define IDM_SET_CLOSETOTRAY 212#define IDM_SET_STARTUP 215@@ -134,6 +133,8 @@#define IDC_RE_UDPNOTE 441#define IDC_RE_NAME 442 // friendly name edit#define IDC_RE_L_NAME 443 // "Name:" label+#define IDC_RE_LOCALHOST 444 // "also proxy localhost" checkbox+#define IDC_RE_EX_LOCAL 445 // its hint text// Name-input dialog (new profile)#define IDD_NAME 500diff --git a/Windows/gui/ui/dialogs.h b/Windows/gui/ui/dialogs.hindex 59ad73a..b8159dc 100644--- a/Windows/gui/ui/dialogs.h+++ b/Windows/gui/ui/dialogs.h@@ -442,6 +442,17 @@ static void AppendApp(wchar_t* out, int cap, const wchar_t* name)// Edit sub-dialog. lParam is a PBRule* seeded with current values; on OK it is written back// (name/proc/hosts/ports/domains/proto/action/cfgStoredId/enabled) and the dialog returns 1.+// "Also proxy localhost traffic" only means something for a PROXY rule (DIRECT / BLOCK never+// send traffic to a proxy), so show it only while the Action list has a proxy selected.+// Action list: 0 = Direct, 1 = Block, 2.. = one entry per proxy server.+static void RuleSyncLocalhostVisibility(HWND dlg)+{+ int asel = (int)SendMessageW(GetDlgItem(dlg, IDC_RE_ACTION), CB_GETCURSEL, 0, 0);+ int show = (asel >= 2) ? SW_SHOW : SW_HIDE;+ ShowWindow(GetDlgItem(dlg, IDC_RE_LOCALHOST), show);+ ShowWindow(GetDlgItem(dlg, IDC_RE_EX_LOCAL), show);+}+INT_PTR CALLBACK RuleEditDlgProc(HWND dlg, UINT msg, WPARAM wp, LPARAM lp){switch (msg)@@ -465,6 +476,8 @@ INT_PTR CALLBACK RuleEditDlgProc(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)SetDlgItemTextW(dlg, IDC_RE_EX_PORTS, T(S_EX_PORTS));SetDlgItemTextW(dlg, IDC_RE_EX_DOMAINS, T(S_EX_DOMAINS));SetDlgItemTextW(dlg, IDC_RE_UDPNOTE, T(S_UDP_NOTE));+ SetDlgItemTextW(dlg, IDC_RE_LOCALHOST, T(S_CHK_LOCALHOST));+ SetDlgItemTextW(dlg, IDC_RE_EX_LOCAL, T(S_EX_LOCALHOST));SetDlgItemTextW(dlg, IDOK, T(S_BTN_OK));SetDlgItemTextW(dlg, IDCANCEL, T(S_BTN_CANCEL));HWND pr = GetDlgItem(dlg, IDC_RE_PROTO);@@ -504,6 +517,8 @@ INT_PTR CALLBACK RuleEditDlgProc(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)}SendMessageW(ac, CB_SETCURSEL, target, 0);CheckDlgButton(dlg, IDC_RE_ENABLED, r->enabled ? BST_CHECKED : BST_UNCHECKED);+ CheckDlgButton(dlg, IDC_RE_LOCALHOST, r->localhost ? BST_CHECKED : BST_UNCHECKED);+ RuleSyncLocalhostVisibility(dlg);InitDarkMode(dlg);return TRUE;}@@ -519,13 +534,16 @@ INT_PTR CALLBACK RuleEditDlgProc(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)SetBkColor(dc, C_BG);if (id == IDC_RE_UDPNOTE) SetTextColor(dc, C_WARN);else if (id == IDC_RE_EX_APPS || id == IDC_RE_EX_HOSTS ||- id == IDC_RE_EX_PORTS || id == IDC_RE_EX_DOMAINS) SetTextColor(dc, C_DIM);+ id == IDC_RE_EX_PORTS || id == IDC_RE_EX_DOMAINS || id == IDC_RE_EX_LOCAL) SetTextColor(dc, C_DIM);else SetTextColor(dc, C_TEXT);return (INT_PTR)g_brBg;}case WM_COMMAND:switch (LOWORD(wp)){+ case IDC_RE_ACTION:+ if (HIWORD(wp) == CBN_SELCHANGE) RuleSyncLocalhostVisibility(dlg);+ return TRUE;case IDC_RE_BROWSE:{// Pick one or more .exe files and append each file name to the list.@@ -586,6 +604,7 @@ INT_PTR CALLBACK RuleEditDlgProc(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)else { lstrcpynW(r->action, L"PROXY", 16);r->cfgStoredId = (UINT32)SendMessageW(ac, CB_GETITEMDATA, asel, 0); }r->enabled = (IsDlgButtonChecked(dlg, IDC_RE_ENABLED) == BST_CHECKED) ? 1 : 0;+ r->localhost = (asel >= 2 && IsDlgButtonChecked(dlg, IDC_RE_LOCALHOST) == BST_CHECKED) ? 1 : 0; // only for PROXY rulesEndDialog(dlg, 1);return TRUE;}diff --git a/Windows/src/ProxyBridge.c b/Windows/src/ProxyBridge.cindex 48e8bc9..48e5115 100644--- a/Windows/src/ProxyBridge.c+++ b/Windows/src/ProxyBridge.c@@ -71,7 +71,6 @@ volatile LONG port_decided_bitmap[2048] = {0}; // 8 KBvolatile LONG port_direct_bitmap[2048] = {0}; // 8 KBUINT16 g_local_relay_port = LOCAL_PROXY_PORT;-BOOL g_localhost_via_proxy = FALSE; // default disabled for security - most proxy server block localhost for ssrf and also many app might not work if localhost trafic goes to remote server if proxy server is on diffrent machineLogCallback g_log_callback = NULL;ConnectionCallback g_connection_callback = NULL;@@ -267,7 +266,7 @@ DWORD WINAPI packet_processor(LPVOID arg)if (action6u == RULE_ACTION_DIRECT && pid6u > 0)udp_direct_remember(TRUE, ipv6_header->DstAddr, sp, dp);- if (action6u == RULE_ACTION_PROXY && !g_localhost_via_proxy)+ if (action6u == RULE_ACTION_PROXY && !g_tl_rule_localhost){const UINT8 *d6=(const UINT8*)ipv6_header->DstAddr;static const UINT8 lb6[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};@@ -464,8 +463,8 @@ DWORD WINAPI packet_processor(LPVOID arg)UINT32 proxy_config_id6 = 0;action6 = check_process_rule_v6((const UINT8*)ipv6_header->SrcAddr, sp, (const UINT8*)ipv6_header->DstAddr, dp, FALSE, &pid6, &proxy_config_id6);- // ::1 IPv6 loopback - use same "Localhost via Proxy" toggle as IPv4 127.- if (action6 == RULE_ACTION_PROXY && !g_localhost_via_proxy)+ // ::1 IPv6 loopback - same per-rule "localhost via proxy" flag as IPv4 127.+ if (action6 == RULE_ACTION_PROXY && !g_tl_rule_localhost){const UINT8 *dst6 = (const UINT8*)ipv6_header->DstAddr;// check for ::1 (loopback) or ::ffff:127.x.x.x (v4-mapped loopback)@@ -656,9 +655,9 @@ DWORD WINAPI packet_processor(LPVOID arg)if (action == RULE_ACTION_DIRECT && pid > 0)udp_direct_remember(FALSE, &dest_ip, src_port, dest_port);- // override PROXY to DIRECT if localhost proxy is disabled and destination is localhost+ // override PROXY to DIRECT when the matched rule does not allow localhost and the destination is localhostBYTE dest_first_octet = (dest_ip >> 0) & 0xFF;- if (action == RULE_ACTION_PROXY && !g_localhost_via_proxy && dest_first_octet == 127)+ if (action == RULE_ACTION_PROXY && !g_tl_rule_localhost && dest_first_octet == 127)action = RULE_ACTION_DIRECT;// Override PROXY to DIRECT for critical IPs and ports@@ -915,7 +914,7 @@ DWORD WINAPI packet_processor(LPVOID arg)action = check_process_rule(src_ip, src_port, orig_dest_ip, orig_dest_port, FALSE, &pid, &proxy_config_id);BYTE orig_dest_first_octet = (orig_dest_ip >> 0) & 0xFF;- if (action == RULE_ACTION_PROXY && !g_localhost_via_proxy && orig_dest_first_octet == 127)+ if (action == RULE_ACTION_PROXY && !g_tl_rule_localhost && orig_dest_first_octet == 127)action = RULE_ACTION_DIRECT;// Override PROXY to DIRECT for criticl ips@@ -1036,12 +1035,6 @@ DWORD WINAPI packet_processor(LPVOID arg)return 0;}-PROXYBRIDGE_API void ProxyBridge_SetLocalhostViaProxy(BOOL enable)-{- g_localhost_via_proxy = enable;- log_message("Localhost routing: %s (most proxies block localhost for SSRF prevention)", enable ? "via proxy" : "direct");-}-PROXYBRIDGE_API void ProxyBridge_SetLogCallback(LogCallback callback){g_log_callback = callback;diff --git a/Windows/src/ProxyBridge.h b/Windows/src/ProxyBridge.hindex 2d40db6..2ba289e 100644--- a/Windows/src/ProxyBridge.h+++ b/Windows/src/ProxyBridge.h@@ -50,16 +50,17 @@ typedef void (*ProxyTestLogCallback)(const char* line, void* user);PROXYBRIDGE_API int ProxyBridge_TestProxyConfigEx(UINT32 config_id, const char* target_host, UINT16 target_port, ProxyTestLogCallback callback, void* user);// Rule management - proxy_config_id selects which proxy config the rule uses (0 = first available)+// localhost_via_proxy: per rule. TRUE = connections to localhost (127.x / ::1) that match this rule are proxied;+// FALSE = they are sent direct (most proxies refuse localhost, and it never reaches a remote proxy's own machine).// target_domains: semicolon/comma separated domain patterns ("*", "google.com", "*.google.com"); NULL/"" = no domain restriction.// Domain matching relies on DNS snooping of the app's own resolutions; unencrypted DNS only (DoH/DoT bypasses it).-PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id);+PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id, BOOL localhost_via_proxy);PROXYBRIDGE_API BOOL ProxyBridge_EnableRule(UINT32 rule_id);PROXYBRIDGE_API BOOL ProxyBridge_DisableRule(UINT32 rule_id);PROXYBRIDGE_API BOOL ProxyBridge_DeleteRule(UINT32 rule_id);-PROXYBRIDGE_API BOOL ProxyBridge_EditRule(UINT32 rule_id, const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id);+PROXYBRIDGE_API BOOL ProxyBridge_EditRule(UINT32 rule_id, const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id, BOOL localhost_via_proxy);PROXYBRIDGE_API BOOL ProxyBridge_MoveRuleToPosition(UINT32 rule_id, UINT32 new_position); // Move rule to specific position (1=first, 2=second, etc)PROXYBRIDGE_API UINT32 ProxyBridge_GetRulePosition(UINT32 rule_id); // Get current position of rule in list (1-based)-PROXYBRIDGE_API void ProxyBridge_SetLocalhostViaProxy(BOOL enable);PROXYBRIDGE_API void ProxyBridge_SetLogCallback(LogCallback callback);PROXYBRIDGE_API void ProxyBridge_SetConnectionCallback(ConnectionCallback callback);PROXYBRIDGE_API void ProxyBridge_SetTrafficLoggingEnabled(BOOL enable);diff --git a/Windows/src/pb_internal.h b/Windows/src/pb_internal.hindex ff9f7cf..da1262c 100644--- a/Windows/src/pb_internal.h+++ b/Windows/src/pb_internal.h@@ -53,6 +53,7 @@ typedef struct PROCESS_RULE {RuleProtocol protocol; // TCP, UDP, or BOTHRuleAction action;UINT32 proxy_config_id; // Which proxy config to route this rule through (0 = first available)+ BOOL localhost_via_proxy; // TRUE: connections to localhost (127.x / ::1) that match this rule are proxied; FALSE: they go directBOOL enabled;struct PROCESS_RULE *next;} PROCESS_RULE;@@ -207,7 +208,9 @@ extern SRWLOCK g_dns_cache_lock;extern volatile LONG port_decided_bitmap[2048]; // 8 KBextern volatile LONG port_direct_bitmap[2048]; // 8 KBextern UINT16 g_local_relay_port;-extern BOOL g_localhost_via_proxy; // default disabled for security - most proxy server block localhost for ssrf and also many app might not work if localhost trafic goes to remote server if proxy server is on diffrent machine+// Set by match_rule*_inner on the calling thread: the "localhost via proxy" flag of the rule that+// produced the last verdict (FALSE when nothing matched). Read right after check_process_rule*().+extern __declspec(thread) BOOL g_tl_rule_localhost;extern LogCallback g_log_callback;extern ConnectionCallback g_connection_callback;extern char *g_pidtbl_buf;diff --git a/Windows/src/pb_rules.c b/Windows/src/pb_rules.cindex e6aa78b..60701dc 100644--- a/Windows/src/pb_rules.c+++ b/Windows/src/pb_rules.c@@ -38,8 +38,11 @@ static DWORD retry_tcp_pid(DWORD pid, BOOL ipv6, UINT32 src_ip, const UINT8 *srcreturn pid;}+__declspec(thread) BOOL g_tl_rule_localhost = FALSE;+RuleAction check_process_rule_v6(const UINT8 src_ip6[16], UINT16 src_port, const UINT8 dest_ip6[16], UINT16 dest_port, BOOL is_udp, DWORD *out_pid, UINT32 *out_proxy_config_id){+ g_tl_rule_localhost = FALSE;DWORD pid;char process_name[MAX_PROCESS_NAME];@@ -588,6 +591,7 @@ RuleAction match_rule_inner(const char *process_name, UINT32 dest_ip, UINT16 desmatch_domain_filter(rule, dst_domain)){// Matched! Return this rule's action+ g_tl_rule_localhost = rule->localhost_via_proxy;if (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;return rule->action;}@@ -614,7 +618,8 @@ RuleAction match_rule_inner(const char *process_name, UINT32 dest_ip, UINT16 desmatch_domain_filter(rule, dst_domain)){// All filters matched! Return this rule's action- if (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;+ g_tl_rule_localhost = rule->localhost_via_proxy;+ if (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;return rule->action;}}@@ -625,11 +630,13 @@ RuleAction match_rule_inner(const char *process_name, UINT32 dest_ip, UINT16 des// No specific rule matched, use wildcard if availableif (wildcard_rule != NULL){+ g_tl_rule_localhost = wildcard_rule->localhost_via_proxy;if (out_proxy_config_id != NULL) *out_proxy_config_id = wildcard_rule->proxy_config_id;return wildcard_rule->action;}// No rule matched at all+ g_tl_rule_localhost = FALSE;if (out_proxy_config_id != NULL) *out_proxy_config_id = 0;return RULE_ACTION_DIRECT;}@@ -688,6 +695,7 @@ RuleAction match_rule_v6_inner(const char *process_name, const UINT8 dest_ip6[16match_port_list(rule->target_ports, dest_port) &&match_domain_filter(rule, dst_domain)){+ g_tl_rule_localhost = rule->localhost_via_proxy;if (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;return rule->action;}@@ -707,7 +715,8 @@ RuleAction match_rule_v6_inner(const char *process_name, const UINT8 dest_ip6[16match_port_list(rule->target_ports, dest_port) &&match_domain_filter(rule, dst_domain)){- if (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;+ g_tl_rule_localhost = rule->localhost_via_proxy;+ if (out_proxy_config_id != NULL) *out_proxy_config_id = rule->proxy_config_id;return rule->action;}}@@ -717,10 +726,12 @@ RuleAction match_rule_v6_inner(const char *process_name, const UINT8 dest_ip6[16if (wildcard_rule != NULL){+ g_tl_rule_localhost = wildcard_rule->localhost_via_proxy;if (out_proxy_config_id != NULL) *out_proxy_config_id = wildcard_rule->proxy_config_id;return wildcard_rule->action;}+ g_tl_rule_localhost = FALSE;if (out_proxy_config_id != NULL) *out_proxy_config_id = 0;return RULE_ACTION_DIRECT;}@@ -735,6 +746,7 @@ RuleAction match_rule_v6(const char *process_name, const UINT8 dest_ip6[16], UINRuleAction check_process_rule(UINT32 src_ip, UINT16 src_port, UINT32 dest_ip, UINT16 dest_port, BOOL is_udp, DWORD *out_pid, UINT32 *out_proxy_config_id){+ g_tl_rule_localhost = FALSE;DWORD pid;char process_name[MAX_PROCESS_NAME];@@ -780,7 +792,7 @@ RuleAction check_process_rule(UINT32 src_ip, UINT16 src_port, UINT32 dest_ip, UIreturn action;}-PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id)+PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id, BOOL localhost_via_proxy){if (process_name == NULL || process_name[0] == '\0')return 0;@@ -793,6 +805,7 @@ PROXYBRIDGE_API UINT32 ProxyBridge_AddRule(const char* process_name, const char*strncpy_s(rule->process_name, MAX_PROCESS_NAME, process_name, _TRUNCATE);rule->protocol = protocol;rule->proxy_config_id = proxy_config_id;+ rule->localhost_via_proxy = localhost_via_proxy;rule->target_hosts = NULL;rule->target_ports = NULL;rule->target_domains = NULL;@@ -1000,7 +1013,7 @@ PROXYBRIDGE_API BOOL ProxyBridge_DeleteRule(UINT32 rule_id)return found;}-PROXYBRIDGE_API BOOL ProxyBridge_EditRule(UINT32 rule_id, const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id)+PROXYBRIDGE_API BOOL ProxyBridge_EditRule(UINT32 rule_id, const char* process_name, const char* target_hosts, const char* target_ports, const char* target_domains, RuleProtocol protocol, RuleAction action, UINT32 proxy_config_id, BOOL localhost_via_proxy){if (rule_id == 0 || process_name == NULL || target_hosts == NULL || target_ports == NULL)return FALSE;@@ -1040,6 +1053,7 @@ PROXYBRIDGE_API BOOL ProxyBridge_EditRule(UINT32 rule_id, const char* process_narule->protocol = protocol;rule->action = action;rule->proxy_config_id = proxy_config_id;+ rule->localhost_via_proxy = localhost_via_proxy;found = TRUE;break;}diff --git a/Windows/src/service/pb_proto.h b/Windows/src/service/pb_proto.hindex 5b6a809..619e4ef 100644--- a/Windows/src/service/pb_proto.h+++ b/Windows/src/service/pb_proto.h@@ -19,7 +19,7 @@#define PB_SERVICE_NAME L"ProxyBridgeSvc"#define PB_PIPE_CTL L"\\\\.\\pipe\\ProxyBridgeCtl"#define PB_PIPE_EVT L"\\\\.\\pipe\\ProxyBridgeEvt"-#define PB_PROTO_VERSION 1+#define PB_PROTO_VERSION 2 // 2: per-rule localhost flag; PBOP_SET_LOCALHOST removed#define PB_MSG_MAX (64u * 1024u)#define PB_STR_MAX (32u * 1024u)#define PB_NULL_STR 0xFFFFFFFFu@@ -30,14 +30,13 @@ enum {PBOP_EDIT_PROXY, // id, type, ip, port, user, pass, sendDomain -> boolPBOP_DELETE_PROXY, // id -> boolPBOP_TEST_PROXY_START, // id, host, port -> bool (result arrives as PBEVT_TEST_DONE)- PBOP_ADD_RULE, // proc, hosts, ports, domains, proto, action, cfgId -> id+ PBOP_ADD_RULE, // proc, hosts, ports, domains, proto, action, cfgId, localhost -> idPBOP_ENABLE_RULE, // id -> boolPBOP_DISABLE_RULE, // id -> boolPBOP_DELETE_RULE, // id -> bool- PBOP_EDIT_RULE, // id, proc, hosts, ports, domains, proto, action, cfgId -> bool+ PBOP_EDIT_RULE, // id, proc, hosts, ports, domains, proto, action, cfgId, localhost -> boolPBOP_MOVE_RULE, // id, pos -> boolPBOP_GET_RULE_POS, // id -> pos- PBOP_SET_LOCALHOST, // bool -> 0PBOP_SET_TRAFFIC_LOG, // bool -> 0PBOP_CLEAR_CONN_LOGS, // () -> 0PBOP_START, // () -> booldiff --git a/Windows/src/service/pb_service.c b/Windows/src/service/pb_service.cindex d93b117..7cbaf45 100644--- a/Windows/src/service/pb_service.c+++ b/Windows/src/service/pb_service.c@@ -154,14 +154,14 @@ static BOOL Dispatch(const BYTE *req, DWORD reqLen, PbW *resp)UINT32 id = (op == PBOP_EDIT_RULE) ? PbR_U32(&r) : 0;PbR_Str(&r, proc, sizeof(proc), &nProc); PbR_Str(&r, hosts, sizeof(hosts), &nHosts);PbR_Str(&r, ports, sizeof(ports), &nPorts); PbR_Str(&r, domains, sizeof(domains), &nDomains);- UINT32 proto = PbR_U32(&r), action = PbR_U32(&r), cfg = PbR_U32(&r);+ UINT32 proto = PbR_U32(&r), action = PbR_U32(&r), cfg = PbR_U32(&r), localhost = PbR_U32(&r);if (!r.ok || proto > 2 || action > 2) return FALSE;if (op == PBOP_ADD_RULE)ret = g_api.AddRule(nProc ? NULL : proc, nHosts ? NULL : hosts, nPorts ? NULL : ports, nDomains ? NULL : domains,- (PBRuleProtocol)proto, (PBRuleAction)action, cfg);+ (PBRuleProtocol)proto, (PBRuleAction)action, cfg, localhost != 0);elseret = g_api.EditRule(id, nProc ? NULL : proc, nHosts ? NULL : hosts, nPorts ? NULL : ports, nDomains ? NULL : domains,- (PBRuleProtocol)proto, (PBRuleAction)action, cfg);+ (PBRuleProtocol)proto, (PBRuleAction)action, cfg, localhost != 0);break; }case PBOP_ENABLE_RULE: { UINT32 id = PbR_U32(&r); if (!r.ok) return FALSE; ret = g_api.EnableRule(id); break; }case PBOP_DISABLE_RULE: { UINT32 id = PbR_U32(&r); if (!r.ok) return FALSE; ret = g_api.DisableRule(id); break; }@@ -169,7 +169,6 @@ static BOOL Dispatch(const BYTE *req, DWORD reqLen, PbW *resp)case PBOP_MOVE_RULE: { UINT32 id = PbR_U32(&r), pos = PbR_U32(&r); if (!r.ok) return FALSE; ret = g_api.MoveRuleToPosition(id, pos); break; }case PBOP_GET_RULE_POS: { UINT32 id = PbR_U32(&r); if (!r.ok) return FALSE; ret = g_api.GetRulePosition(id); break; }- case PBOP_SET_LOCALHOST: { UINT32 v = PbR_U32(&r); if (!r.ok) return FALSE; g_api.SetLocalhostViaProxy(v != 0); break; }case PBOP_SET_TRAFFIC_LOG: { UINT32 v = PbR_U32(&r); if (!r.ok) return FALSE; g_api.SetTrafficLoggingEnabled(v != 0); break; }case PBOP_CLEAR_CONN_LOGS: g_api.ClearConnectionLogs(); break;case PBOP_START: ret = g_api.Start(); break;