Introducing a new way to review your PRs.

Read the announcement

jdx / fnox

encrypted/remote secret manager

View on GitHub

27 documents · Updated Nov 23, 2026

docs / secret-exposure-safeguards

Secret exposure safeguards

fnox limits where secret values can go while it runs commands or brokers network requests. It selects only the values needed for a run, replaces secrets with safe placeholders at the proxy boundary, removes ambient credentials, redacts supported output, and can place the command inside an OS sandbox. This page extends Execution and environment integration with the safeguards that protect those boundaries. For adjacent command, environment, and shell behavior, see Command execution and environment injection, Environment inspection and serialization, and Shell hooks and activation.

Exposure control model

Secret protection uses several boundaries because no single boundary covers every way a process can read or send a value. Selection limits resolution, environment cleanup limits inherited access, placeholders keep raw values out of proxy clients, redaction protects copied output, and sandboxing blocks routes around the proxy.

Secret selection

fnox exec --only and --except control which secrets and lease-produced variables a run resolves and injects. --only narrows the set, while --except removes matching names after inclusion. Provider dependencies still resolve when a selected secret needs them, but dependencies are not passed to the command unless they are selected themselves. Unknown names and --only patterns that match nothing fail early. References: src/secret_filter.rs• L1-6, src/secret_filter.rs• L66-95, src/child_env.rs• L225-283, src/…/exec.rs• L132-189

The filter applies before provider work. This means an unrelated broken or unreachable provider does not fail a run that does not need its secret. Lease selection follows the same boundary: a lease runs only when its produced variable is in scope, and command leases are skipped when a filter is active because their inputs are not statically known. References: src/secret_filter.rs• L87-95, src/child_env.rs• L225-283, src/…/exec.rs• L181-189

Child environment scrub

The command boundary removes credentials that fnox uses to decrypt values or access providers before the target starts. It also removes configured secrets already present in the parent environment, common provider credential-chain variables, and selected runtime sockets when the OS sandbox is active. Explicitly selected values and lease credentials are added after this scrub, so an intentional configured value can still cross the boundary without exposing the ambient resolver credentials. References: src/child_env.rs• L43-53, src/…/proxy.rs• L384-405, src/…/exec.rs• L191-210

Process inspection boundary

The proxy reduces same-user access to its memory and environment while it holds live credentials. This protects the broker during command setup, although the executed child returns to the platform default after it starts its own program. References: src/…/plan.rs• L12-35

Output redaction

Output redaction protects secret values that a child writes to a non-terminal stream. It is an output filter rather than a process sandbox: it can replace values that appear in plain output, but it cannot stop a command from transforming a secret before it prints it or sending the value through another channel.

Command output redaction

fnox exec --redact replaces resolved values with [REDACTED] in piped or redirected stdout and stderr. Terminal streams remain unchanged so interactive programs keep their normal behavior. Empty and very short values are not added to the redaction set because replacing common short text would damage ordinary output. References: src/…/exec.rs• L26-30, src/…/exec.rs• L67-87, src/…/exec.rs• L224-251, src/redact.rs• L13-45

The filter works across stream chunks and uses the longest matching value when secrets overlap. It keeps only a bounded tail until the next read proves that the tail is not the start of a secret, then writes the safe output to the original stream. This preserves streaming behavior while avoiding a leak when a value crosses a read boundary. References: src/redact.rs• L46-85, src/redact.rs• L88-143

Redaction is not available with fnox exec --replace when it would need to capture output. Replacement gives the target direct ownership of the fnox process, so the normal child-process output filter cannot run. References: src/…/exec.rs• L121-160, src/…/exec.rs• L213-225

Proxy response redaction

The credential proxy keeps raw values out of the command by giving it placeholders. It replaces current and recently replaced values in upstream response headers and bodies before sending them back to the command. Query-based rules also cover URL-escaped forms because a server can echo a credential through a redirect or response body. References: src/…/values.rs• L19-25, src/…/values.rs• L107-137, src/…/policy.rs• L181-191, src/…/policy.rs• L248-272, src/…/server.rs• L473-505

The proxy requests identity-encoded upstream responses and rejects other content encodings because it cannot safely inspect compressed content. It redacts headers and streams the body in chunks. A bounded tail is held between chunks so a value split across reads is still replaced, while memory does not grow with the full response. References: src/…/server.rs• L462-495, src/…/server.rs• L533-595, src/…/policy.rs• L692-723

