Sanctions geofence on a self-hosted gateway
The sanctions geofence refuses requests that come from places listed in the sanctions jurisdiction policy, the jurisdictions under comprehensive United States sanctions. A refused request gets HTTP 451, Unavailable For Legal Reasons, with a stable error code and a link to the policy. On a self-hosted gateway the geofence is off by default, needs no license and is never paywalled, because it is a compliance control you may need under your own obligations. Spanway Cloud always runs it with the Cloud scope of the policy. See Sanctions data and geofencing for the policy itself and how it is maintained.
This is compliance tooling and not legal advice. IP geolocation is best effort. VPNs, proxies and Tor defeat it, and region data for Crimea and eastern Ukraine is often wrong, so screen your customers as well and treat the geofence as a supporting control.
A real-world scenario
A company exposes its gateway to customers worldwide through a CDN and its export compliance officer asks that requests from sanctioned jurisdictions be refused and logged. The platform admin turns the geofence on, names the CDN so the gateway reads its country and region headers, adds the company's own VPN exit range as always allowed, and checks the readiness details to confirm every request can be located before telling the officer it is live.
Steps
-
Make sure the gateway knows which addresses are your CDN or load balancer, so it trusts their headers and reads the real client address.
general_settings:trusted_proxy_ranges: ["10.0.0.0/8"] -
Turn on the geofence and name the CDN whose geolocation headers to read, then restart the gateway.
general_settings:trusted_proxy_ranges: ["10.0.0.0/8"]sanctions_geofence:enabled: trueon_unknown: allowgeo:provider: cloudflareallow_networks: ["203.0.113.0/24"] -
Turn on your CDN's region headers, otherwise subdivision rules see only the country.
-
Confirm the gateway can locate requests.
curl -s http://localhost:4000/health/readiness/details -H "Authorization: Bearer $SPANWAY_MASTER_KEY" | jq .sanctions_geofence -
In the Admin UI open Settings, then Compliance, and select the Sanctions tab. The Jurisdiction policy section lists every rule with its codes, legal basis and status, shows the readiness of the geofence, and shows a Geofence configuration problem alert when a setting did not validate. Proxy admins and admin viewers see it on every gateway, with or without a license. The same data is on the API:
curl -s http://localhost:4000/sanctions/geofence -H "Authorization: Bearer $SPANWAY_API_KEY" -
From a location in a restricted place, or through a VPN exit in one, call any route.
curl -sS -D - -o /dev/null https://gateway.example.com/v1/models -H "Authorization: Bearer $SPANWAY_KEY"
Expected result
Step 4 reports "enabled": true, the scope, the policy_version, the approval_state and no problem. Step 5 returns the policy as the gateway applies it, including candidate rules and your overrides. Step 6 answers HTTP/1.1 451 with Cache-Control: no-store, private, Link: <https://spanway.ai/legal/sanctions/>; rel="blocked-by" and this body, and the refusal is logged with the client address truncated to its network. Requests from everywhere else are untouched.
{
"error": {
"type": "unavailable_for_legal_reasons",
"code": "sanctioned_jurisdiction",
"message": "Spanway is not available in your region.",
"policy_url": "https://spanway.ai/legal/sanctions/"
}
}
Settings
| Setting | Meaning |
|---|---|
enabled | Turns the geofence on, so the gateway refuses requests from restricted places with HTTP 451 and your service is not used where sanctions forbid it. Off by default, which refuses nobody by location. Spanway Cloud enforces the geofence whatever this says. Your compliance owner decides it, and a platform admin sets it. |
on_unknown | allow (default) serves requests whose location cannot be resolved, block refuses them with sanctions_location_unknown. block is stricter but also refuses customers whose CDN header is missing, so turn it on only when every request comes through the CDN. Spanway Cloud always behaves as block. When no request can be located there (no geo.provider, or a CDN provider without trusted_proxy_ranges) it refuses every request with sanctions_location_unknown, logs the reason at startup and reports it in the readiness check, until the provider is configured. |
geo.provider | The CDN in front of the gateway (cloudflare, cloudfront or vercel), whose geolocation headers are read, or mmdb to look the address up in a MaxMind-format database, which the gateway images cannot use today (see below). Unset means no request can be located, which the readiness check reports. |
geo.mmdb_path | The database file for mmdb. |
allow_countries, allow_subdivisions | ISO codes you are licensed to serve even though the policy restricts them, such as UA-43. |
allow_networks | CIDR ranges that are always allowed, such as your own VPN egress. |
extra_block_countries, extra_block_subdivisions | Places you restrict on top of the policy. |
policy_path | Your own reviewed copy of jurisdictions.json, instead of the bundled one. |
Overrides apply in a fixed order: allowed networks first, then allowed codes, then your extra blocked codes, and only then the policy. When enabled: true (or on Spanway Cloud), settings that do not validate never turn the geofence off. The gateway keeps enforcing the policy without your overrides, keeps the geo, on_unknown and policy_path values when those parts are valid, and reports the problem in the readiness check and the logs. When the location settings themselves do not validate, the gateway refuses every request it cannot locate, which is every request until you fix them, so a typo never quietly lets restricted places through. Settings that do not validate never turn a disabled geofence on either, so a typo next to enabled: false leaves it off and the readiness check reports the problem. If the policy file cannot be read at all, every request except the health checks gets HTTP 503 with the code sanctions_policy_unreadable, so a broken install fails closed.
Where the location comes from
The client address is the one the gateway already resolves for IP allow lists and login throttling. X-Forwarded-For is only trusted when the direct peer is inside trusted_proxy_ranges, and it is read right to left, so a client cannot spoof it by adding its own entry. The geofence never reads the header itself.
With cloudflare the gateway reads CF-IPCountry with cf-region-code, with cloudfront it reads CloudFront-Viewer-Country and CloudFront-Viewer-Country-Region, and with vercel it reads x-vercel-ip-country with x-vercel-ip-country-region. It reads only the headers of the CDN you name. A CDN overwrites its own headers but passes other CDNs' headers through, so a client could otherwise add a forged header from a different CDN. The headers are honoured only when the request came through a proxy in trusted_proxy_ranges, because a client talking to the gateway directly could send them too. Without trusted_proxy_ranges the readiness check and the Admin UI report that the geofence cannot locate anyone.
The mmdb provider reads a MaxMind-format database through the maxminddb package. The Spanway images do not include that package and cannot install one, so on the images mmdb always reports geo.provider is mmdb but the maxminddb package is not installed and no request can be located. Put a CDN in front of the gateway and name it in geo.provider instead. No geolocation database ships in any Spanway image either.
What a refused request gets
The codes are stable, so clients can act on them. The same body comes back from the geofence, from a Spanway Cloud account check on any authenticated route, and from Cloud signup and verification. WebSocket connections, such as the realtime endpoints, are checked too. A refused handshake gets the same 451 response where the server supports WebSocket denial responses, and is otherwise closed with code 1008.
| Code | When |
|---|---|
sanctioned_jurisdiction | The request comes from a restricted place, or a Cloud signup gave a restricted address. |
sanctions_location_unknown | The location could not be resolved and on_unknown is block, the geofence's location settings do not validate (which forces block), or the gateway is Spanway Cloud, which always refuses a request it cannot place, for example when the CDN header is missing. |
sanctions_screening_hold | A Spanway Cloud account is held while a possible list match is reviewed. |
sanctions_restricted | A Spanway Cloud account was restricted after review. |
sanctions_confirmed_match | A Spanway Cloud account was blocked after a confirmed list match. |
/health/liveliness, /health/liveness, /health/readiness and the Stripe webhook are exempt, because the caller there is your orchestrator or Stripe, not a customer.
| Method | Path | Summary |
|---|---|---|
| GET | /sanctions/geofence | Read the sanctions geofence policy and its readiness |
Errors
| What you see | Why | Fix |
|---|---|---|
| The readiness check reports the geofence cannot locate anyone. | geo.provider is unset, or a CDN provider is named without trusted_proxy_ranges. | Name the CDN and list its address ranges in trusted_proxy_ranges. |
problem in the readiness check and a Geofence configuration problem alert in the Admin UI. | A setting did not validate, for example a code that is not ISO 3166 or a range that is not CIDR. | Fix the setting the message names. The policy keeps being enforced without your overrides meanwhile, and when geo itself is invalid every request answers 451 sanctions_location_unknown until it is fixed. |
Every request answers 503 sanctions_policy_unreadable. | The policy file at policy_path or the bundled one cannot be read. | Fix the path or restore the file. The gateway fails closed on purpose. |
Requests from your own offices answer 451. | Your egress sits in or is geolocated to a restricted place, or a subdivision rule matches a wrong region header. | Add the egress range to allow_networks, or the code to allow_subdivisions when you are licensed to serve it. |
| Subdivision rules never match, whole countries do. | The CDN does not send region headers. | Turn on region headers at the CDN. |
403 Only proxy admins can read the sanctions policy | A non-admin key called /sanctions/geofence. | Use a proxy admin or admin viewer key. |
The readiness check says geo.provider is mmdb but the maxminddb package is not installed. | The gateway images do not include the maxminddb package, so mmdb cannot work on them. | Name the CDN in front of the gateway in geo.provider and list its address ranges in trusted_proxy_ranges. |
Logs
| Level | Line | Meaning |
|---|---|---|
| WARNING | sanctions geofence refused <path> from <network> (<country> <subdivision>, rule <rule_id>) | One request was refused with 451. The address is truncated to its network. Normal while the geofence is on. Many lines from your own network mean your egress is located in a restricted place, see the Errors table. |
| ERROR | sanctions geofence: <problem> | A setting did not validate, or no request can be located. The same text is in the readiness check. Action needed, fix the setting it names. |
| ERROR | sanctions geofence: invalid settings left it off: <detail> | Settings next to enabled: false did not validate, so the geofence stays off. Fix them before you turn it on. |
| ERROR | sanctions geofence: the jurisdiction policy is unreadable: <detail> | The policy file cannot be read, so every request answers 503 sanctions_policy_unreadable. Fix policy_path or restore the file. |
Decisions about who to refuse are not written to the audit log, because they are traffic, not changes. Who changed the geofence settings is, as a Spanway_Config row when the settings are saved through the config API.
Related
- Sanctions data and geofencing describes the policy and how it is kept current.
- Sanctions screening on Spanway Cloud covers the account checks that share these codes.
- IP and route allow-lists explains how the client address is found.
- Health checks for
/health/readiness/details. - Compliance for the rest of the Compliance page.