Geo-Blocking & Access Control
Control who can access your content based on geographic location. Essential for licensing compliance, regulatory requirements, and market strategy.
Why Use Geo-Blocking?
Content Licensing
Media companies often have different licensing agreements per region. Geo-blocking ensures content is only accessible where you have distribution rights.
Regulatory Compliance
Some industries require restricting access to certain jurisdictions. Financial services, gambling, and healthcare often have geographic requirements.
Sanctions Compliance
Block access from sanctioned countries to comply with export controls and international trade regulations.
Market Strategy
Launch products in specific regions first, run geo-targeted promotions, or create regional pricing strategies.
Implementation Options
Allowlist
Only allow access from specific countries. Block everyone else by default.
allowed = ['US', 'CA', 'GB']
Blocklist
Allow access from everywhere except specific countries.
blocked = ['KP', 'IR', 'CU']
Tiered Access
Different content or features based on location.
tier = region_tiers[country]
Example Implementation
Middleware to check geographic access:
async function geoMiddleware(req, res, next) {
const ip = req.headers['x-forwarded-for'] || req.ip;
const response = await fetch(
`https://api.iplocatepro.com/v1/country/${ip}`,
{ headers: { 'X-API-Key': API_KEY } }
);
const { country_code } = await response.json();
const blocked = ['KP', 'IR', 'CU', 'SY'];
if (blocked.includes(country_code)) {
return res.status(403).json({
error: 'Access not available in your region'
});
}
req.country = country_code;
next();
}
Best Practices
Clear Messaging
When blocking access, provide a clear explanation and suggest alternatives if available.
VPN Consideration
Use ASN data to detect VPN/proxy traffic for stricter enforcement when needed.
Graceful Fallbacks
If geolocation fails, decide whether to allow or deny by default based on your risk tolerance.
Legal Review
Consult legal counsel when implementing geo-blocking for compliance purposes.