From 9b0c68f2bf382982e2c8542184df85febeabb5b2 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 26 Jun 2019 02:35:35 +0200 Subject: [PATCH] Prevent usage with Gab domains. --- src/mastodon-cpp.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/mastodon-cpp.cpp b/src/mastodon-cpp.cpp index bf042a9..a047ad6 100644 --- a/src/mastodon-cpp.cpp +++ b/src/mastodon-cpp.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "version.hpp" #include "debug.hpp" #include "mastodon-cpp.hpp" @@ -36,7 +37,24 @@ API::API(const string &instance, const string &access_token) , _exceptions(false) , _proxy("") , _proxy_userpw("") -{} +{ + bool fash = false; + const std::regex re_gab("(?:\\.|^)gab\\.[^\\.]+$"); + + for (const std::regex &re : { re_gab }) + { + if (std::regex_search(_instance, re)) + { + fash = true; + break; + } + } + + if (fash) + { + throw std::runtime_error("Fascist instance detected: " + _instance); + } +} API::~API() {}