---
title: "Take the client address only from proxies · Agent Wranglers"
url: https://agentwranglers.se/playbook/application-security/limits-and-business-logic/trusted-proxy-client-address
id: APS-50
level: Required
risk: takeover
updated: 2026-10-27
build: a2a6bdfed830
tokens: 970
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Take the client address only from proxies you run

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Limits and business logic](https://agentwranglers.se/playbook/application-security/limits-and-business-logic.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: APS-50
- Level: Required
- Chapter: [Limits and business logic](https://agentwranglers.se/playbook/application-security/limits-and-business-logic.md)
- Rule: Read the client address from `X-Forwarded-For` or `Forwarded` only when the request came through your own proxy. Take the entry that proxy added, and key every rate limit, ban and log on that one value.
- Check: On the test copy, send 30 failed logins for one test account in a minute, each with a different random `X-Forwarded-For` value. Tries after the fifth are still slowed, and the log shows one client address for all 30. A request to the app's port from outside the proxy gets no answer.
- Risk: An account or system taken over
- How: Any client can send these headers with a made-up address. An app that trusts the first entry lets an attacker claim a new address on every request. Each login guess and sign-up then looks like a new visitor, and every per-address limit is gone. RFC 7239 says the header cannot be relied upon, and that only proxies you have checked may be trusted. Count the proxies in front of the app, such as one load balancer. Set the framework's trusted proxy setting to that count or to their addresses. Read the list from the right and skip only your own proxies. Use the same function for [Slow down password guessing](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/login-guessing.md) and [Limit requests per client](https://agentwranglers.se/playbook/application-security/limits-and-business-logic/rate-limits.md). Let only the proxy reach the app's port.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
const PROXIES_IN_FRONT = 1;

app.set('trust proxy', PROXIES_IN_FRONT);
app.use((req, res, next) => {
  req.clientAddress = req.ip;
  next();
});
```

### Python example

```python
from werkzeug.middleware.proxy_fix import ProxyFix

PROXIES_IN_FRONT = 1

app.wsgi_app = ProxyFix(app.wsgi_app, x_for=PROXIES_IN_FRONT)
```

## Sources

- [RFC 7239 Forwarded HTTP Extension, section 8.1](https://www.rfc-editor.org/rfc/rfc7239#section-8.1)

## Related rules

- APS-10 [Slow down password guessing](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/login-guessing.md) in Application security
- APS-49 [Limit how often anyone can call your APIs](https://agentwranglers.se/playbook/application-security/limits-and-business-logic/rate-limits.md) in Application security

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/application-security/limits-and-business-logic/trusted-proxy-client-address">Agent Wranglers application security playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Limit how often anyone can call your APIs](https://agentwranglers.se/playbook/application-security/limits-and-business-logic/rate-limits.md)
- Next: [Keep regular expressions from stalling the server](https://agentwranglers.se/playbook/application-security/limits-and-business-logic/regex-denial-of-service.md)
- [Limits and business logic](https://agentwranglers.se/playbook/application-security/limits-and-business-logic.md)
