Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

Versions follow `v*.*.*` with dots. Dates are US Eastern.

## 0.8.0 · 2026-11-22

Change what passes through FormNET, and capture a phone.

- Rules, in Preferences and the new Tools menu: rewrite headers, the address, the status or the body; map a request to another server (Map Remote) or answer it from a file or folder on this computer (Map Local); block a host with a 403 or by dropping the connection. Each rule has its own switch, and Enable Rules (Cmd+Option+K, Ctrl+Alt+K) turns them all off and on. Flows marks every request a rule changed. Make a Rule turns a flow into a rule.
- Breakpoints: pause a request or its response, change it, then let it go on or abort it. A forgotten breakpoint lets the request go on by itself after a minute, so no program hangs.
- Throttling: 3G, 4G, slow Wi-Fi or your own speeds and delay, for everything or a list of hosts.
- Capture from other devices: a phone or another computer on your network can use FormNET's proxy, for the addresses you allow. It is off until you turn it on, and FormNET's own window and data stay reachable from this computer only. The phone installs FormNET's certificate from http://formnet.cert/.
- Fixed: Esc closes Preferences after you use the System Proxy switch.
- The new labels read in English in the other languages until a later version translates them.

## 0.7.0 · 2026-11-22

No setup by hand, and any request can be sent again.
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ What a program actually does on the network, not what it promises: an intercepti
## Layout

- `cmd/formnet/` the command: `serve` (default), `url`, `open`, `ca`, `snapshot`, `version`, `help`.
- `internal/config/` settings from `FORMNET_*` variables; both listeners are loopback-only and refuse anything else.
- `internal/config/` settings from `FORMNET_*` variables; both listeners are loopback-only and refuse anything else, except the proxy's listeners for capture from other devices (below).
- `internal/flow/` the record: `Flow`, the `Store` bounded by a flow count and a byte budget, with counted subscriptions and an epoch, per-host summaries, the known-host labels (`classify.go`) and a streaming HAR export.
- `internal/ca/` the local root certificate (made on first run in the data folder) and per-host leaf certificates.
- `internal/proxy/` the proxy: plain HTTP forwarding, CONNECT tunnels, TLS interception with the root, passthrough patterns, body capture up to the limit, byte and time accounting into the Store.
Expand All @@ -23,7 +23,7 @@ What a program actually does on the network, not what it promises: an intercepti

## Rules

- Never listen on a non-loopback address. The proxy and the API carry the bodies of everything FormNET sees.
- Never listen on a non-loopback address. The proxy and the API carry the bodies of everything FormNET sees. The one exception is the owner's: capture from other devices (`internal/proxy/remote.go`), a switch that is off by default, opens the proxy only (never the API or the page) on this computer's network addresses, needs an address allow list with at least one entry, and closes any other client before reading from it.
- Loopback is not a trust boundary: every program and user on the computer shares it. The API answers only with the run's session token (`FORMNET_TOKEN`, or the one written to `<data>/token` with mode 0600). Never add a route that serves recordings without it.
- The proxy never connects to FormNET's own addresses, and never to a loopback address reached through a host name (DNS rebinding into local services). Private ranges stay reachable; intranet hosts are legitimate.
- HTTPS is opened only when the root is trusted (or `FORMNET_INTERCEPT=on`); otherwise it is tunnelled and counted, and the UI says so. Keep the wording and the behaviour in step.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := v0.7.0
VERSION := v0.8.0
LDFLAGS := -s -w -X github.com/nodemode-dev/formnet/internal/app.Version=$(VERSION)
GO_BUILD := CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)"
TARGETS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</p>

<p align="center">
<img alt="version v0.7.0" src="https://img.shields.io/badge/version-v0.7.0-eef0f4?style=flat-square">
<img alt="version v0.8.0" src="https://img.shields.io/badge/version-v0.8.0-eef0f4?style=flat-square">
<img alt="Go 1.26" src="https://img.shields.io/badge/Go-1.26-00ADD8?style=flat-square&logo=go&logoColor=white">
<img alt="TypeScript and Vite" src="https://img.shields.io/badge/TypeScript-Vite-3178c6?style=flat-square">
<img alt="macOS, Windows, Linux" src="https://img.shields.io/badge/macOS%20%C2%B7%20Windows%20%C2%B7%20Linux-native-2f7bf5?style=flat-square">
Expand Down Expand Up @@ -55,7 +55,7 @@
</td>
<td width="25%" valign="top">
<h3>Nothing leaves</h3>
Both listeners bind loopback only, and recordings stay in memory until you export them.
Both listeners bind loopback only unless you let a phone or another computer use the proxy, and recordings stay in memory until you export them.
</td>
<td width="25%" valign="top">
<h3>Agent-ready</h3>
Expand Down Expand Up @@ -117,7 +117,7 @@ Also `/api/flows/{id}`, `/api/hosts`, `/api/machine`, `/api/export/har` and `/ap
## Under the hood

- **One binary:** a Go server with the web client embedded, plus a Tauri 2 window around the same binary for the desktop app.
- **Loopback only:** the proxy and the API refuse any other address, and the proxy never connects to loopback through a host name.
- **Loopback by default:** the API and the page answer on loopback only, always; the proxy also listens on the network only while "capture from other devices" is on, for the addresses you allow. The proxy never connects to loopback through a host name.
- **Local root:** the certificate is made on first run, its private key never leaves `~/formnet`, and HTTPS is opened only once you trust it.
- **Tested:** 82 Go tests and a Playwright window smoke in CI.

Expand Down Expand Up @@ -147,7 +147,7 @@ For client development, `cd web && npm ci && npm run dev` serves the client on h

Then point a program at the proxy, for example `curl -x http://127.0.0.1:8761 http://example.com/`. Until the computer trusts the root, HTTPS is tunnelled and counted but not opened; `./bin/formnet ca trust` prints the command that trusts it for your user only.

