# Upstream proxy

Phantom can send its research traffic through another proxy: a second
intercepting proxy you chain to, a corporate proxy, Tor, or an SSH tunnel
(`ssh -D 1080 host`). Open **Proxy › Settings › Upstream proxy**.

## What goes through it

- the intercepting proxy's connections to sites (what your browser sends
  through Phantom);
- replay and Repeater;
- Intruder attacks;
- scans.

Loopback addresses (`localhost`, `127.0.0.1`, `::1`) always go directly,
and so do hosts that match **Go directly to**: exact names or patterns
such as `*.internal` or `10.*`. AI providers, bug bounty platforms and
webhooks are not research traffic and connect as before.

## Address

| Address | Proxy |
| --- | --- |
| `http://host:port` | HTTP proxy; HTTPS sites through `CONNECT` |
| `https://host:port` | The same, with TLS to the proxy |
| `socks5://host:port` | SOCKS5; the proxy resolves names, so DNS goes through it too |

A user name and password are optional. The password is kept encrypted
with the configuration key and never shown again: the card only says that
one is saved. Leave the field empty to keep it, or use **Forget
password**.

**Test** opens a tunnel to `example.com:443` through the saved proxy and
says whether it worked and how long it took.

## Things to know

- **TLS stays end to end.** Through an HTTP or SOCKS proxy, Phantom
  starts TLS with the site inside the tunnel, so the upstream proxy sees
  only the encrypted connection. To inspect the traffic in a second
  intercepting proxy, that proxy must act as a normal forward proxy, and
  Phantom must trust its CA (Proxy › Settings › Upstream TLS, extra CA
  file).
- **Plain HTTP and SOCKS.** Browser traffic over plain `http://` cannot
  go through a SOCKS upstream: Phantom refuses those requests with an
  explanation (502). HTTPS through the proxy, replay, Repeater, Intruder
  and scans work with SOCKS. With an HTTP upstream everything works.
- **Scope does not change.** Scope and engagement rules are checked before
  a request leaves, wherever it goes next.
- **Who can change it.** Only you can save or test the upstream proxy;
  agents cannot.

## API

| Method | Path | Does |
| --- | --- | --- |
| `GET` | `/api/v1/proxy/upstream` | Settings in effect: `enabled`, `url`, `username`, `has_password`, `bypass`, `socks` |
| `PUT` | `/api/v1/proxy/upstream` | Replace them (user only); `password` null keeps the saved one, `""` removes it |
| `POST` | `/api/v1/proxy/upstream/test` | Open a tunnel to example.com through the saved proxy (user only) |

Code: `backend/app/core/upstream_proxy.py` (connecting through HTTP and
SOCKS5), `backend/app/core/upstream_transport.py` (httpx clients),
`backend/app/runtime/upstream_proxy.py` (settings),
`backend/app/api/v1/upstream_proxy.py`.
