kiji-proxy icon indicating copy to clipboard operation
kiji-proxy copied to clipboard

Transparent Proxy toggle shows "Off" while the backend has enabled the system proxy and is intercepting

Open TrigrD3 opened this issue 1 month ago • 0 comments

Reproduction steps

Desktop app 1.6.8 on macOS, default settings: ~/Library/Application Support/Kiji Privacy Proxy/config.json has no transparentProxyEnabled key, and the Kiji CA is not installed in any keychain.

  1. Before launching, check the system proxy:
    $ networksetup -getautoproxyurl Wi-Fi
    Enabled: No
    
  2. Launch Kiji Privacy Proxy. Open Settings → Advanced: the Transparent Proxy toggle is off. The Dashboard shows Intercepting.
  3. While the app is running:
    $ networksetup -getautoproxyurl Wi-Fi
    URL: http://localhost:9090/proxy.pac
    Enabled: Yes
    
    $ lsof -nP -iTCP -sTCP:LISTEN | grep kiji
    kiji-prox  *:9090 (LISTEN)
    kiji-prox  *:8080 (LISTEN)
    kiji-prox  *:8081 (LISTEN)
    
  4. The proxy on :8081 decrypts and masks traffic, although the toggle is off:
    $ openssl s_client -proxy 127.0.0.1:8081 -connect api.openai.com:443 -servername api.openai.com </dev/null | grep issuer
    issuer=C=US, ... O=Kiji Privacy Proxy CA, CN=Kiji Privacy Proxy CA
    
    A chat completion sent through :8081 (with a dummy API key) containing Hi, I am Tom Becker, email [email protected] appears in Activity as request_masked: Hi, I am Jennifer Smith, email [email protected].
  5. A browser that follows the system proxy fails on the provider hosts. Headless Chrome with default proxy settings:
    https://api.openai.com/v1/models -> net::ERR_CERT_AUTHORITY_INVALID
    https://example.com/             -> HTTP 200
    
  6. Turn the toggle on (the CA setup modal opens), then off again. config.json now has "transparentProxyEnabled": false. The proxy stops decrypting (:8081 now returns OpenAI's own certificate, issuer=... Google Trust Services), but the system proxy is still Enabled: Yes.
  7. Quit and relaunch with "transparentProxyEnabled": false stored. The toggle shows off, the system proxy is Enabled: Yes again, and :8081 presents the Kiji CA certificate again, as in steps 2–4.
  8. Quit: Enabled: No.

Backend log at startup and shutdown. This is the bundled binary Kiji Privacy Proxy.app/Contents/Resources/kiji-proxy run directly with no config file and no environment overrides, which is the same path the desktop app takes; the desktop app does not write the backend log to disk.

PAC server starting on http://localhost:9090/proxy.pac
Configuring proxy for network service: Wi-Fi
System proxy configured successfully with PAC URL: http://localhost:9090/proxy.pac
✅ System proxy configured successfully
📡 Traffic to [api.anthropic.com api.openai.com generativelanguage.googleapis.com api.mistral.ai api.openai.com chatgpt.com] will be automatically routed through proxy
Starting transparent proxy on port :8081
...
Received signal terminated, shutting down and restoring system proxy...
Disabling system proxy for network service: Wi-Fi
System proxy disabled successfully

Current vs. Expected behavior

Current:

  • On every launch the backend enables the macOS auto-proxy for the provider hosts and decrypts and masks their traffic, whatever the toggle shows or the config stores (steps 2–4, 7).
  • Until the CA is trusted, browser requests to those hosts fail with ERR_CERT_AUTHORITY_INVALID while the toggle says off (step 5).
  • Turning the toggle off stops decryption but leaves the system proxy enabled until the app quits (step 6).
  • The next launch turns interception back on, while the toggle still shows off (step 7).

Expected: the toggle shows what the backend is doing, and a stored choice survives a restart.

Which default is intended isn't clear to me, since the project points both ways. #182 ("make the transparent proxy optional") and the toggle's off default with its "Experimental" label suggest opt-in. The README's automatic PAC setup on macOS and the backend default (TransparentEnabled: true) suggest on-by-default. Either works for the fix below, as long as the toggle and the backend share one default.

Cause (source at main, 0b3ff18; identical in v1.6.8)

Present since the toggle was added in #182: the stored value has only ever been sent to the backend when the toggle changes, never at startup.

  • The desktop setting defaults to off: src/frontend/src/electron/ipc-handlers.js:505-515 (defineConfigField("transparentProxyEnabled", …, { defaultValue: false, … })).
  • The backend defaults to on: src/backend/config/config.go:409-413 (TransparentEnabled: true, EnablePAC: true).
  • When the desktop app spawns the backend it forwards provider keys and KIJI_TELEMETRY_ENABLED (src/frontend/src/electron/electron-main.js:284-289), but not TRANSPARENT_PROXY_ENABLED, which the backend reads at src/backend/main.go:351. The stored value only reaches the backend when the toggle changes (onChange → POST /api/proxy/transparent/toggle); nothing sends it on launch.
  • So the backend starts the PAC server and calls systemProxyManager.Enable() at startup (src/backend/server/server.go:218-240).
  • POST /api/proxy/transparent/toggle only flips the flag that switches the proxy to passthrough (server.go:864, proxy/transparent.go:84-92); it does not touch the system proxy.

Possible fix

Forward the stored value when spawning the backend, the same way telemetry is forwarded:

// electron-main.js, next to isTelemetryEnabled()
const isTransparentProxyEnabled = () => {
  try {
    return readConfig().transparentProxyEnabled === true;
  } catch (error) {
    console.error("[TransparentProxy] Failed to read preference:", error);
    return false;
  }
};

// in the backend spawn, next to KIJI_TELEMETRY_ENABLED
env.TRANSPARENT_PROXY_ENABLED = isTransparentProxyEnabled() ? "true" : "false";

The helper's fallback for an unset key decides the desktop default: === true makes interception opt-in (matching today's toggle), !== false keeps it on by default (matching today's backend), and then ipc-handlers.js should use the same default so the toggle shows on. Linux/server deployments keep the backend's own default, since they have no desktop app to pass the value.

Making the toggle also enable and disable the system proxy at runtime (step 6) is a separate change. Happy to open a PR for the first part once you've picked the default.

Kiji Privacy Proxy version and system specs

  • Kiji Privacy Proxy 1.6.8 (Homebrew cask dataiku/tap/kiji-privacy-proxy), desktop app
  • macOS 15.8.1 (24H212), Apple M3

Model provider details

  • Provider: not provider-specific. Reproduced with no provider keys configured in the app; step 4 used OpenAI's endpoint with a dummy key (HTTP 401).
  • Model Name: n/a

TrigrD3 avatar Nov 04 '26 11:11 TrigrD3