Repository navigation
fix: honour CLI --password and stop trusting client-supplied X-Forwarded-For - #178
Merged
Merged
Conversation
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.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
--passworddid 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=truelink 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 withcfyi encrypt -pby released CLI versions were never password-protected.X-Forwarded-Forfrom every client (CFYI-SEC-001). WithtrustProxy: true, Fastify tookreq.ipfrom the left-mostX-Forwarded-Forentry, which the client controls.req.ipdrives the IP allow-list and the per-IP rate limit, so neither held.--readsalways failed (CFYI-UX-003).--burndefaulted to true and couldn't be turned off, and the server rejects burn plus a read count, so--readsalways got "unexpected status code 400".What changed
src/encrypt.ts(buildCreateInput,formatSecretUrl) and now passesp. Added--no-burn.--readsturns off the default burn and is rejected locally together with an explicit--burn. CLI README documents this.TRUST_PROXYsetting, 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.trueand hop counts are rejected at startup:trueis the old behaviour, and Fastify 5.12 treats a hop count as trusting nothing, because it can't check the immediate peer.TRUST_PROXYthrough, 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-examplelists the variable, and SPECIFICATION §7.2.1 adds it as a MUST NOT trust other peers.@crypt.fyi/clipatch,@crypt.fyi/serverminor (operators behind a proxy must now setTRUST_PROXY).How it was tested
pnpm install --frozen-lockfile,pnpm build,pnpm typecheck,pnpm lint(0 errors; the existing coreno-explicit-anywarning),pnpm format:check: all pass.X-Forwarded-Forwith the default config. WithtrustProxy: ['loopback'], a forwarded IP is honoured, but a client-supplied entry before the proxy-appended one is not.TRUST_PROXYparsing accepts lists and rejectstrueand1. WithtrustProxy: truerestored, both behaviour tests fail.-pnow sendspasswordAlgorithm=ml-kem-768-argon2and a 64-char v2 hash, and prints a2.-prefixed key.-r 3sendsb=false rc=3.pnpm test:e2enot run.For the reviewer / owner
TRUST_PROXYto 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 toX-Forwarded-For.-plinks created with earlier versions.Left out of this PR