The client and API listen on 127.0.0.1:8760 and the proxy on 127.0.0.1:8761 (loopback only; the client needs this run's session token). Settings are `FORMNET_*` environment variables, such as `FORMNET_DATA`, `FORMNET_PASSTHROUGH` and `FORMNET_INTERCEPT`; `./bin/formnet help` lists them all.
The client and API listen on 127.0.0.1:8760 and the proxy on 127.0.0.1:8761 (loopback only, unless capture from other devices is on, which adds the proxy alone on the addresses you allow; the client needs this run's session token). Settings are `FORMNET_*` environment variables, such as `FORMNET_DATA`, `FORMNET_PASSTHROUGH` and `FORMNET_INTERCEPT`; `./bin/formnet help` lists them all.

> [!IMPORTANT]
> **Status:** early (v0.1). The desktop window source has not been compiled yet, and the process column in Flows is filled only where the platform reports it.
Expand Down
6 changes: 5 additions & 1 deletion cmd/formnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ Settings (environment):
FORMNET_REVERSE_DNS 1 to name remote addresses in the machine view (sends PTR queries); default off
FORMNET_TOKEN this run's session token; default a new one, kept in <data>/token
FORMNET_SYSTEM_PROXY 1 to point the system proxy at formnet while it runs, 0 not to (macOS, Windows); default off
FORMNET_REMOTE_CAPTURE 1 to let other devices use the proxy on this computer's network addresses, 0 not to; default off
FORMNET_REMOTE_ALLOW addresses or CIDR ranges allowed to, comma-separated; at least one is needed to turn it on

Interception, the passthrough list and the system proxy chosen in the web
client are kept in <data>/settings.json; FORMNET_INTERCEPT,
Expand Down Expand Up @@ -206,6 +208,7 @@ func serve(stdout, stderr io.Writer) int {
Refuse: []string{apiAddr, proxyAddr},
Log: log,
})
startRemote := useTraffic(px, cfg, saved, log)
proxyErr := make(chan error, 1)
go func() { proxyErr <- px.Serve(ctx, bound.proxy) }()

Expand All @@ -214,7 +217,7 @@ func serve(stdout, stderr io.Writer) int {
terminals := terminal.New(terminal.Options{APIAddr: apiAddr, ProxyAddr: proxyAddr, CAPath: info.Path, Log: log})
defer terminals.Close()
api := &http.Server{
Handler: server.Handler(server.Deps{Addr: apiAddr, Token: token, Store: store, Proxy: px, CA: authority, Machine: monitor, Dist: formnet.Dist(), Log: log, Notices: bound.notices, Quit: stop, Remember: remember, SystemProxy: systemProxy, BodyLimit: cfg.BodyLimit, Terminals: terminals}),
Handler: server.Handler(server.Deps{Addr: apiAddr, Token: token, Store: store, Proxy: px, CA: authority, Machine: monitor, Dist: formnet.Dist(), Log: log, Notices: bound.notices, Quit: stop, Remember: remember, SystemProxy: systemProxy, BodyLimit: cfg.BodyLimit, Terminals: terminals, Traffic: px}),
ReadHeaderTimeout: 10 * time.Second,
IdleTimeout: 90 * time.Second,
}
Expand All @@ -225,6 +228,7 @@ func serve(stdout, stderr io.Writer) int {
log.Error("proxy", "addr", proxyAddr, "err", err)
return 1
}
startRemote()
if err := writeEndpoints(cfg.Data, endpoints{Product: app.Product, Version: app.Version, PID: os.Getpid(), Addr: apiAddr, ProxyAddr: proxyAddr, CAPath: info.Path, Started: time.Now().UTC()}); err != nil {
log.Warn("endpoints file", "err", err)
}
Expand Down
74 changes: 74 additions & 0 deletions cmd/formnet/traffic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"log/slog"
"strings"
"time"

"github.com/nodemode-dev/formnet/internal/config"
"github.com/nodemode-dev/formnet/internal/proxy"
"github.com/nodemode-dev/formnet/internal/rules"
"github.com/nodemode-dev/formnet/internal/settings"
"github.com/nodemode-dev/formnet/internal/throttle"
)

// useTraffic gives the proxy its rules, throttle and breakpoints from the
// data folder, and returns the step that applies capture from other devices
// once the proxy listens. FORMNET_REMOTE_CAPTURE and FORMNET_REMOTE_ALLOW win
// for this run and are never written to settings.json.
func useTraffic(px *proxy.Proxy, cfg config.Config, saved *settings.File, log *slog.Logger) func() {
kept := saved.Current()
engine, err := rules.Open(cfg.Data)
if err != nil {
log.Warn("rules file not read; no rules apply until the next change replaces it", "err", err)
}
tc := throttle.Defaults()
if t := kept.Throttle; t != nil {
tc = throttle.Config{Enabled: t.Enabled, Preset: t.Preset, DownKbps: t.DownKbps, UpKbps: t.UpKbps, LatencyMS: t.LatencyMS, Hosts: t.Hosts}
}
shaper, err := throttle.New(tc)
if err != nil {
log.Warn("throttle setting not read; it is off until the next change", "err", err)
}
var timeout time.Duration
maxPaused := 0
if b := kept.Breakpoints; b != nil {
timeout, maxPaused = time.Duration(b.TimeoutSeconds)*time.Second, b.MaxPaused
}
px.UseTraffic(proxy.TrafficOptions{
Rules: engine,
Throttle: shaper,
BreakpointTimeout: timeout,
MaxPaused: maxPaused,
RemoteFromEnv: cfg.RemoteSet || cfg.RemoteAllowSet,
RememberThrottle: func(c throttle.Config) error {
return saved.SetThrottle(settings.Throttle{Enabled: c.Enabled, Preset: c.Preset, DownKbps: c.DownKbps, UpKbps: c.UpKbps, LatencyMS: c.LatencyMS, Hosts: c.Hosts})
},
RememberRemote: saved.SetRemote,
RememberBreakpoints: saved.SetBreakpoints,
})
enabled, allow := false, []string{}
if r := kept.Remote; r != nil {
enabled, allow = r.Enabled, r.Allow
}
if cfg.RemoteSet {
enabled = cfg.RemoteCapture
}
if cfg.RemoteAllowSet {
allow = cfg.RemoteAllow
}
return func() {
st, err := px.StartRemote(enabled, allow)
switch {
case err != nil && enabled:
log.Warn("capture from other devices not turned on", "err", err)
if _, err := px.StartRemote(false, allow); err != nil {
log.Warn("remote allow list not read", "err", err)
}
case err != nil:
log.Warn("remote allow list not read", "err", err)
case st.Enabled:
log.Info("capture from other devices: set the proxy on the other device to one of these", "addresses", strings.Join(st.Addresses, " "), "port", st.Port, "certificate", st.CertURL)
}
}
}
16 changes: 16 additions & 0 deletions internal/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,19 @@ The child's environment is the person's own, less `FORMNET_TOKEN` and `FORMNET_D
How children end: closing a tab (`DELETE`), a tab no page has been attached to for 60 seconds (the dock keeps its socket while the page lives and reattaches by listing after a reload), and the server stopping (SIGTERM, Ctrl-C, the desktop pipe closing, `POST /api/quit`) all end the tab's program. On macOS and Linux the shell is a session leader on its PTY: every process of that session (listed from `/proc` on Linux, from `kern.proc.all` on macOS, by session id) gets SIGHUP and SIGCONT, then after a second SIGKILL, so a job the shell put in its own process group goes too; a program that leaves the session with `setsid` is not followed. When the shell exits by itself what is left of its session is killed. On Windows each program runs in a job object with kill-on-close: the pseudo console is closed first (the console's close event), then the job is terminated; if the server dies without stopping, Windows closes the job handle and ends the tree. A crashed server on macOS and Linux leaves no job behind: the shell loses its terminal and gets SIGHUP from the kernel, but a program that ignores it stays.

Tests never start a real agent program: `agentlookup.Guard` runs before every start of a found program (the `--version` probe and an agent tab) and, inside a test binary only (`testing.Testing()`), refuses `claude`, `codex`, `cursor-agent`, `agent` and `agy` unless the file lives under the folder `FORMNET_AGENT_STAND_INS` names. A later test also sets a made-up `HOME`, a stand-in `SHELL` that runs `/bin/sh -c` without reading a profile, `PATH=/usr/bin:/bin:/usr/sbin:/sbin`, unsets the override variables, and sets `agentlookup.SystemFolders` to return nothing, as form.md's testguard does.

## 2026-11-22 · Rules, breakpoints, throttling and capture from other devices

One matcher (`internal/rules/match.go`) serves rules and the throttle's host list: `{scheme, host, port, path, method, query}`, compiled once to regular expressions. Host is a case-insensitive glob and `*.example.com` also matches `example.com`, as the passthrough list already does; path is a glob on the path alone where `*` crosses slashes; method may be a list (`GET,POST`); query is `name` or `name=glob` pairs joined by `&`, each of which must be present. Validation errors are `FieldError`s that name the field (`rules[2].match.port`), and the API returns them as they are.

`<data>/rules.json` (`userfile`, written whole, `{"version":1,"enabled":bool,"rules":[...]}`) holds the ordered list. A file that does not parse or validate is reported at start and no rule applies until the next change replaces it. A request is matched against the original request; rewrites accumulate in list order, the first map_remote wins, the first block or map_local ends the walk (rules after it do not run), and the first breakpoint of each stage pauses. Matching happens only where the proxy reads the HTTP: plain HTTP and HTTPS it opens. Tunnelled HTTPS and WebSocket upgrades pass unchanged; `GET /api/rules` says so in `https_note` and per rule in `notes`. Rules never apply to FormNET's own addresses (`ownTarget`), and a map_remote or edited URL still goes through the destination guard.

The rule path (`proxy/rules_hook.go`) is a separate exchange used only when a rule matches, so untouched traffic keeps the old path byte for byte. Body find and replace runs on text bodies (content type text, JSON, XML, JavaScript, form, SVG, or none) up to 8 MiB, on the decoded form. The changed body is sent without its `Content-Encoding` and with a new `Content-Length` rather than encoded again: identity is acceptable to every client, it cannot mismatch an encoder the client lacks, and it avoids carrying a second encoder for each coding; the flow carries a note saying so. A body over 8 MiB, or one that does not decode or is not UTF-8, passes unchanged with a note. A User-Agent a rule removes stays removed (net/http would add its own). Every flow a rule touched lists the rule names in `rules` and what happened in `notes`.

map_local: the path must be absolute, exist, and be neither the data folder nor inside it (refused at save). A file answers every match; a folder maps the part of the path after the match's literal prefix (the path pattern up to its first wildcard) under it. A `..` segment (decoded or not), a backslash, a symlink that resolves outside the folder or into the data folder are 403; a missing file is 404; `index.html` serves a folder. The file opened is compared with the one checked (`os.SameFile`). Content type comes from the extension.

Breakpoints (`proxy/breakpoints.go`): a paused exchange is in `GET /api/breakpoints` and on the stream (`breakpoint.paused`, then `breakpoint.resumed` with continued, edited, aborted, timeout or client_gone); the flow shows `paused` until it goes on. The request pauses after rewrites and map_remote, so the person sees what would go out. Continue takes an optional edit; an edited body that was shown decoded is sent without its Content-Encoding. Abort closes the client's connection. After the timeout (default 60 s, `POST /api/breakpoints`, kept in settings.json) the exchange goes on as it was, with a note; past the most paused at once (default 20) a match passes with a note, so a forgotten breakpoint never holds a program for ever. A client that leaves releases its pause.

Throttle (`internal/throttle`): one token bucket per direction shared by every throttled exchange and tunnel, as one slow link would be, burst 50 ms of traffic and at least 1500 bytes. Latency is added once per request the proxy reads and once per new tunnel. Requests are slowed at the client side (request body read, response body written); tunnels at the upstream connection. The API and the page never pass through the proxy and are never slowed; WebSocket frames are not throttled. Presets 3g, 4g, slow-wifi, custom; rates in kbit/s, 0 is no limit that way.

Capture from other devices (`proxy/remote.go`), the owner's rule: off by default. On, it listens for the proxy only on each unicast address of this computer (link-local skipped) at the proxy's port, read again every 10 s, beside the loopback listener. The API is never bound there. An allow list (CIDR or addresses, at least one entry to turn it on, a range holding every address refused) is checked on accept; a connection from outside it is closed before a byte is read and counted. Turning it off, or narrowing the list, closes the listeners and the connections of addresses no longer allowed. The proxy refuses to connect to its own remote listeners, and refuses a client on another device asking for this computer's loopback (by address or by a localhost name), so allowing a phone never opens local services to it. `http://formnet.cert/` is answered by the proxy itself and never resolved: a small page, `/ca.pem` and `/ca.cer` (DER) while the switch is on, 404 otherwise; the key is never read. `FORMNET_REMOTE_CAPTURE` and `FORMNET_REMOTE_ALLOW` win for a run and are not written; a change made in the page is kept in settings.json.
Loading
Loading