More Granular Geoblocking

With varying state laws in the US, commercial websites often must limit access to specific states. With that in mind, I’d love to see blocking for VPNs and proxies, and state-level Geoblocking. So much easier to do these through CF, versus a third-party app

You could do this with a Worker and probably through the Firewall

With a Worker, you could do like (code untested):

export default {
  fetch(req) {
    const states = ['TX', 'WA'];
 
    if (req.cf.regionCode && states.includes(req.cf.regionCode)) {
      return fetch(req);
    } else {
      return new Response('This website is unavailable outside of Texas and Washington', { status: 403 });
    }
  }
}
1 Like