lminspect guide
Overview
lminspect brings mitmproxy-style HTTP and HTTPS traffic interception, on-the-fly TLS certificate minting, JSONL flow recording and replay, and the 226-signature lmcode_std_v3 standard library into a single zero-dependency Go executable. Addon scripts written in LMScript compile to compact .dslb bytecode and run inside the proxy pipeline with sub-10-millisecond startup overhead.
Proxy architecture and TLS interception modes
The proxy engine supports multiple deployment topologies and interception stages:
- Forward, reverse, and transparent proxy modes: In default regular mode (lminspect run --listen 127.0.0.1:8080), clients configure lminspect as an explicit HTTP/HTTPS proxy. Passing --mode reverse:http://backend:8000 places lminspect directly in front of an origin or mock server so clients need no proxy configuration. Transparent mode accepts redirected socket traffic.
- Dynamic SSL-Bump TLS decryption: When --ssl-bump is enabled alongside a Root CA generated by lminspect certgen (--ca-cert ca.crt --ca-key ca.key), lminspect intercepts HTTP CONNECT tunnels, extracts the target hostname, and dynamically mints and caches a leaf X.509 certificate with matching Subject Alternative Names (SANs) using Go crypto/tls.
- Declarative CLI rules vs bytecode addons: Simple traffic manipulations can be declared directly on the CLI using repeatable --redirect pattern=target_url, --route pattern=host:port, --header pattern=key:val, and --mock pattern=code:body flags. Complex stateful logic is compiled from .lms files to .dslb bytecode and loaded via --script build/addon.dslb.
- Flow hook pipeline: Each transiting HTTP transaction is wrapped in a mutable Flow object with a 16-character hexadecimal ID. Functions implementing RequestHook (@request) run before upstream forwarding and can rewrite method, URL, scheme, host, port, path, query parameters, headers, or body text, call flow.respond(status, body, content_type) to return a synthetic response immediately, or call flow.kill() to drop the connection. Functions implementing ResponseHook (@response) or FlowHook run before returning the response to the client and can rewrite status codes, reason phrases, response headers, and payloads while automatically synchronizing Content-Length.
- JSONL recording and client/server replay: Passing --record flows.jsonl streams completed flows to newline-delimited JSON. Recorded flows can be re-sent as client traffic against a staging service with lminspect replay --client flows.jsonl --target 127.0.0.1:9000, or served directly by the proxy without an upstream backend via lminspect run --replay-server flows.jsonl.
Mandatory credential sanitization boundary
Every diagnostic and persistence sink in lminspect — including --record JSONL files, flow.to_json() serialization, --tap stderr streams, replay and route error logs, and _lmcode_ println output — passes through a single mandatory sanitization barrier (proxy.SanitizeOutput):
- Wire preservation vs sanitized copy: Sanitization operates on a cloned copy of the flow in memory. Authenticated upstream requests and downstream client responses keep their exact wire credentials during live proxy execution, while raw unsanitized bytes are never spooled to disk.
- Bidirectional credential discovery: Known sensitive headers, cookies, URL userinfo, query parameters, form fields, and JSON keys (Authorization, Basic, Bearer, Proxy-Authorization, API keys, access and refresh tokens, signatures, CSRF/session tokens, passwords, secrets) are scrubbed in both request and response directions. High-entropy auth-like custom fields, common vendor token prefixes, and values matching credential-shaped environment variables supplied to the proxy process are tracked in RAM across the proxy lifetime and scrubbed even when echoed without labels or split across Server-Sent Events (SSE) data frames.
- Grammar-safe replacement markers: Redacted values are replaced with the fixed token <redacted:credential> (compatible with lmmock fixture imports), and multipart MIME boundaries use redacted-credential across headers and body parts without leaking secret length or fingerprints.
- Compression and encoding normalization: Percent-encoded, base64-encoded, quoted-printable, and doubly escaped JSON strings are inspected before export. Gzip, deflate, brotli (br), and zstd payloads are decompressed for inspection and exported unencoded with recomputed Content-Length. Unsupported, corrupt compressed, or non-UTF-8 binary bodies are replaced in full and noted in an X-Lminspect-Note response header.
Standard lmcode_std_v3 REST and CLI interfaces
Alongside RequestHook, ResponseHook, and FlowHook, lminspect embeds the full 226-signature lmcode_std_v3 standard library via github.com/lmctl-ai/lmcode-go. Scripts can expose custom control planes, flow generators, or test harnesses through the 10 standard interfaces:
- HTTP route handlers: Implement RestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, or RestHandler on functions annotated with static (@"/health") or parameterized (@"/flow/:seg") paths.
- Stateless CLI commands and flags: Implement CliOption (@"--flag") and CliCommand (@"cmd") and invoke rest_cli(args) to test flow transformations or synthetic responses in-process without starting a proxy listener.
- Session state and server lifecycle: Use rest_config("session", "global") to retain state across RestExchange.set and RestExchange.increment calls, register dynamic routes with rest_route(method, path, handler), and run or stop an embedded HTTP endpoint with rest_serve() and rest_stop().
p = _lmcode_ cli="lminspect" install="github:lmctl-ai/lminspect@latest";
@"--target"
fn opt_target(x: RestExchange) -> void implements CliOption {
x.set("target", x.query("target"));
}
@"simulate"
fn cmd_simulate(x: RestExchange) -> void implements CliCommand {
let f = inspect.new_flow("GET", "https://" + x.get("target") + "/api/items");
f.request().set_query("limit", "10");
f.respond(200, "{\"items\":[]}", "application/json");
x.send(f.request().url() + " -> " + str(f.response().status_code()));
}
rest_config("session", "global");
let res_str = rest_cli(str_split("--target=shop.internal simulate", " "));
assert(res_str == "https://shop.internal/api/items?limit=10 -> 200", "simulation mismatch");
end _lmcode_
Combining lminspect with lmmock and lmcurl
In end-to-end testing pipelines, lminspect often runs as a recording reverse proxy (--mode reverse:$LMMOCK_URL --record flows.jsonl) between a client driven by lmcurl and an upstream service or lmmock instance. Because lminspect and lmmock share the <redacted:credential> placeholder convention and JSONL flow schema, traffic recorded by lminspect can be imported directly into lmmock for deterministic offline regression testing.