Proxy boundary

fnox proxy run brokers selected credentials for approved HTTPS requests instead of placing the real values in the child environment. The child receives a placeholder, proxy settings, a per-run proxy password, and a session trust bundle. The proxy replaces the placeholder only when the request matches its configured destination and route rules.

Placeholder substitution

Each proxied secret has a unique placeholder that differs from the real value. A matching request can carry that placeholder in the configured header or query parameter, but not in the path or in another target. The proxy rejects repeated, ambiguous, or out-of-route placeholders, then sends the request upstream with the real value. Placeholder values cannot overlap with each other or with a real secret, so one rule cannot trigger another rule by accident. References: src/…/plan.rs• L109-235, src/…/policy.rs• L462-565, src/…/policy.rs• L569-600, src/…/server.rs• L410-433

The proxy resolves only rule secrets and the provider dependencies needed to obtain them. Before launch, the command receives placeholders rather than raw values. The proxy also requires a per-session authorization token, so an unrelated local user cannot use the listener to obtain credential injection. References: src/…/plan.rs• L237-290, src/…/policy.rs• L329-359, src/…/server.rs• L247-291

Destination policy

The proxy checks the resolved address and port before it connects upstream. Public addresses are allowed by default, while non-public networks require an explicit allow_private entry. An entry can allow a whole network or limit access to one port. The proxy connects to the approved resolved addresses rather than performing a second lookup, which prevents a later name change from redirecting the request to a refused address. References: src/…/destination.rs• L6-51, src/…/destination.rs• L69-135, src/…/server.rs• L310-353

Credential injection is narrower than ordinary tunneling. A rule must match the configured domain, method, path, and header or query target, and credential-bearing requests must use HTTPS on port 443. Destinations without a rule can only use the separate tunnel policy. References: src/…/policy.rs• L76-105, src/…/policy.rs• L335-342, src/…/server.rs• L310-365

Request and audit limits

The proxy accepts only authenticated HTTPS CONNECT clients for credential injection. It bounds request bodies, removes hop-by-hop headers, and keeps audit targets free of user information and query strings. These limits reduce both resource use and the chance that logs or forwarded headers carry credentials. References: src/…/mod.rs• L31-35, src/…/policy.rs• L135-158, src/…/server.rs• L264-291, src/…/server.rs• L399-495, src/…/server.rs• L633-647

When audit records are enabled, the proxy redacts values from forwarded and refused request details before it records them. A configured audit sink receives queued records instead of sending them to stderr, which keeps proxy activity out of a full-screen child; if the sink is closed, the proxy reports the record through tracing so shutdown does not lose it. References: src/…/plan.rs• L67-73, src/…/policy.rs• L395-460

Value lifecycle

The proxy can start with a rule secret that is not set. It gives the child the placeholder, then tries to resolve the secret when a matching request needs it. A value set during the session can therefore become usable without restarting the proxy, while a failed or slow lookup leaves the request refused. References: src/…/values.rs• L1-17, src/…/values.rs• L54-69, src/…/values.rs• L187-289, src/…/policy.rs• L304-327, src/…/policy.rs• L529-537

When a value changes or is forgotten, the old value stays in the response redaction set for the rest of the session. This covers responses that still finish after the proxy has moved to a new value. References: src/…/values.rs• L35-42, src/…/values.rs• L107-137, src/…/values.rs• L170-185

Lease-backed credentials

Proxy rules can name a lease instead of a stored secret. The proxy mints the lease when a matching request first needs it, shares it while it is valid, and renews it before expiry. It validates every produced credential before making any of them usable, so a partial or expired lease cannot cross the request boundary. References: src/…/leases.rs• L1-10, src/…/leases.rs• L211-229, src/…/leases.rs• L567-640

The proxy records minted leases for later revocation without offering their credentials to commands or to ordinary fnox exec runs. At shutdown it stops new minting, removes the values from use, and revokes the leases it created. Errors that may contain parent credentials are scrubbed before they reach the log. References: src/…/leases.rs• L72-84, src/…/leases.rs• L255-316, src/…/leases.rs• L437-465, src/…/leases.rs• L643-695

MCP value control

