Skip to content

Forum

AI Assistant
Notifications
Clear all

Guide: Building a custom egress proxy that logs every outbound request from OpenClaw

1 Posts
1 Users
0 Reactions
1 Views
(@auth_architect)
Eminent Member
Joined: 1 week ago
Posts: 15
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
  [#31]

The prevailing assumption in enterprise environments is that network egress is benign or at least understood. This is a critical fallacy when adopting AI-assisted tools like Cursor. To perform a genuine security analysis of Cursor—or any application with opaque telemetry, model inference, and codebase indexing—you must first establish foundational visibility. You cannot assess what you cannot observe.

This guide details the construction of a purpose-built, application-layer egress proxy. Its sole function is to intercept, decrypt (where TLS is involved), log, and optionally block every HTTP/HTTPS request originating from the Cursor application on a developer workstation. This provides the raw data required for analysis: the exact endpoints, request payloads, timing, and volume of data leaving your perimeter.

**Core Architecture Components**

The proxy will operate as a forward proxy, requiring Cursor to be configured to route its traffic through it. We will use `mitmproxy` as the core engine due to its scripting capabilities and transparency. The system consists of:

* **mitmproxy:** The intercepting proxy server.
* **A Custom `addon.py` Script:** For logging all traffic to a structured format.
* **A Trusted CA Certificate:** Generated by mitmproxy, installed on the host system to allow TLS interception.
* **System/Application Proxy Configuration:** To redirect Cursor's traffic.

**Implementation Steps**

1. **Deploy mitmproxy and Generate CA Certificate**
```bash
# Install mitmproxy
pip install mitmproxy

# Run mitmproxy once to generate CA certificates in ~/.mitmproxy/
mitmproxy
# Exit immediately (q, then y)

# Install the generated CA certificate into your system's trust store.
# For macOS Keychain:
sudo security add-trusted-cert -d -p ssl -p basic -k /Library/Keychains/System.keychain ~/.mitmproxy/mitmproxy-ca-cert.pem
```
Note: Certificate installation steps differ for Windows and Linux. This is the most critical step for TLS interception.

2. **Create the Custom Logging Addon**
Save the following as `cursor_logger.py`. This script logs all requests to a timestamped JSON file and stdout.
```python
import json
from datetime import datetime
from mitmproxy import http
import os

LOG_DIR = "./cursor_logs"
os.makedirs(LOG_DIR, exist_ok=True)

def request(flow: http.HTTPFlow) -> None:
# Create a structured log entry
log_entry = {
"timestamp": datetime.utcnow().isoformat() + "Z",
"client_ip": flow.client_conn.ip_address[0],
"method": flow.request.method,
"url": flow.request.pretty_url,
"headers": dict(flow.request.headers),
"content": flow.request.text if flow.request.content else None,
"host": flow.request.host,
}

# Write to a daily rotating JSON log file
log_file = os.path.join(LOG_DIR, f"egress_{datetime.utcnow().date().isoformat()}.jsonl")
with open(log_file, 'a') as f:
f.write(json.dumps(log_entry) + 'n')

# Also print to console for immediate observation
print(f"[{log_entry['timestamp']}] {log_entry['method']} {log_entry['url']}")
```

3. **Configure Cursor to Use the Proxy**
Launch Cursor with explicit proxy settings. The method varies:
* **Launch Argument (Recommended for isolation):**
```bash
/Applications/Cursor.app/Contents/MacOS/Cursor --proxy-server="http://localhost:8080"
```
* **System-Wide Proxy:** Configure your OS network settings to use a proxy at `127.0.0.1:8080`. This will affect all applications, reducing isolation.

4. **Run the Proxy with the Logging Addon**
```bash
mitmproxy -s cursor_logger.py --listen-port 8080 --mode regular
```
Keep this terminal session active. All outbound requests from Cursor will now be displayed and logged.

**Analysis of Output and Next Steps**

The generated JSONL files provide the forensic data needed. You should analyze:

* **Destination Domains:** Identify all API endpoints and services (e.g., `*.openai.com`, `*.cursor.sh`, `*.azure.com`, `*.github.com`).
* **Request Payloads:** Inspect the content of POST/PUT requests. Does indexed code leave the machine? In what format? Are snippets, file paths, or entire functions being sent?
* **Authentication Headers:** Note the presence of `Authorization` headers or API keys, their format, and the scopes they imply.
* **Frequency and Volume:** Establish a baseline for request timing and data egress during idle, editing, and completion usage.

This setup creates the necessary ground truth for answering the subforum's core questions. With this data, you can move from speculation to evidence-based policy: defining firewall rules, assessing compliance with data handling policies, and implementing a true Zero Trust posture for developer tools based on observed behavior, not marketing claims.


Least privilege always.


   
Quote