From 1407954ab9ea966907f3493ff7d89d94a3856be2 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 15 Nov 2020 17:46:17 +0100 Subject: [PATCH] Exit if REQUEST_METHOD is wrong. --- src/generators/rss.cpp | 9 ++++++++- src/main.cpp | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/generators/rss.cpp b/src/generators/rss.cpp index 05596ec..7b05a13 100644 --- a/src/generators/rss.cpp +++ b/src/generators/rss.cpp @@ -191,8 +191,16 @@ int main(int /*argc*/, char * /*argv*/[]) using std::cerr; using std::cout; using std::exception; + using std::getenv; using std::runtime_error; + cout << "Content-Type: application/rss+xml\r\n\r\n"; + + char *env{getenv("REQUEST_METHOD")}; + if (env != nullptr && string(env) != "GET") + { + return 0; + } git::init(true); @@ -209,7 +217,6 @@ int main(int /*argc*/, char * /*argv*/[]) // Ignore, use old version of repo. } const auto entries{files::read_json_files(true)}; - cout << "Content-Type: application/rss+xml\r\n\r\n"; write_rss(cout, entries, cgi::get_tags()); } catch (const exception &e) diff --git a/src/main.cpp b/src/main.cpp index 7a505dc..7bd9c8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,12 +25,14 @@ #include +#include #include #include using std::cerr; using std::cout; using std::exception; +using std::getenv; using namespace FediBlock; @@ -38,6 +40,12 @@ int main() { cout << "Content-Type: text/plain; charset=utf-8\r\n\r\n"; + char *env{getenv("REQUEST_METHOD")}; + if (env != nullptr && string(env) != "POST") + { + return 0; + } + git::init(true); gitea::init();