The proxy's MCP bridge exposes rule metadata and placeholders to fnox mcp, not live secret values. The bridge can accept a value that the user has just entered or forget a value for later re-resolution, while the proxy keeps the value inside its own session. References: src/…/handle.rs• L1-3, src/…/handle.rs• L41-97, src/…/plan.rs• L81-91, src/…/server.rs• L292-303

Sandbox boundary

The optional proxy sandbox prevents a child from bypassing the proxy through direct network access, local credential stores, fnox configuration, or writable files outside the project. --sandbox is strict: if the host cannot provide the required OS sandbox, fnox fails before resolving secrets instead of running the command without protection.

Filesystem and network limits

The sandbox gives the command a writable working directory and configured write paths. It hides fnox configuration and key files, common credential directories, and selected deny-read paths. It also protects configuration files and Git hooks from writes because changes there could affect later commands outside the sandbox. The network is isolated, and only the proxy route is made available. References: src/sandbox.rs• L1-20, src/sandbox.rs• L37-83, src/sandbox.rs• L104-181, src/sandbox.rs• L369-395, src/sandbox.rs• L462-496

The policy is built from the active working directory, profile configuration, provider key paths, and credential-related environment paths. An allowed read path does not become writable, and missing protected paths are masked so the child cannot create them for later use. References: src/sandbox.rs• L184-238, src/sandbox.rs• L242-288, src/sandbox.rs• L302-339

Sandbox launch boundary

The sandbox is prepared before secret resolution. On Linux it uses bubblewrap with a separate network namespace and a Unix socket mounted into the sandbox; on macOS it uses the system seatbelt profile and the proxy's loopback port. Unsupported platforms and missing sandbox tools are errors. References: src/…/proxy.rs• L301-320, src/sandbox.rs• L512-606, src/sandbox.rs• L612-645

Bridge behavior

The bridge makes the sandboxed proxy usable by normal HTTP clients without exposing the host socket directly. It listens on a loopback TCP port inside the sandbox and forwards each connection to the proxy's Unix socket outside the sandbox. The proxy listener accepts only loopback TCP clients or its restricted Unix socket, and each connection still needs the session token.

Proxy connection flow

The following flow shows how a child request reaches the proxy while direct host network access remains unavailable.

flowchart LR
    A[Child HTTP client] -->|127.0.0.1 proxy port| B[Sandbox bridge]
    B -->|Restricted Unix socket| C[fnox proxy]
    C -->|Approved HTTPS request with real credential| D[Allowed upstream]
    C -->|Redacted response| B
    B --> A

The bridge runs the requested command as its child and returns the command's exit status. It forwards bytes in both directions and closes each side when the stream ends. The proxy URL and trust-bundle path passed into the sandbox point at the bridge's in-sandbox view, not at the host socket. References: src/…/sandbox_bridge.rs• L6-11, src/…/sandbox_bridge.rs• L27-67, src/…/sandbox_bridge.rs• L71-92, src/…/server.rs• L6-45, src/…/server.rs• L107-194, src/sandbox.rs• L422-459, src/sandbox.rs• L563-599

The proxy creates a session-specific certificate authority and adds it to a trust bundle with the native roots given to the child. This lets the proxy inspect the HTTPS request for rule checks and value substitution while the upstream client uses the normal native trust roots. The certificates include the extensions required by strict TLS clients. References: src/…/ca.rs• L6-57, src/…/ca.rs• L61-92, src/…/server.rs• L107-185, src/…/server.rs• L356-374, src/…/tests.rs• L1899-1939

Sandbox cleanup

Linux may create empty host-side mount points for protected paths that did not exist before launch. fnox removes only those empty placeholders after the command exits or is interrupted, so the sandbox does not leave false configuration or hook files behind. References: src/sandbox.rs• L315-339, src/…/proxy.rs• L432-461

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep --only and --except validation aligned with secret names, lease-produced names, and provider dependency resolution. A change can silently widen the set of values fetched.
  • Preserve the order of environment removal and explicit injection. Reversing it can leak resolver credentials or replace a brokered placeholder with a raw value.
  • Keep proxy placeholder checks aligned with the configured header or query target. A new request location must not become an unvalidated path for raw credentials.
  • Keep proxy response redaction, streaming framing, and content-encoding checks aligned. Returning a new response form without a safe redaction path can expose a value or corrupt the client stream.
  • Keep destination resolution and the allow_private policy aligned. A new address family, lookup path, or port rule must not bypass the non-public network check.
  • Update both Linux and macOS sandbox rules when changing writable, hidden, or proxy-reachable paths.
  • Keep sandbox preparation before secret resolution and keep bridge paths consistent with the launch environment.
  • Preserve mount-point cleanup on normal exit and interruption. Empty masks must not remain as real project files.
  • Keep lease minting, value replacement, ledger recording, and shutdown revocation as one lifecycle. A new credential path must not skip validation or leave a usable lease untracked.
  • Keep MCP relay metadata and reserved environment names separate from rule placeholders. A rule must not disable the bridge or expose live values through its control path.
  • Keep the proxy CA, child trust bundle, and native trust roots aligned. A change that breaks strict certificate validation can stop clients before request policy runs.
  • Keep audit routing and redaction aligned. A new request or refusal field must not send raw user input or secret values to the audit log or fallback stderr path.

