| 1 | # -*- mode: perl -*- | ||
| 2 | # Copyright (C) 2017–2021 Alex Schroeder <alex@gnu.org> | ||
| 3 | |||
| 4 | # This program is free software: you can redistribute it and/or modify it under | ||
| 5 | # the terms of the GNU Affero General Public License as published by the Free | ||
| 6 | # Software Foundation, either version 3 of the License, or (at your option) any | ||
| 7 | # later version. | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU Affero General Public License along | ||
| 15 | # with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | =encoding utf8 | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | App::Phoebe::BlockFediverse - block Fediverse instances from Phoebe wiki | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | This extension blocks the Fediverse user agent from your website (Mastodon, | ||
| 26 | Friendica, Pleroma). The reason is this: when these sites federate a status | ||
| 27 | linking to your site, each instance will fetch a preview, so your site will get | ||
| 28 | hit by hundreds of requests from all over the Internet. Blocking them helps us | ||
| 29 | weather the storm. | ||
| 30 | |||
| 31 | There is no configuration. Simply add it to your F<config> file: | ||
| 32 | |||
| 33 | use App::Phoebe::BlockFediverse; | ||
| 34 | |||
| 35 | Sure, we could also think of better caching and all that. I hate the fact that | ||
| 36 | other developers are forcing us to build “software that scales” – I hate how | ||
| 37 | they think that I have nothing better to do than think about blocking and | ||
| 38 | caching. Phoebe is software for the Smolnet, not for people that keep thinking | ||
| 39 | about scaling. | ||
| 40 | |||
| 41 | The solution implemented is this: if the user agent of a HTTP request matches | ||
| 42 | the regular expression, quit immediatly. The result: | ||
| 43 | |||
| 44 | $ curl --header "User-Agent: Pleroma" https://transjovian.org:1965/ | ||
| 45 | Blocking Fediverse previews | ||
| 46 | |||
| 47 | Yeah, we could respond with a error, but fediverse developers aren’t interested | ||
| 48 | in a new architecture for this problem. They think the issue has been solved. | ||
| 49 | See L<#4486|https://github.com/tootsuite/mastodon/issues/4486>, “Mastodon can be | ||
| 50 | used as a DDOS tool.” | ||
| 51 | |||
| 52 | =cut | ||
| 53 | |||
| 54 | package App::Phoebe::BlockFediverse; | ||
| 55 | use App::Phoebe qw(@extensions); | ||
| 56 | use App::Phoebe::Web qw(http_error); | ||
| 57 | use Modern::Perl; | ||
| 58 | |||
| 59 | push(@extensions, \&block_fediverse); | ||
| 60 | |||
| 61 | sub block_fediverse { | ||
| 62 | my ($stream, $url, $headers) = @_; | ||
| 63 | # quit as quickly as possible: return 1 means the request has been handled | ||
| 64 | return 0 unless $headers and $headers->{"user-agent"} and $headers->{"user-agent"} =~ m!Mastodon|Friendica|Pleroma!i; | ||
| 65 | http_error($stream, "Blocking Fediverse previews"); | ||
| 66 | return 1; | ||
| 67 | } | ||
| 68 | |||
| 69 | 1; |