Geofence access by jurisdiction
A geofence is a control with a bypass, and the bypass is usually a $5 VPN. Design the block
knowing that, decide fail-open or fail-closed deliberately, and keep the evidence that the block
was live.
Procedure
Write the blocked set as data with a reason per region, so legal can read it:
cat > geoblock.yaml <<'YAML'
deny:
- { country: IR, reason: "sanctions", fail: closed }
- { country: KP, reason: "sanctions", fail: closed }
- { country: US-NY, reason: "no licence", fail: closed }
YAML
Resolve country at the edge from the request, not only from what the client claims. Use the
connecting IP, and treat X-Forwarded-For as advisory; a header set by the client is not a
country.
Decide the failure mode per row. For sanctions regions, fail closed: if geo lookup is down, the
request is denied. For a soft restriction, fail open with a flag is acceptable — but write
which is which.
Handle the VPN problem honestly. Datacentre and hosting ASNs are the strongest signal; block or
challenge them where the restriction matters. Put the ASN check next to the country check so
one change covers both:
grep -w "$ASN" asn-deny.txt && echo "deny: hosting ASN"
Cover the whole surface: web, API, mobile app store availability, and the marketing site. A
blocked web app with an open public API is not geofenced.
Log the decision per request with the input it used — resolved country, ASN, action — so a
later dispute can be checked against the config of that moment.
Re-review on regime change, not on a schedule. A new sanctions designation or a licence grant
changes the deny list, and the config should be version-controlled so the change is visible.
Pitfalls
- Trusting a client-supplied locale, SIM or device language as the location. It is a preference,
not a location.
- Blocking the country of a company's registration rather than the customer's connection; the two
are unrelated and the wrong one both over- and under-blocks.
- Leaving the mobile app available in a blocked region's app store while blocking web. The app is
the product.
- Fail-open by accident: a geo resolver exception that returns
allowed turns a control into a
no-op during exactly the incident you care about.
- Blocking an entire country for a state-level restriction; sub-national restrictions (the NY
example) need state resolution, which IP geolocation only sometimes provides.
Verification
python3 -c 'import yaml;d=yaml.safe_load(open("geoblock.yaml"));
assert all("fail" in r for r in d["deny"]); print(len(d["deny"]), "rules, all with fail mode")'
A pass means every deny rule states its failure mode; a rule with no fail key is ambiguous and
fails the check.
Report the deny list with reasons and failure modes, the signals used (IP, ASN), and the log
field that records the decision. Which countries a product may serve is set by counsel and the
relevant regulator, not by the engineering team.
1---2name: geofence-access-by-jurisdiction3description: Use when a service must not be reachable from certain countries, whether because of sanctions, an unlicensed activity or a product restriction, and the block has to hold up against VPNs.4metadata:5 source: https://skillmd.com/skills/jiayaoqijia/geofence-access-by-jurisdiction6---78# Geofence access by jurisdiction910A geofence is a control with a bypass, and the bypass is usually a $5 VPN. Design the block11knowing that, decide fail-open or fail-closed deliberately, and keep the evidence that the block12was live.1314## Procedure15161. Write the blocked set as data with a reason per region, so legal can read it:1718 cat > geoblock.yaml <<'YAML'19 deny:20 - { country: IR, reason: "sanctions", fail: closed }21 - { country: KP, reason: "sanctions", fail: closed }22 - { country: US-NY, reason: "no licence", fail: closed }23 YAML24252. Resolve country at the edge from the request, not only from what the client claims. Use the26 connecting IP, and treat `X-Forwarded-For` as advisory; a header set by the client is not a27 country.28293. Decide the failure mode per row. For sanctions regions, fail closed: if geo lookup is down, the30 request is denied. For a soft restriction, fail open with a flag is acceptable — but write31 which is which.32334. Handle the VPN problem honestly. Datacentre and hosting ASNs are the strongest signal; block or34 challenge them where the restriction matters. Put the ASN check next to the country check so35 one change covers both:3637 grep -w "$ASN" asn-deny.txt && echo "deny: hosting ASN"38395. Cover the whole surface: web, API, mobile app store availability, and the marketing site. A40 blocked web app with an open public API is not geofenced.41426. Log the decision per request with the input it used — resolved country, ASN, action — so a43 later dispute can be checked against the config of that moment.44457. Re-review on regime change, not on a schedule. A new sanctions designation or a licence grant46 changes the deny list, and the config should be version-controlled so the change is visible.4748## Pitfalls4950- Trusting a client-supplied locale, SIM or device language as the location. It is a preference,51 not a location.52- Blocking the country of a company's registration rather than the customer's connection; the two53 are unrelated and the wrong one both over- and under-blocks.54- Leaving the mobile app available in a blocked region's app store while blocking web. The app is55 the product.56- Fail-open by accident: a geo resolver exception that returns `allowed` turns a control into a57 no-op during exactly the incident you care about.58- Blocking an entire country for a state-level restriction; sub-national restrictions (the NY59 example) need state resolution, which IP geolocation only sometimes provides.6061## Verification6263 python3 -c 'import yaml;d=yaml.safe_load(open("geoblock.yaml"));64 assert all("fail" in r for r in d["deny"]); print(len(d["deny"]), "rules, all with fail mode")'6566A pass means every deny rule states its failure mode; a rule with no `fail` key is ambiguous and67fails the check.6869Report the deny list with reasons and failure modes, the signals used (IP, ASN), and the log70field that records the decision. Which countries a product may serve is set by counsel and the71relevant regulator, not by the engineering team.