# Threat model

> [!NOTE]
>
> Halaman ini belum diterjemahkan. Anda sedang membaca versi bahasa Inggris.

This page says what CashPilot protects, who it protects it from, and where the boundaries are. Each control links to the code that enforces it. The links point at a fixed commit, so you can read the exact lines. The [security defaults](<https://geiserx.github.io/CashPilot/id/security-defaults/index.md>) page has the full detail of each control. This page is the map.

## Assets

| Asset | Where it lives | Why it matters |
| --- | --- | --- |
| Provider logins, API keys and tokens | The UI's database, `/data/cashpilot.db`, encrypted | Most of these accounts hold money |
| The encryption key | `/data/.fernet_key`, or a file you name with `CASHPILOT_ENCRYPTION_KEY_FILE` | It decrypts every stored login |
| Wallets and node identities | Earner volumes, such as Mysterium's keystore and Storj's identity | No provider keeps a copy, so a lost one is gone |
| The host | Every machine that runs a worker | The Docker API is root on that machine |
| Your home network | The LAN, the router, your tailnet, cloud metadata | Earners carry strangers' traffic through your IP |
| The owner account | The UI | It can deploy, delete and read every login |
| Your earnings data | The UI's database and `/metrics` | Balances, box names and LAN addresses are private |

## Adversaries

1. A hostile earner image. The images in the catalog are third-party and mostly closed-source. One of them can be malicious, or a provider can push a bad build under the same tag.
2. A buyer of your bandwidth. Bandwidth-sharing services sell your IP to their customers. That traffic must reach the internet and nothing else.
3. Someone who reaches the dashboard or the worker's API. A person on your LAN, or on the internet if you publish a port.
4. A compromised worker. A bug in the worker, or an attacker who holds a worker's key.
5. A compromised UI. A bug in the dashboard, or a stolen session.
6. A dead or hostile proxy. A proxy that you route a copy through can stop, or can try to reach your LAN.

## Trust boundaries

```
flowchart LR
  B[Browser] -->|session cookie| UI[CashPilot UI]
  UI -->|per-worker key| W[Worker]
  W -->|filtered socket| P[Socket proxy]
  P -->|calls its policy allows| D[Docker on the host]
  M[One-shot migration] -->|raw socket, at each compose up| D
  D --> E[Earner containers]
  E -->|fenced bridge| I[Internet]
  E -.->|dropped| L[LAN, host, tailnet, metadata]
  E -->|shared namespace| T[Tunnel sidecar]
  T --> X[Your proxy]
  C[Isolated copy] -->|internal network| G[Gate]
  G --> X
```

| Boundary | Between | What crosses it |
| --- | --- | --- |
| 1 | Your browser and the UI | Sign-in, every page and every action |
| 2 | The UI and each worker | Deploy, stop and remove commands, and heartbeats |
| 3 | The worker and Docker | Every Docker API call, through the socket proxy |
| 4 | An earner and the host kernel | System calls, capabilities, devices, host folders |
| 5 | An earner and the network | Every packet an earner sends |
| 6 | A proxied copy and its proxy | Every packet of that copy, through a tunnel sidecar, or through a gate for an isolated copy |

## Threats and controls

### 1\. Browser to UI

| Threat | Control | Enforced in |
| --- | --- | --- |
| The dashboard is reachable from other machines | The compose file publishes the UI on `127.0.0.1` only. You must set `CASHPILOT_BIND_ADDR` to open it | [docker-compose.yml](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/docker-compose.yml#L42-L43>) |
| The first person to open `/register` takes the owner account | The first account needs a one-time setup token. The UI prints it to its own log, so only someone with access to the host can read it | [app/setup\_token.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/setup_token.py#L51>), [app/deps.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/deps.py#L177-L190>) |
| Password guessing | Passwords are stored as bcrypt hashes. Sign-in stops for 5 minutes after 5 attempts at one account from one IP, or 30 attempts from one IP | [app/auth.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/auth.py#L104-L109>), [app/login\_rate\_limit.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/login_rate_limit.py#L28-L38>) |
| Session theft through a script on the page | The session cookie is `HttpOnly` and `SameSite=Lax`. It is `Secure` when `CASHPILOT_BASE_URL` starts with `https`, when a trusted proxy (`CASHPILOT_TRUSTED_PROXY`) sends `X-Forwarded-Proto: https`, or when `CASHPILOT_SECURE_COOKIE` is on | [app/auth.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/auth.py#L215-L222>) |
| Another site on the same host sends actions with your cookie | The UI refuses a state-changing request whose `Sec-Fetch-Site` or `Origin` is not its own | [app/main.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/main.py#L3568-L3600>) |
| A stolen session or the admin API key empties a wallet | Actions that cannot be undone, such as deleting a wallet volume or showing a seed, ask for the owner's password again. An API key can never give it | [app/deps.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/deps.py#L198-L215>) |
| Device IDs leak to people who should not see them | Alerts and logs for anyone but the owner show only the last four characters of an EarnApp or ProxyRack device ID | [app/notify.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/notify.py#L67-L95>) |
| `/metrics` shows balances and box names | Metrics are off by default. With `CASHPILOT_METRICS_TOKEN` set, they need a bearer token | [app/metrics.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/metrics.py#L280-L286>) |

### 2\. UI to worker

| Threat | Control | Enforced in |
| --- | --- | --- |
| Anyone with the shared key commands every worker | The shared key only enrolls a worker. The UI then gives each worker its own key, and the worker refuses the shared key once its own key is confirmed | [app/worker\_api.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/worker_api.py#L374-L390>) |
| The worker's API is reachable from the network | The default compose file does not publish the worker's port. The fleet and worker files publish it on `127.0.0.1` only | [docker-compose.yml](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/docker-compose.yml#L209-L210>), [docker-compose.worker.yml](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/docker-compose.worker.yml#L136>) |
| A worker URL makes the UI call cloud metadata or a loopback service (SSRF) | The UI blocks metadata, loopback and link-local addresses. It resolves the name once, checks the address, and connects to that address | [app/worker\_proxy.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/worker_proxy.py#L42-L43>) |
| A key travels in clear text over the internet | The UI and the worker send a key over plain HTTP only to a private address or a private name. The check reads the URL's host and does no DNS lookup, so a name under `.local`, `.lan`, `.home.arpa`, `.internal` or `.ts.net` passes even if it resolves to a public address | [app/cleartext.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/cleartext.py#L56-L90>) |
| Secrets in request URLs end up in the log | A log filter removes bot tokens, webhook tokens, URL passwords and API keys from every logged URL | [app/log\_redaction.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/log_redaction.py#L188>) |

### 3\. Worker to Docker

| Threat | Control | Enforced in |
| --- | --- | --- |
| Whoever holds the Docker socket is root on the host | With the shipped compose files the worker has no socket. A proxy, sockguard, pinned by digest, holds the socket, has no network, and serves the worker a filtered socket. The proxy's filtering is the control. Its `:ro` mount is not, because a read-only bind of a Unix socket still allows the full Docker API | [docker-compose.yml](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/docker-compose.yml#L139-L179>) |
| A compromised worker starts a privileged container or binds `/` | The proxy reads every request body. It refuses privileged mode, host PID, IPC and user namespaces, capabilities and devices outside a short list, and any host folder you did not list | [docker-compose.yml](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/docker-compose.yml#L322-L344>) |
| A compromised worker touches the UI or your other containers | The proxy stamps an owner label on everything the worker creates, and refuses the worker everything without that label | [app/socket\_policy.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/socket_policy.py#L59-L62>) |
| A compromised worker reads the encryption key | The worker does not mount the UI's `/data`. A test fails if the two volumes are merged | [docker-compose.yml](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/docker-compose.yml#L214-L231>) |
| An image update widens the proxy's rules | The rules live in your compose file, never in an image. A test fails when a catalog change needs a rule the policy lacks, or when the policy gets looser | [scripts/socket\_proxy\_policy.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/scripts/socket_proxy_policy.py>), [tests/test\_socket\_proxy.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/tests/test_socket_proxy.py>) |

### 4\. Earner to host

| Threat | Control | Enforced in |
| --- | --- | --- |
| An earner uses kernel features it does not need | Every capability is dropped. Only the ones its catalog entry declares come back. `no-new-privileges` and a process limit are always set, and privileged mode is fixed to off | [app/orchestrator.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/orchestrator.py#L1713-L1730>) |
| A deploy request asks for privileged mode or a host device | The worker refuses privileged mode. It refuses any device that the service's own catalog entry does not declare | [app/worker\_api.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/worker_api.py#L2149-L2160>) |
| A deploy binds `/etc`, `/var/run` or another system folder | System folders are blocked. You can open a specific service folder, never a whole root | [app/worker\_api.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/worker_api.py#L1744-L1760>) |
| An earner takes the GPU on a host whose default runtime is `nvidia` | Every container without a catalog GPU grant gets `NVIDIA_VISIBLE_DEVICES=void` | [app/gpu.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/gpu.py#L54>) |
| A custom image you add gets extra rights | A custom service can carry no ports, capabilities, devices, network mode or privileged mode | [app/custom\_services.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/custom_services.py#L9-L15>) |
| An earner's password shows in `docker inspect` | With `CASHPILOT_EARNER_SECRETS=file`, the worker keeps most catalog passwords out of Docker's container config | [app/secret\_env.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/secret_env.py#L1-L25>) |
| A deploy or delete destroys a wallet or node identity | The worker refuses to delete a critical volume without an approval the UI signs after the owner's password check | [app/worker\_api.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/worker_api.py#L3304-L3326>) |
| A provider pushes a broken build under the same tag | The daily image update watches each new container for 2 minutes. If it stops, restarts, turns unhealthy or logs a known failure, the worker starts the old container again, and tells you if that fails too. This does not catch a malicious build that keeps running. Images pinned by digest move only with a CashPilot release | [app/image\_updates.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/image_updates.py#L19-L30>) |

### 5\. Earner to network

| Threat | Control | Enforced in |
| --- | --- | --- |
| An earner, or a customer of the provider, reaches your LAN, router or other devices | New installs put earners on `cashpilot-isolated`, behind a firewall table that drops the private ranges, Tailscale's range, link-local and the host itself | [app/lan\_fence.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/lan_fence.py#L106-L116>) |
| The firewall table goes missing after a reboot or a flush | The internet route (the masquerade) lives in the same table as the drops. Without the table the earners go offline, not onto the LAN. Three exceptions apply until the worker writes the table again: the host itself stays reachable, a masquerade rule of the host's own that covers the bridge lets earners out unfiltered, and one-way UDP to a LAN device still leaves ([isolation](<https://geiserx.github.io/CashPilot/id/isolation/index.md#lan-isolation-by-default>)) | [app/lan\_fence.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/lan_fence.py#L19-L27>) |
| An earner reaches cloud metadata on a VPS | `169.254.0.0/16` is one of the dropped ranges | [app/lan\_fence.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/lan_fence.py#L106-L116>) |

### 6\. Proxied copy to proxy

| Threat | Control | Enforced in |
| --- | --- | --- |
| The proxy dies and the copy earns from your own IP | A copy without `NET_ADMIN`, `NET_RAW` or a device shares the network of a tunnel sidecar whose firewall drops every packet by default. It lets out only the tunnel and the connection to the proxy. If the tunnel stops, traffic stops | [tunnel/cp-tunnel](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/tunnel/cp-tunnel#L15-L52>) |
| A copy that holds `NET_ADMIN`, `NET_RAW` or a device such as `/dev/net/tun` (Mysterium, Bitping) rewrites its own firewall or sends raw packets past it | That copy never shares a sidecar's namespace. It runs in `cp-inner`, on an internal Docker network whose only route is a gate. The gate is a sidecar that forwards the copy's traffic into the tunnel and nowhere else, from a firewall in its own namespace ([isolated copies](<https://geiserx.github.io/CashPilot/id/proxies/index.md#copies-that-need-net_admin-or-net_raw>)) | [app/proxy\_tunnel.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/proxy_tunnel.py#L916-L919>), [tunnel/cp-tunnel](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/tunnel/cp-tunnel#L202-L226>), [tunnel/cp-inner](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/tunnel/cp-inner#L1-L15>) |
| Traffic through the tunnel reaches your LAN or tailnet | The sidecar drops private, Tailscale and link-local destinations on the tunnel too | [tunnel/cp-tunnel](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/tunnel/cp-tunnel#L138-L150>) |
| The tunnel sidecar itself has too many rights | It drops every capability except `NET_ADMIN`, has a read-only root, `no-new-privileges` and a process limit | [app/proxy\_tunnel.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/proxy_tunnel.py#L757-L764>) |
| The proxy password shows in labels or `docker inspect` | The worker writes the proxy settings into a file in the sidecar, under `/run/cashpilot-secret`, never into its environment | [app/proxy\_tunnel.py](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/app/proxy_tunnel.py#L103>) |

## Limits

We list the gaps so that you can decide with all the facts. The details are in [security defaults](<https://geiserx.github.io/CashPilot/id/security-defaults/index.md#docker-socket-proxy>).

- The socket proxy is not yet a full root boundary in every setup. Since sockguard 2.4.10 it binds a listed host path only as itself, so a symlink planted in a listed folder leads nowhere. But when one listed path sits inside another, counting `CASHPILOT_COMPOSE_DIR` as listed (a path inside the compose folder, or a path that holds it), a compromised worker can replace the inner one with a symlink and reach the host's `/`. With both unset, no host folder can be bound.
- The raw socket still reaches two places. The one-shot `cashpilot-migrate` holds it as root, with no network and every capability dropped, each time `docker compose up` runs. It starts before the proxy and exits ([docker-compose.yml](<https://github.com/GeiserX/CashPilot/blob/cd7d87e25109b2ac838cc56a742760e0c456aed5/docker-compose.yml#L97-L128>)). The Unraid template and the TrueNAS app do not ship the proxy yet, so there the worker gets the raw socket ([app stores](<https://geiserx.github.io/CashPilot/id/app-stores/index.md>)).
- A compromised worker controls its own earners. It can stop them, read their logs and environment, and delete their volumes, including the critical ones, through Docker directly.
- A compromised worker can start a container on host networking with `NET_ADMIN`. That container can change the host's network settings and take an earner off the fence. The owner label does not stop it, because the LAN fence's own helper needs the same rights.
- An isolated copy can still send DNS lookups from the box's own IP. This happens on Docker engines before 25.0.5 (23.0.11 on the 23 line), when the host's own resolver is a loopback address, such as a Pi-hole on `127.0.0.1`. This is moby [CVE-2024-29018](<https://github.com/moby/moby/security/advisories/GHSA-mq39-4gv4-mvpx>). The fix is [\#977](<https://github.com/GeiserX/CashPilot/pull/977>), which is not shipped yet.
- The UI and a worker on one host share that host. For a stronger boundary, run the UI on a machine with no worker ([fleet](<https://geiserx.github.io/CashPilot/id/fleet/index.md>)).
- The encryption key sits beside the database by default. A leaked database file alone does not reveal the stored logins, but it shows your earnings data. Moving the key out protects copies of the data folder, such as backups. A compromised UI reads the key in both cases, because the UI loads it to decrypt the logins ([encryption key](<https://geiserx.github.io/CashPilot/id/encryption-key/index.md>)).
- UI to worker traffic is plain HTTP by default. Keep it on your LAN or in a VPN. Neither side sends its key over plain HTTP to a public address, but the check trusts private names such as `.lan` without a DNS lookup.
- Earners share the host kernel. A kernel bug in an earner reaches the host. gVisor or the Secure VM closes this, and both are opt-in ([security layers](<https://geiserx.github.io/CashPilot/id/security-layers/index.md>)).
- Root on the host reads everything. No control here protects against someone who is already root on a box.
- The provider sees your traffic and your IP. CashPilot cannot change what a provider does with the connection it rents.

## Tests

- `tests/test_socket_proxy.py` checks the proxy policy against the catalog and fails when it gets looser. `scripts/socket_proxy_live_test.sh` runs the real proxy against a real Docker daemon. Each refused call passes when sent to the raw socket, which proves the refusal is the proxy's.
- `tests/test_lan_fence.py` checks the firewall table. [Test your isolation](<https://geiserx.github.io/CashPilot/id/isolation-check/index.md>) runs the same probes from the dashboard, on your own box.
- `tests/test_proxy_tunnel.py` and `tests/test_proxy_tunnel_real_docker.py` check the tunnel. `scripts/proxy_leak_test.sh` checks that a dead proxy stops the copy.
- `tests/test_setup_token.py`, `tests/test_cleartext_refusal.py`, `tests/test_custom_services.py`, `tests/test_secret_env.py` and `tests/test_image_updates.py` cover the other rows.
- `tests/test_beads_batch_69.py` fails if the worker's volume and the UI's `/data` are merged.

To report a gap, see [SECURITY.md](<https://github.com/GeiserX/CashPilot/blob/main/SECURITY.md>). Do not open a public issue.
