lag.dev

The drift test

Last updated

The drift test is the location check marked "powered by URnetwork" that some sites add to a sign-up or checkout form. It times pings between your browser and URnetwork's servers to check that your connection is in the country your IP address says. Here is what it measures, what the site learns and what is kept.

For developers

The drift test comes with URnetwork's Embed plan. Put the widget in your sign-up or checkout form, and your backend asks for a token for each check and reads its verdict.

The widget

Paste it into any https page, or one on http://localhost while you develop. The demo token works at once and verifies nothing.

<iframe src="https://lag.dev/?t=demo" width="300" height="104"
        title="Location check" style="border:0"></iframe>
  • Don't sandbox the frame: the widget needs its own origin to reach lag.dev. If you must, allow at least allow-scripts allow-same-origin allow-popups.
  • Don't give it referrerpolicy="no-referrer", which hides your page's origin from the widget in some browsers.
  • On a light page, add &theme=light to its src.

A token for each check

From your backend, with your network's API key and the visitor's IP address as your server sees it:

curl -fsS -X POST https://api.bringyour.com/lag/drift-test \
  -H "Authorization: Bearer $URNETWORK_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{"client_ip": "203.0.113.7"}'

The answer holds the token, the widget's embed_url and a drift_test_id. Keep the id on your server, with the visitor's session.

The verdict

Read it from your backend when the visitor moves on, for example when they submit your form:

curl -fsS "https://api.bringyour.com/lag/drift-test?drift_test_id=$DRIFT_TEST_ID" \
  -H "Authorization: Bearer $URNETWORK_API_KEY"

result.verdict is agree, disagree or inconclusive, with its reason. The widget's messages to your page never carry it, since any script on the page could forge one.

What it measures

Each run times round trips between your browser and about 12 servers: URnetwork extenders, machines that URnetwork providers run around the world. There is no download or upload.

  • lag.dev's server chooses them, not your browser: the 4 nearest to where your IP address places you, 4 at 300 to 2,500 km chosen to tell that place apart from others 800 to 2,000 km away, and 4 at 2,500 to 9,000 km, in different directions.
  • Each server pings your browser about 4 times a second over a secure connection and times the round trip. A ping carries random bytes your browser must send back, so nothing can answer it early: a round trip can be made longer, never shorter.
  • A run stops once at least 8 servers have 8 round trips each and its answer is steady or clear: typically 7.5 seconds after it connects on a first run and 5.5 on a third, and never later than 12. From start to verdict, a check usually takes about 8 to 12 seconds, a little less on a retest, and at most about 15.
  • The pings to all 12 use about 14 KB a second.
  • The check starts on its own once it is on your screen, and not before.

What it checks

It checks whether your pings place you in the country your IP address says. That country comes from databases of where addresses are registered and used, and it can be wrong: a VPN's "virtual location", for example, is a server in one country using an address registered to another.

Round trips grow with distance, by about 15 ms for every 1,000 km. lag.dev fits one position to them, with a region around it holding every place they allow, at 99% confidence, or 95% if the site asks for it. The check passes if any part of that region touches your IP address's country, and fails only if the whole region lies outside it. When the round trips can't place you well enough, the result is inconclusive. The methodology explains the model.

What you see

The check tells you only your IP address's country and whether it was verified:

  • "Verified Germany", for example, when your pings place you in Germany.
  • "Couldn't verify Germany" when they place you outside it, or when the measurement can't tell. The two read the same to you, and the site learns which it was. A Retest button runs the check again.

It never names the place or country your pings point to, or how far away that is. Its small radar draws the measurement around the place your IP address gives, with your country's outline, and names nothing.

One check allows up to 6 runs, within 15 minutes of the first, and its result comes from its last 3 runs taken together, so one noisy run doesn't decide it. "This check has expired" usually means it wasn't started in time; reloading the page should start a new one.

What the site receives

The site reads the result from URnetwork's API with its own key. The check tells the page it sits in only how far a run has got and when it ends, never the result. The site receives:

  • the verdict, with its reason: your pings agree with your IP address's country, disagree with it, or the check is inconclusive;
  • your IP address's country, which the site can look up itself;
  • the country your pings point to, and how far the fitted position is from your IP address's country;
  • the uncertainty: the size and shape of the region;
  • the last-mile delay: the time your own connection adds to every round trip, with a flag when it is far above normal, which can mean a relay;
  • for each run, when it ran, how long it measured and why it stopped, how many servers answered, and whether it came from the address the site gave.

It doesn't receive where your pings place you as a point on a map, which servers measured you, or the round trips themselves.

The site also gives lag.dev the IP address it sees you at, so someone elsewhere can't pass the check for you: a run from outside the block of addresses around it (a /29 of IPv4, a /56 of IPv6) is still measured, and the site sees it, but it never counts. lag.dev first tries to reach you over the same kind of address the site saw, IPv4 or IPv6. If a run still comes over the other kind, the two addresses can't be compared: it counts only if both are in the same country, and the site is told.

What is kept

  • No address. Your IP address is never stored. To compare each run with the address the site gave, lag.dev's server keeps a keyed one-way hash of the block around it (its /29 or /56) until the check closes, usually within 20 minutes, then deletes it. Hourly limits count runs per larger block (a /24 of IPv4, a /48 of IPv6) under the same kind of hash, and each count ends with its hour.
  • 7 days. The check, its runs and its result are deleted after 7 days. Each run keeps its round trips and your network (its ASN) and city-level location, worked out from your address when the run starts.
  • The servers see your address while they ping you, as any server you connect to does. The reports they sign and send to lag.dev carry no address.
  • Nothing in your browser. The check sets no cookies and keeps nothing in your browser's storage.
  • Their use. They give the site its result and, like lag.dev's other measurements, are used to improve URnetwork's network performance. URnetwork's IP geolocation never reads them, and lag.dev keeps no access log.

What the site does with its result is up to the site and its own privacy policy. lag.dev's is URnetwork's privacy policy.

Where your connection ends, not where you are

The check locates whatever ends your connection: your own device, or the VPN or proxy server your traffic leaves from. A VPN adds about the same delay to every path, so it shows in the last-mile delay, not in the position.

  • It catches an address whose country is wrong for where its connection ends: a VPN's "virtual location", or addresses registered or located in the wrong country.
  • It doesn't catch a VPN whose server really is in the country its address says. Someone in France using a VPN server in Germany, with a German address, passes as Germany.
  • On one run it often misses a place only a few hundred km from the one claimed, such as a VPN server in a neighboring country. Retests catch more, since each uses new servers.
  • It catches less in Oceania, until more servers run in New Zealand and the Pacific.
  • A disputed area, such as Crimea or Kashmir, counts as part of each country that claims it.

The methodology gives how often it catches a wrong country, and how often it wrongly says a visitor is outside theirs.

The demo token

A check marked "Demo" uses the token demo, at lag.dev/?t=demo. Anyone may put it on an https page, to show the check or to test its accuracy. A site that verifies its visitors uses tokens of its own, from URnetwork Embed.

  • It runs a real measurement, with servers chosen as for any check.
  • Its result is worked out in your browser, from its own round trips and a simplified world map, by the same rule.
  • It shows what a real check never shows you: the country your pings point to, the distance and margin to your IP address's country, and the uncertainty. The page it sits in receives the same figures.
  • Nothing about it is stored: no check, run or result, and the servers send no reports. No API can tell whether a demo passed.
  • lag.dev's server keeps only a daily total of demo runs, and an hourly count per block of addresses, under a keyed hash, which allows 30 demo runs an hour from each block.

Try the demo