Skip to content

fix: honour CLI --password and stop trusting client-supplied X-Forwarded-For - #178

Merged
dillonstreator merged 3 commits into
mainfrom
fix/cli-password-and-trust-proxy
Nov 28, 2026
Merged

dillonstreator merged 3 commits into
mainfrom
fix/cli-password-and-trust-proxy

Conversation

@dillonstreator

Copy link
Copy Markdown
Member

What was wrong

  • CLI --password did nothing (CFYI-CRYPTO-001). cfyi encrypt -p <pw> never handed the password to the client. The secret was encrypted with the URL key only, yet the CLI printed a ?p=true link and the password. Anyone with the link could read the secret, and a recipient who typed the password in the web app got "wrong password". This has been the case since the shared client SDK refactor (shared client sdk #49). Links created with cfyi encrypt -p by released CLI versions were never password-protected.
  • The API trusted X-Forwarded-For from every client (CFYI-SEC-001). With trustProxy: true, Fastify took req.ip from the left-most X-Forwarded-For entry, which the client controls. req.ip drives the IP allow-list and the per-IP rate limit, so neither held.
  • CLI --reads always failed (CFYI-UX-003). --burn defaulted to true and couldn't be turned off, and the server rejects burn plus a read count, so --reads always got "unexpected status code 400".

What changed

  • CLI: the option-to-request mapping moved into src/encrypt.ts (buildCreateInput, formatSecretUrl) and now passes p. Added --no-burn. --reads turns off the default burn and is rejected locally together with an explicit --burn. CLI README documents this.
  • Server: new TRUST_PROXY setting, a comma-separated list of proxy IPs, CIDR blocks or proxy-addr presets (loopback, linklocal, uniquelocal). It defaults to empty, which means the socket address is used and forwarded headers are ignored. true and hop counts are rejected at startup: true is the old behaviour, and Fastify 5.12 treats a hop count as trusting nothing, because it can't check the immediate peer.
  • Deploy/docs: the compose file passes TRUST_PROXY through, with a comment. Compose publishes the API port directly and nginx serves only the web app, so the default is the correct setting for the shipped deploy and nginx needs no change. README has a new "Running the API behind a reverse proxy" section, .env-example lists the variable, and SPECIFICATION §7.2.1 adds it as a MUST NOT trust other peers.
  • Docs (CFYI-CRYPTO-002, docs part only): SECURITY.md gets a short "Threat Model and Limits" section, and SPECIFICATION §6.1 notes that browser E2EE doesn't cover whoever serves the client code, pointing to the CLI and desktop app.
  • Changesets: @crypt.fyi/cli patch, @crypt.fyi/server minor (operators behind a proxy must now set TRUST_PROXY).

How it was tested

  • pnpm install --frozen-lockfile, pnpm build, pnpm typecheck, pnpm lint (0 errors; the existing core no-explicit-any warning), pnpm format:check: all pass.
  • Tests: core 65, cli 22 (7 new), extension 14, desktop 58, theme 12, web 6: all pass. Server: 30 pass (3 new), run against a temporary Redis container.
  • New server tests: an IP-restricted entry returns 404 when the client sends a matching X-Forwarded-For with the default config. With trustProxy: ['loopback'], a forwarded IP is honoured, but a client-supplied entry before the proxy-appended one is not. TRUST_PROXY parsing accepts lists and rejects true and 1. With trustProxy: true restored, both behaviour tests fail.
  • Ran the audit's CLI repro against the rebuilt CLI and a stub API. -p now sends passwordAlgorithm=ml-kem-768-argon2 and a 64-char v2 hash, and prints a 2.-prefixed key. -r 3 sends b=false rc=3.
  • pnpm test:e2e not run.

For the reviewer / owner

  • Before deploying the hosted API, set TRUST_PROXY to the edge proxy's addresses. Otherwise every request shares the proxy's IP: one 10 req/min bucket for everyone, and IP restrictions see the proxy. I don't know the hosting platform's proxy ranges. The proxy must append the real client address to X-Forwarded-For.
  • Consider a GitHub security advisory and a release note for CLI users about -p links created with earlier versions.

Left out of this PR

  • CRYPTO-002 bundle integrity (published hashes, reproducible builds): needs a release-process decision. Only the documentation caveat is here.
  • The other findings in the audit are in separate PRs or listed there.

The encrypt command never passed --password to the client, so links it
printed as password-protected were encrypted with the URL key alone.
Map the options in one tested function, add --no-burn, and let --reads
turn off the default burn instead of sending a combination the server
rejects.
trustProxy: true took the client IP from the left-most X-Forwarded-For
entry, which any client controls, so IP restrictions and the rate limit
could be bypassed. Add TRUST_PROXY (proxy IPs, CIDRs or proxy-addr
presets) and use the socket address when it is unset.
@dillonstreator
dillonstreator merged commit 30b2555 into main Nov 28, 2026
11 checks passed
@dillonstreator
dillonstreator deleted the fix/cli-password-and-trust-proxy branch November 28, 2026 19:08
@github-actions github-actions Bot mentioned this pull request Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant