From b09aab4a1d1fbb89c3304d15494bd2a3ae5c1b4d Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 9 Jan 2023 12:25:48 +0100 Subject: [PATCH] don't connect to fascists --- mastodon/src/main/assets/blocks.tsv | 39 +++++++++++++++++++ .../android/api/MastodonAPIController.java | 19 +++++++++ 2 files changed, 58 insertions(+) create mode 100644 mastodon/src/main/assets/blocks.tsv diff --git a/mastodon/src/main/assets/blocks.tsv b/mastodon/src/main/assets/blocks.tsv new file mode 100644 index 000000000..8075bbb4b --- /dev/null +++ b/mastodon/src/main/assets/blocks.tsv @@ -0,0 +1,39 @@ +# lists.d Mastodon Blocklist (c) 2022 Greyhat Academy LICENSED UNDER: CC-BY-NC-SA 4.0 +# https://raw.githubusercontent.com/greyhat-academy/lists.d/main/mastodon.domains.block.list.tsv +# This list contains domains of toxic mastodon instances +# Last-Modified: 1672044500 + +# gab - a neonazi social network +gab.ai +gab.com +gab.protohype.net + +# consequence-free speech +social.unzensiert.to +freeatlantis.com + +# reactionary bigotry and hatespeech against magrinalized groups +poa.st +freespeechextremist.com +rdrama.cc +outpoa.st +anime.website +gameliberty.club +social.byoblu.com +yggdrasil.social +smuglo.li +dogeposting.social +unsafe.space +freezepeach.xyz + +# + CSAM +rojogato.com + +# antivaxxer shitposting & fearmongering +shadowsocial.org + +# Kiwifarms +kiwifarms.net +kiwifarms.cc +kiwifarms.is +kiwifarms.pleroma.net \ No newline at end of file diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIController.java b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIController.java index 5610155be..6a2dfe8a3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIController.java @@ -12,11 +12,14 @@ import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import org.joinmastodon.android.BuildConfig; +import org.joinmastodon.android.MastodonApp; import org.joinmastodon.android.api.gson.IsoInstantTypeAdapter; import org.joinmastodon.android.api.gson.IsoLocalDateTypeAdapter; import org.joinmastodon.android.api.session.AccountSession; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.Reader; import java.time.Instant; import java.time.LocalDate; @@ -47,9 +50,22 @@ public class MastodonAPIController{ private static OkHttpClient httpClient=new OkHttpClient.Builder().build(); private AccountSession session; + private static List badDomains = new ArrayList<>(); static{ thread.start(); + try { + final BufferedReader reader = new BufferedReader(new InputStreamReader( + MastodonApp.context.getAssets().open("blocks.tsv") + )); + String line; + while ((line = reader.readLine()) != null) { + if (line.isBlank() || line.startsWith("#")) continue; + badDomains.add(line.toLowerCase().trim()); + } + } catch (IOException e) { + e.printStackTrace(); + } } public MastodonAPIController(@Nullable AccountSession session){ @@ -57,8 +73,11 @@ public class MastodonAPIController{ } public void submitRequest(final MastodonAPIRequest req){ + final String host = req.getURL().getHost().toLowerCase(); + final boolean isBad = badDomains.stream().anyMatch(host::endsWith); thread.postRunnable(()->{ try{ + if (isBad) throw new IllegalArgumentException(); if(req.canceled) return; Request.Builder builder=new Request.Builder()