> For the complete documentation index, see [llms.txt](https://coldbox-security.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-security.ortusbooks.com/secure-your-app/route-middleware/ip-filtering.md).

# IP Filtering

Allow or block requests by IP address with AllowedIPs and DenyIPs.

| Middleware              | Behavior                                                |
| ----------------------- | ------------------------------------------------------- |
| `AllowedIPs@cbsecurity` | Only the listed IPs get in. Everyone else gets a `403`. |
| `DenyIPs@cbsecurity`    | The listed IPs get a `403`. Everyone else passes.       |

Lists accept IPv4, IPv6 and CIDR ranges, as a list or an array, in the route `meta`:

```javascript
// Only the office and the VPN
route( "/admin" )
    .middleware( "AllowedIPs@cbsecurity" )
    .meta( { allowedIps : "203.0.113.7,10.8.0.0/16" } )
    .to( "admin.index" )

// Block a range
route( "/api" )
    .middleware( "DenyIPs@cbsecurity" )
    .meta( { denyIps : [ "198.51.100.0/24" ] } )
    .to( "api.index" )
```

A route without its list throws `cbsecurity.MiddlewareMisconfigured` instead of silently allowing or blocking everyone.

## Behind a Proxy or Load Balancer

By default the client IP is the address that made the connection. Forwarded headers can be faked, so `X-Forwarded-For` is only honored when the connection comes from a proxy you trust:

```javascript
moduleSettings = {
    cbsecurity : {
        middleware : { trustedProxies : [ "10.0.0.0/8" ] }
    }
}
```

The header is read from the right and the first address that is not a trusted proxy is the client.

Combine IP filtering with [authentication middleware](/secure-your-app/route-middleware.md). An IP is not an identity.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox-security.ortusbooks.com/secure-your-app/route-middleware/ip-filtering.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
