From 8b6a26d6b6e71d353a56720e70e786ade69a81de Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 17 Jan 2021 17:01:46 +0100 Subject: [PATCH] Catch non-targeted spam. --- src/cgi.cpp | 13 +++++++++++++ src/cgi.hpp | 10 +++++++++- src/main.cpp | 7 ++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/cgi.cpp b/src/cgi.cpp index a9088a1..b58abab 100644 --- a/src/cgi.cpp +++ b/src/cgi.cpp @@ -61,6 +61,13 @@ entry_type parse_formdata() entry_type entry; cgicc::Cgicc cgi; + + // Catch non-targeted spam. + if (!cgi("url").empty()) + { + throw SpamException{}; + } + entry.instance = cgi("instance"); entry.tags = string_to_vector(cgi("tags")); transform(entry.tags.begin(), entry.tags.end(), entry.tags.begin(), @@ -176,4 +183,10 @@ string text2html(string text) return text; } + } // namespace FediBlock::cgi + +const char *SpamException::what() const noexcept +{ + return "Spam detected."; +} diff --git a/src/cgi.hpp b/src/cgi.hpp index cb48eff..28b81c1 100644 --- a/src/cgi.hpp +++ b/src/cgi.hpp @@ -1,5 +1,5 @@ /* This file is part of FediBlock-backend. - * Copyright © 2020 tastytea + * Copyright © 2020, 2021 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -19,6 +19,7 @@ #include "types.hpp" +#include #include #include #include @@ -53,4 +54,11 @@ string text2html(string text); } // namespace FediBlock::cgi +class SpamException : public std::exception +{ +public: + // NOLINTNEXTLINE(modernize-use-nodiscard) + const char *what() const noexcept override; +}; + #endif // FEDIBLOCK_BACKEND_CGI_HPP diff --git a/src/main.cpp b/src/main.cpp index 7bd9c8d..e78e8ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ /* This file is part of FediBlock-backend. - * Copyright © 2020 tastytea + * Copyright © 2020, 2021 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -79,6 +79,11 @@ int main() files::remove_tmpdir(); } + catch (const SpamException &e) + { + cerr << e.what() << '\n'; + cout << e.what() << "\r\n"; + } catch (const exception &e) { cerr << e.what() << '\n';