# How to Detect VPN Traffic at Login Without Blocking Users

> Detect VPN at login without locking out real users: resolve the client IP, check Tor, relay and datacenter signals, and use a decision table by flow.

Source: https://digitaldtech.com/blog/how-to-detect-vpn-traffic-at-login/
Published: 2026-11-27 | Updated: 2026-11-27
Author: ST Muntaha
Publisher: DigitalD.tech (https://digitaldtech.com/)


Your login page sees a VPN address and has to decide fast. Block it and you lock out people on corporate VPNs, Apple's iCloud Private Relay or Cloudflare WARP. Ignore it and you may miss abuse that hides behind proxies.

To detect VPN at login without blocking real users, do three things. Get the client IP from proxies you trust, look it up on the server with a timeout and a planned failure mode, then map each signal to allow, step up, review or block by flow. Detection is a signal, not proof.

You will finish with a working IP resolver, a decision table, a logging rule and a test plan. It builds on [how VPN detection works](https://digitaldtech.com/blog/how-vpn-detection-works-flagged-ips/) and [how to choose a detection API](https://digitaldtech.com/blog/how-to-choose-a-vpn-detection-api/).

## Before You Start

You need four things.

- Admin access to every hop between the internet and your app (CDN, load balancer, reverse proxy) and to your framework's proxy settings.
- The addresses of those hops, because trust is set by count or by address.
- Signal sources: public files such as the Tor exit list and Apple's relay file, plus a lookup service for hosting, VPN and WARP.
- A table for decisions and a staging environment. Try every change there first.

IP addresses can be personal data, so read Step 6 before you log anything.

## Step 1: Decide What You Are Trying to Stop

Name the abuse before choosing a signal. OWASP's [Credential Stuffing Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Credential_Stuffing_Prevention_Cheat_Sheet.html) separates brute force, credential stuffing (breached username and password pairs from another site) and password spraying (one weak password across many accounts). Signup, checkout and API flows need their own one line goals, such as fake accounts, card testing or scraping.

OWASP calls multi factor authentication (MFA) the best defense and says to ask for it on suspicion: a new device or IP, an unusual location, an address tied to anonymization services such as proxy or VPN services, or one that has tried many accounts. It also says blocking IPs should not be the sole or primary defense, because it is easy to get around, and recommends a graduated response.

**Done when:** each flow has a written goal and a strongest allowed action. **Most likely failure:** a policy that says only "block VPN".

## Step 2: Get the Real Client IP From Proxies You Trust

Behind a CDN or load balancer, your app sees the proxy's address unless you restore the client's. Every later check depends on this.

**Cloudflare.** Read `CF-Connecting-IP`. [Cloudflare recommends](https://developers.cloudflare.com/fundamentals/reference/http-headers/) it, or `True-Client-IP` on Enterprise, over `X-Forwarded-For`, because both hold one address in a consistent format. Accept it only from Cloudflare's published ranges. Cloudflare's "Restoring original visitor IPs" page warns that the header could be spoofed otherwise.

**Your own proxies.** `X-Forwarded-For` lists the client first and each proxy after it, but any client can send it. [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For) says security uses must rely only on addresses added by a trusted proxy: search from the right, skipping either a configured count of proxies or addresses on a trusted list. The leftmost value suits only cases where spoofing does no harm, and if the server can be reached directly, no part of the list is trustworthy. The standard `Forwarded` header has the same limit, since RFC 7239 section 8.1 says nodes on the path, the client included, can alter it.

**Your framework.** In Express, [`trust proxy`](https://expressjs.com/en/guide/behind-proxies/) is off by default. Give it your proxy subnets or a hop count. Setting `true` takes the leftmost entry, and Express warns that the last trusted proxy must then overwrite the header. In nginx, `set_real_ip_from` names trusted hops and `real_ip_header` names the header; the realip module is not built by default, so confirm your build includes it.

An nginx sketch, where 192.0.2.0/24 is a documentation range and you would use your proxy or Cloudflare prefixes:

```
set_real_ip_from  192.0.2.0/24;
real_ip_header    CF-Connecting-IP;   # or X-Forwarded-For with: real_ip_recursive on;
```

```js
// Express sketch: list only your own proxies
app.set('trust proxy', ['loopback', '192.0.2.0/24']);
const clientIp = req.ip; // inside a request handler
```

**Done when:** a debug route prints the resolved address, and a request carrying a forged `X-Forwarded-For` still shows your real one. **Most likely failure:** the origin accepts connections that skip your proxy.

## Step 3: Choose Your Signal Sources

| Signal | Source | Limit |
|---|---|---|
| Tor exit | Bulk list at `check.torproject.org/torbulkexitlist`, or a DNS lookup that answers `127.0.0.2` for an exit ([Tor Project, 2020](https://blog.torproject.org/changes-tor-exit-list-service/)), though that post does not name the zone to query. Behind Cloudflare, `CF-IPCountry` is `T1` for Tor once the Add visitor location headers Managed Transform is on | Listed once Tor observes an exit relay using the address, so refresh your copy |
| Apple Private Relay | CSV at `mask-api.icloud.com/egress-ip-ranges.csv` (prefix, country, region, city), or the "iCloud Private Relay" organization label that Apple says most geo IP providers use ([Apple](https://developer.apple.com/icloud/prepare-your-network-for-icloud-private-relay/)) | Apple's page gives no refresh interval, so log your fetch time |
| Cloudflare WARP | No documented WARP egress list found as of 31 October 2026. Cloudflare says Cloudflare One Client egress ranges are not published, and in 2022 it said it sent consumer WARP egress geolocation to database providers. A Cloudflare conference slide names a geolocation file for its own addresses at `api.cloudflare.com/local-ip-ranges.csv`, which we could not read or confirm covers WARP | Depend on your lookup provider. In DNS only mode WARP does not tunnel traffic |
| Hosting range | Ranges some providers publish (OWASP), plus vendor ASN data | Says where an address lives, not why it is used |
| Commercial VPN or proxy | A lookup vendor or your own research | No official list we found, and coverage varies |
| Residential proxy | No public list we found | Google's January 2026 report says such networks create significant challenges for defenders who try to detect and block malicious activity |

Open the Tor and Apple files and check their format before writing a parser. [IPLogs](https://digitaldtech.com/products/iplogs/) is our own free VPN, proxy and Tor IP checker with a public REST API and a 0 to 100 threat score, and its product page says it flags datacenter ranges, Apple Private Relay and Cloudflare WARP. Weigh that accordingly and test it on your traffic like any other source.

**Done when:** you can say which signal comes from which source and how old it is. **Most likely failure:** treating one vendor's label as fact.

## Step 4: Look Up on the Server, With a Timeout and a Failure Mode

OWASP warns that client side defenses can be spoofed or bypassed, so call the lookup from your backend. Set a hard timeout well inside your login time budget and decide in advance what a timeout or error means.

```js
// Sketch only. LOOKUP_URL and the answer's fields are placeholders for your provider.
async function ipSignals(ip) {
  try {
    const res = await fetch(`${LOOKUP_URL}?ip=${encodeURIComponent(ip)}`, {
      signal: AbortSignal.timeout(300), // milliseconds
    });
    if (!res.ok) return { status: 'error' };
    return { ...(await res.json()), status: 'ok' };
  } catch (err) {
    return { status: err.name === 'TimeoutError' ? 'timeout' : 'error' };
  }
}
```

Fail open lets the request continue on your other signals. Fail closed stops it or sends it to review. Our reading: fail open for login and signup, where a lockout hits a real customer, and fail closed to review for high value checkout. The cost arithmetic is in our [detection API guide](https://digitaldtech.com/blog/how-to-choose-a-vpn-detection-api/).

**Done when:** switching the lookup off in staging makes each flow take its fallback within the timeout. **Most likely failure:** no timeout, so a slow vendor slows every login.

## Step 5: Map Signals to Actions by Flow

Allow means the IP alone changes nothing and other signals still count. The table is our reading of the sources below it, not a standard.

| Signal | Login | Signup | Checkout | API |
|---|---|---|---|---|
| None | Allow | Allow | Allow | Allow |
| Apple Private Relay | Allow | Allow | Allow | Allow |
| Cloudflare WARP | Allow | Allow | Allow | Allow |
| Commercial VPN | Allow, step up on a new device | Allow, limit new account privileges | Step up | Allow |
| Tor exit | Step up | Step up, limit new account privileges | Review | Rate limit, registered keys for sensitive routes |
| Hosting range | Step up, then remember the device | Step up | Review | Allow with a valid key |
| Residential proxy (suspected) | Step up | Review | Review | Rate limit |

Block only when a signal is joined by behavior, such as a burst of failed passwords across many accounts from one address, and give the block an expiry. Keep blocks as narrow as the evidence. Relay, carrier and corporate VPN addresses are shared, and corporate VPNs often exit from hosting ranges, so prefer step up or per account limits there. Step up means a check the user can complete, such as MFA or a code to the verified email. Review means a person decides within a stated time. Neither should become a silent hold.

Why these cells. Apple says many relay users can share one address, suggests treating it like carrier grade NAT, and warns that IP based fraud detection might need adjusting. Cloudflare says WARP replaces your address with a Cloudflare one that reflects your approximate location. The Tor Project's [advice to site operators](https://support.torproject.org/abuse/ban-tor/) is to limit features such as posting to registered users instead of banning. OWASP suggests CAPTCHAs for hosting provider traffic and weighing residential against hosting. Our reading: server to server API calls naturally come from datacenters, so that signal is weak there.

**Done when:** every cell has an owner and a reason code. **Most likely failure:** a datacenter rule applied to API traffic.

## Step 6: Cache and Log Without Overcollecting

Cache verdicts for minutes to hours (our reading) and refresh list files on a schedule. Store the decision, the reason codes and the list or vendor version, so support can explain it and tests can replay it. OWASP also suggests considering an account's IP authentication history, and says that if a recent address is later added to a block or mitigation list it may be appropriate to lock the account and notify the user. Our reading: treat that as a reason to verify, not proof of compromise, and set a retention limit for the history.

Privacy law touches this. The European Commission lists an IP address among its examples of personal data. In [Breyer](https://eur-lex.europa.eu/legal-content/EN/TXT/HTML/?uri=CELEX:62014CJ0582) (`C-582/14`, 19 October 2016) the Court of Justice held that a dynamic IP address registered by an online media provider is personal data for that provider where it has legal means to identify the person using additional data held by the internet service provider. That ruling applied the older Directive 95/46/EC, not the GDPR. The GDPR (Regulation (EU) 2016/679) names online identifiers in its definition of personal data (Article 4(1)), and Recital 30 gives internet protocol addresses as an example. Where it applies, Article 6(1) requires a lawful basis. Recital 47 says processing strictly necessary to prevent fraud constitutes a legitimate interest, and Article 6(1)(f) still weighs that against the person's interests and rights. Articles 13 and 14 require telling people the purposes, the recipients and the storage period or its criteria. Article 5(1)(e) limits identifiable storage to what the purposes need. Article 22 gives a right not to be subject to a decision based solely on automated processing that produces legal or similarly significant effects, and whether an automated block reaches that threshold depends on the facts. This is general information, not legal advice, and other laws may apply to your users. Take these questions to counsel or your data protection officer: your lawful basis for risk checks, whether to send raw IPs to a vendor and under what agreement, how long to keep them, what your privacy notice says, and whether automated blocks need human review.

**Done when:** a log row answers "why" without storing more than it needs. **Most likely failure:** keeping raw IPs forever "just in case".

## Step 7: Give People a Way Back

OWASP says mitigations, blocks above all, should be temporary, with a process to lift them as abuse declines. It also suggests telling users about unusual events without flooding them, and showing recent logins so they can end sessions that are not theirs.

In practice: the challenge screen says what happened and what to do, support sees the reason codes, every block expires, and every allow list entry (partner gateways, staff, test accounts) has an owner and an end date.

**Done when:** support can answer "why was I asked to verify?" from the log in a minute. **Most likely failure:** silent blocks nobody owns.

## Step 8: Test Before You Enforce

| Test | How | Pass looks like |
|---|---|---|
| Forged header | `curl -H "X-Forwarded-For: 203.0.113.50" https://staging.example.test/debug/ip` | The page shows the connecting address, not the forged one |
| Tor | Feed an address from the exit list to your classifier | Tor signal, action from your table |
| Relay | Feed an address from a prefix in Apple's file | Relay signal, no block |
| Timeout | Point the lookup at a stub slower than the timeout | The flow's fallback, inside the timeout |

Then run the decision in log only mode for two to four weeks (our reading) and read a sample of the logins it would have challenged.

**Most likely failure:** testing only from your own network, which never produces a relay or Tor address.

## Troubleshooting: Symptom, Cause, What to Check

| Symptom | Likely cause | What to check |
|---|---|---|
| Every user shows a few internal or CDN addresses | The app sees the proxy hop | Step 2. With Cloudflare, check Transform Rules and Managed Transforms if `CF-Connecting-IP` is missing |
| Attackers choose their own IP | Leftmost `X-Forwarded-For` value used, or origin reachable directly | Take the first address from the right that is not your proxy, and firewall the origin |
| Some visitors show odd IPv4 addresses such as 240.16.0.1 | Cloudflare Pseudo IPv4 set to Overwrite Headers, which uses Class E addresses | Read `CF-Connecting-IPv6`, or change the setting |
| Relay users are all challenged | Many people share one relay address | Lighten the action and key on account and device |
| Takeovers continue | Proxy networks spread requests thinly (OWASP), and residential ones are hard to detect (Google) | Add per account velocity, device and connection signals, and MFA |

## FAQ

### Can you detect a VPN at login with certainty?

No. A VPN flag describes the network behind an address, not the person or their intent. Use it as one input beside device history and behavior.

### Should I block VPN users at login?

Not by default. Step up when the signal arrives with other risk signals, such as a new device. Apple and the Tor Project both point operators to alternatives to blanket blocking.

### How do I detect Apple Private Relay or WARP users?

For Private Relay, use Apple's egress file or your provider's categories. For WARP we found no documented egress list, so rely on your lookup provider and test it.

### Is a visitor's IP address personal data?

It can be. The Commission lists it as an example, and Breyer found a dynamic IP personal data in specific circumstances. Ask counsel about yours. This is not legal advice.

## Takeaway: Detect VPN at Login as One Signal

Resolve the IP from trusted hops only, look it up with a timeout, and let relay and WARP users through on the IP signal alone, and give Tor users a step up instead of a wall. Log reasons, expire blocks and test with real addresses before you enforce.

Planning a VPN app with its own accounts and billing? DigitalD.tech can help you design the app, backend, server infrastructure, and admin panel around your business model. [Tell us what you are building](https://digitaldtech.com/contact/).

*Last checked against Cloudflare documentation and its 2022 WARP post, MDN, Express and nginx documentation, a Cloudflare IAB workshop slide, RFC 7239, OWASP's Credential Stuffing Prevention Cheat Sheet, Apple's Private Relay guidance and egress file, Tor Project posts, Google's residential proxy report, the Breyer judgment and the European Commission's personal data page on 31 October 2026.*