Important failure modes

TriggerConsequenceGuard
A filter names an unknown secret or an empty-match --only globThe run stops before it resolves or starts the commandValidate names against known secrets and lease-produced variables.
A child inherits provider credentials or fnox key variablesIt can bypass the intended provider or decrypt configuration outside fnox's controlScrub ambient credentials before adding explicit command values.
A proxy client omits or sends an invalid session tokenThe proxy refuses the connection before it can inject a credentialRequire the per-session Proxy-Authorization value.
A placeholder appears more than once, in a path, or outside its configured targetThe request is rejected instead of sending a credential to an unintended locationCheck occurrence count, route, header, query target, and path encoding before substitution.
A destination resolves only to a non-public address or to a port not allowed by allow_privateThe proxy refuses the connection and protects local or metadata servicesApply the address and port policy to every resolved address.
The proxy receives an encoded upstream responseThe response is rejected because raw values cannot be safely redactedRequire an identity response encoding before returning the response.
A lease cannot be minted, has expired, or fails validationThe request is refused without injecting a partial or stale credentialValidate all produced values and never inject an expired lease.
The sandbox tool is missing or cannot startNo command runs without the requested boundaryPrepare and probe the sandbox before resolving secrets.
A command uses a proxy without --sandboxSame-user code can bypass the proxy or read local credential storesUse --sandbox when the proxy must be the only network and credential route.
A protected path does not exist before launchThe child could create it for later useMask missing configuration, key, and Git protection paths.
A secret is shorter than three characters or is emptyIt remains visible in command outputDo not treat output redaction as complete protection; use the sandbox and avoid printing values.
A request body exceeds the proxy limit or a response stream ends before its final chunkThe request is refused or the client sees an incomplete responseApply the body limit and complete streamed response framing.
Audit routing fails or a new audit field is not redactedRequest details can be lost at shutdown or expose user input in logsQueue records through the audit sink, fall back safely after closure, and redact values before recording.

Key files

FileWhy to read it
src/secret_filter.rsDefines per-run secret and lease selection rules.
src/child_env.rsConnects selection, environment scrubbing, lease handling, and command plans.
src/…/exec.rsShows command-boundary setup and output redaction.
src/redact.rsDefines streaming replacement behavior for secret values.
src/…/plan.rsTurns proxy rules into placeholders, routes, and a protected session policy. It also connects proxy audit records to the audit sink.
src/…/policy.rsDefines request authorization, value redaction, safe request logging, and audit routing.
src/…/server.rsShows proxy authentication, HTTPS interception, upstream forwarding, request limits, streamed response redaction, and listener behavior.
src/…/values.rsDefines pending values, replacement, and retained redaction state.
src/…/leases.rsDefines lease minting, renewal, ledger recording, error scrubbing, and revocation.
src/…/destination.rsDefines public-address checks, explicit private-network access, and optional port limits.
src/…/ca.rsDefines the session trust bundle used for HTTPS inspection.
src/…/handle.rsDefines the limited value-control surface available to the MCP relay.
src/…/tests.rsDemonstrates the contracts for placeholder placement, encoded query redaction, streamed responses, listener access, destination limits, leases, and strict TLS certificates.
src/sandbox.rsDefines filesystem, network, platform, and launch boundaries.
src/…/sandbox_bridge.rsProvides the in-sandbox TCP-to-Unix proxy connection.
test/proxy_sandbox.batsVerifies proxy-only networking, hidden files, write limits, placeholders, status passing, and cleanup.