Webview mobile app country permission

I am using country restriction on my website.

I also have mobile applications with webview.

I want to do something like this but I don’t know if it’s possible.

my aim:

When traffic comes from the countries that I limit, the block is active on the website.

When traffic comes through the webview-based mobile application, the blocking rule I added is disabled.

In summary: I want to disable country restriction for mobile apps available in android, ios, huawei stores.

is there a method for this?

You could add a few user-agent strings to your Firewall Rule, but using UA in a security rule is by nature faulty, as one can easily forge their user agent. Also, differentiating a mobile browser from a webview app is close to impossible, as developers may or may not use the default webview user agent when they code their apps. Searching stackoverflow.com for “android vs webview” may help you.

If still you want to combine your country restriction (a Firewall Rule, I presume) with mobile user agents, then if your Cloudflare Plan is Business or Enterprise, you can use regex to match terms from mobile and/or webview user agents, and this example from Cache by Device Type could serve as inspiration.

Otherwise, you can to create a Firewall Rule with several terms, linked with AND logical operator.

If Country is not in {"US" "UK"} AND
User Agent does not contain "mobile" AND
User Agent does not contain "ios" AND...

then Block/Challenge


Thanks for your support. you really helped a lot.

I want to ask this too. I will be grateful if you help.

As I mentioned before, there is already a rule for countries at the moment. you can see in the picture.

How should I study for the new rule you mentioned?

In the rule I added earlier; Should I add the information you sent or create another rule?

Start by familiarizing yourself with the documentation and practice with the provided examples.

It’s up to you. Combining several into one rule has the advantage of using fewer rules, and if you are on Cloudflare Free Plan, you can only set 5 Firewall Rules.
On the other hand, many expressions mixed in the same rule make it more difficult to understand and debut, should there be a problem down the road.

You could use the rule you created above and add terms from mobile user agents, but again, I don’t think it’s the best idea to count on UA as a defining element of a rule. It could be used in combination with other elements, but not your your case, I’m afraid.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.