agentleFS
KhaledSaeed18KhaledSaeed18/dotclaude/skills/deployment/proxy-client-address/SKILL.md

proxy-client-address

Skill5 starsChanged 4 months agoMITView on GitHub

Forward the real client address from a server-side proxy to a backend without trusting forgeable headers. Use when an API behind a BFF or reverse proxy rate-limits or audits every user as one address.

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never trust X-Forwarded-For from the client side: Only the entry the edge proxy appended is real.

    line 11

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

When a browser calls a front-end server that forwards to an API, the API's peer is the front-end for every user: one rate-limit bucket and one audit address for everyone. Fix it with a named address the API believes only next to a shared secret, derived from the one forwarded header the edge proxy wrote itself.

Hard rules: never break these

  • Never trust X-Forwarded-For from the client side. Only the entry the edge proxy appended is real; confirm which entry that is for the proxy in front of you before relying on it.
  • The secret is runtime, server-only, identical on both sides, generated by the owner (openssl rand -base64 32), pasted into both deployments, never in a repository or a client bundle.
  • Strip the headers on the way in. The front-end deletes any x-<app>-proxy-secret or x-<app>-client-ip a browser sent before setting its own; the API deletes both after reading them.
  • Compare the secret in constant time on digests, so length and content leak nothing.
  • Without the secret, behave as before. The front-end falls back to the plain rewrite; the API falls back to req.ip. Rollout is safe in any order.

Step 1: Establish the proxy's behaviour

Read the edge proxy's configuration (Traefik: docker inspect coolify-proxy --format '{{json .Args}}' | grep -i forwarded). With no trusted IPs configured, Traefik discards client-sent X-Forwarded-* and writes the peer address itself, so the last entry is the client; a platform edge behaves the same. If trusted IPs or insecure are set, the client's forged entries survive in front of the real one and the last entry is still the real one. A Node server does not append. Document the finding.

Step 2: Front-end side (the BFF)

In the Next.js proxy (or middleware), for /api/* requests: when the secret is configured, rewrite to the API origin with two added request headers, else return nothing and let next.config rewrites handle it. Server-side fetches (Server Components) add the same headers from next/headers. Snippets in reference/snippets.md.

Step 3: API side

A middleware early in the chain: read both headers, delete them, verify the presented secret against the configured one on SHA-256 digests with timingSafeEqual, accept the named address only if it is a valid IP, else use req.ip. Store the result on the request (req.clientIp) and make the rate limiter's key generator and the audit writer read it. trust proxy stays set for req.ip to be meaningful behind the edge.

Step 4: Roll out and prove it

  1. Ship both code sides (they are inert without the secret).
  2. Owner sets API_PROXY_SECRET on the front-end app and DASHBOARD_PROXY_SECRET (or the chosen name) on the API, same value, then redeploys both.
  3. Prove it: a request through the front-end to a non-existent API route with a forged X-Forwarded-For: 203.0.113.9, from two different networks, must be logged by the API with each real address; the same forged header plus a wrong secret sent straight to the API must be logged with the sender's address. The deploy-verification skill has the commands.

Report the proxy finding, the header names chosen, the variable names on each side, and the proof lines from the API log.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.