# Flag VPN and data center traffic

Automated signups and fraud often arrive through infrastructure that hides where they come from: servers in data centers, Tor, VPNs, proxies. The same infrastructure carries ordinary people too: someone on a corporate VPN, a privacy-minded user, a traveler. This guide uses the IP endpoint to tell you which situation you are probably in, and to respond in proportion.

## What the flags say, and what they do not

| Signal | Set when | What it suggests | What it does not prove |
|---|---|---|---|
| `flags.datacenter` | The network is classified as hosting (`asn.type: "hosting"`) | The traffic comes from a server: a script, a bot, a cloud desktop, a proxy | That the person is not real: remote desktops and some privacy services run in data centers too |
| `flags.tor` | The address is on the Tor Project's list of exit nodes | The person uses Tor to hide their address | Bad intent: journalists, researchers and people under censorship use Tor |
| `flags.vpn` | The address belongs to a known VPN provider's network | The person uses a commercial VPN | Bad intent: VPNs are everyday privacy and work tools |
| `flags.proxy` | The address belongs to a known proxy network | Traffic is relayed by a proxy | Much: residential proxies, which route traffic through home connections, are generally not detectable |
| `risk.level` | Computed from the flags | How much the signals add up | Anything on its own |

Two rules follow:

- **A `false` flag means "not detected", not "clean".** VPN and proxy detection is best effort.
- **An IP address identifies a network, not a person.** Many people can share one address, and one person changes address when they move between networks.

## Use risk.level to choose friction

`risk.level` is `low` under 30, `medium` from 30 to 69 and `high` from 70. [IP risk score](/docs/ip-risk-score) shows how the score is computed.

| `risk.level` | Suggested response |
|---|---|
| `low` | Nothing. Let the person through. |
| `medium` | Nothing at signup. Add a check before actions that cost you something: confirm the email before granting trial credits, or show a challenge before a high-value action. |
| `high` | Ask for an extra step: confirm the email or phone number before the account becomes active, or send the account to manual review. |

Whatever the level, prefer friction over walls. A legitimate user you block may never come back; one you ask to confirm an email address loses a few seconds. Keep outright blocking for patterns you have confirmed on your own traffic.

Tor deserves its own decision. Some services welcome Tor users on purpose; others see mostly abuse from it. `flags.tor` lets you apply your policy without guessing.

## Read the right client address

The lookup is only as good as the address you send:

- **Behind Cloudflare**, read the `CF-Connecting-IP` header.
- **Behind a load balancer or reverse proxy**, read the address it appends to `X-Forwarded-For`, and configure your framework to trust that proxy only. In Express, `app.set('trust proxy', 1)` trusts one proxy hop and makes `req.ip` the client address.
- **Never trust `X-Forwarded-For` blindly** when your server is reachable directly: anyone can send that header with any value.
- **In local development**, the client address is `127.0.0.1` or `::1`. The API answers `422 unprocessable_input` for such addresses and does not bill the call. Treat it as "no signal".

## The code

A function that looks up an address and returns a level and the flags that are set, failing open on errors:

```javascript
export async function ipSignal(ip) {
  const response = await fetch('https://api.qelka.com/v1/ip', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ ip }),
    signal: AbortSignal.timeout(3000),
  }).catch(() => null)
  if (!response?.ok) return { level: 'unknown', flags: [] }
  const result = await response.json()
  const flags = Object.entries(result.flags)
    .filter(([, isSet]) => isSet)
    .map(([name]) => name)
  return { level: result.risk.level, flags, network: result.asn?.org ?? null }
}

export function frictionFor(signal) {
  if (signal.flags.includes('tor') || signal.level === 'high') return 'verify'
  if (signal.level === 'medium') return 'confirm-before-rewards'
  return 'none'
}
```

`ipSignal` returns `level: 'unknown'` for private addresses, timeouts and errors, and `frictionFor` treats that like `low`. Used at signup, with Express behind one proxy:

```javascript
app.set('trust proxy', 1)

app.post('/signup', express.json(), async (req, res) => {
  const signal = await ipSignal(req.ip)
  const friction = frictionFor(signal)
  const user = await createUser({ ...req.body, friction, ipFlags: signal.flags })
  res.status(201).json({ id: user.id, nextStep: friction === 'verify' ? 'confirm-email' : 'welcome' })
})
```

`createUser` stands for your own account creation code. Store the flags with the account: they are useful later, when you investigate abuse.

The same lookup in Python:

```python
import os

import requests


def ip_signal(ip):
    try:
        response = requests.post(
            "https://api.qelka.com/v1/ip",
            headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
            json={"ip": ip},
            timeout=3,
        )
    except requests.RequestException:
        return {"level": "unknown", "flags": []}
    if not response.ok:
        return {"level": "unknown", "flags": []}
    result = response.json()
    flags = [name for name, is_set in result["flags"].items() if is_set]
    return {"level": result["risk"]["level"], "flags": flags}
```

## Look up each address once per session

Each lookup costs 1 credit, cached or not. Look up the address at the moments that matter, such as signup, login or checkout, and keep the result with the session. Do not look it up on every page view.

## Measure before you enforce

Before you turn on friction, run in shadow mode for a while: compute the decision, log it next to the account, and do nothing else. Then compare with the accounts you later confirmed as abusive or legitimate. You will see how many real users each rule would have slowed down, and you can tune the thresholds on your own traffic rather than on assumptions.

## Test it

With a test key, the documentation address ranges return fixed profiles, so you can exercise each branch without real traffic: `192.0.2.10` is a residential address with a `low` risk, `203.0.113.10` a data center address with a `medium` risk, `198.51.100.10` a VPN and `198.51.100.200` a Tor exit node, both `high`. [Test mode](/docs/test-mode) lists them all.

## Related

- [IP lookup reference](/docs/api-reference/ip): every field, the network types and the special-purpose addresses.
- [Validate signup forms](/docs/guides/validate-signup-forms): the IP check combined with email and phone in one call.
- Free tools: [VPN and proxy detection](/tools/vpn-proxy-detection), [IP lookup](/tools/ip-lookup), [ASN lookup](/tools/asn-lookup).
