Geo Blocking plugin

Summary: Geo Blocking plugin for Discourse

:link: GitHub: GitHub - communiteq/discourse-geo-blocking
:arrow_right: Install: Follow the plugin installation guide.
:moneybag: Client: This plugin has been sponsored by Sketchfab.

Features

This can be used to completely block access to your forum for certain countries or networks, for example fraud prevention or to comply with sanctions.

The plugin leverages the MaxMindDB database that is already available in Discourse.

Configuration

  • Enable the plugin
  • Add all networks you want to block to geo_blocking_asn_blocklist. Prefix the numbers with AS, so for example AS12345.
  • Add all countries and regions you want to block to geo_blocking_country_region_blocklist. The following formats are accepted:
    • Full country name (for example: Belgium)
    • Country ISO code (for example: JP for Japan)
    • Full country name followed by a dot and then the region name (for example: Switzerland.Jura).

  • If you enable geo blocking detailed reason then the error message will contain the country/region or network that caused the user to be blocked.

versus

  • To test the plugin you can check geo blocking log blocked and/or geo blocking log allowed and inspect the /logs on your forum.

image

For a full list of supported countries and regions, see list_of_countries_and_regions.txt.

Attention and Caveats

If anonymous visitors are being blocked, they could still get a cached version of the home page for around one minute.

The error page does not contain “Popular” and “Recent” topics because that would leak content to a blocked user.

18 Likes

Thanks for the quick turnaround on this project, Richard!

4 Likes

Thank you. Very usefull

1 Like

I’ll try this right away. How could I miss this :woozy_face:

I need geoblock few countries and ASes, but for obvious reason I can’t use Varnish for this task as with my other sites. This solves that headache, if it is still operational.

Yes, the plugin is still maintained and working.

2 Likes

Thanks for developing this useful plugin, Richard.

I made some minor modifications to adapt to my use case: blocking certain URLs for users in certain regions. What I’ve done is, in add_model_callback(:application_controller, :before_action), adding some more match rules with request.fullpath, e.g.:

return unless request.fullpath.start_with?(*SiteSetting.topic_geo_blocking_exact_paths.split('|'))

I find that this URL-level geo-blocking works if I access the URL by directly typing it in the browser navigation bar. However, if I navigate to the URL by clicking it from Discourse homepage, this doesn’t work. (but after pressing F5 to refresh the page, it gets blocked.)

Could you give me any advice to fix this issue? Thanks.

1 Like

You would need to add some Ember code that intercepts the router as well.

However, I think that you would need to take a different approach here. This plugin was not built for such specific filtering.

It would probably work way better to create a separate plugin that has a mechanism to add/remove users to groups based on their geolocation, and then you could leverage the existing group security to restrict or allow access to specific parts of the forum.

3 Likes