Catch non-targeted spam.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
6a7fdb4903
commit
8b6a26d6b6
13
src/cgi.cpp
13
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.";
|
||||
}
|
||||
|
|
10
src/cgi.hpp
10
src/cgi.hpp
|
@ -1,5 +1,5 @@
|
|||
/* This file is part of FediBlock-backend.
|
||||
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||
* Copyright © 2020, 2021 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* 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 <exception>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* This file is part of FediBlock-backend.
|
||||
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||
* Copyright © 2020, 2021 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* 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';
|
||||
|
|
Reference in New Issue