1

We're looking at deploying CloudFlare as a WAF for our site. One of the requirements is that we restrict access to the site from outside North America. Fortunately, CloudFlare supports GeoLocation, and stamps requests to the origin server with a location header.

Now, however, I need to figure out how to whitelist countries. Ideally, I'd like to specify CA and US or whatever as permissible values, and reject everything else, but in IIS, it seems to only support blacklisting.

Is there a way to do this in IIS alone, or does anyone know of a third part module that does this?

Mike Caron
  • 237
  • 2
  • 13

1 Answers1

1

You could use the IIS Rewrite Module.

Use a rule to match all URLs and use a condition to check for the http header injected by CloudFlare, check for the country value and reject all requests not from the US or Canada.

A sample rule would be something like this:

<rewrite>
    <rules>
        <rule name="RequestBlockingRule1" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_CF_IPCOUNTRY}" pattern="^CA|US$" negate="true" />
            </conditions>
            <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="Using this site from your location is not supported." />
        </rule>
    </rules>
</rewrite>

CF-IPCountry would be the name of the header injected by CloudFlare.

Mike Caron
  • 237
  • 2
  • 13
Peter Hahndorf
  • 13,763
  • 3
  • 37
  • 58