diff --git a/html/index.html b/html/index.html index d459ad3..5e410b9 100644 --- a/html/index.html +++ b/html/index.html @@ -286,10 +286,7 @@ ).then((res) => { if (res.status == 200) { console.log("Got token."); - const json = res.json().then((parsed) => { - document.cookie = "CheckpointToken=" + parsed.token + "; path=/"; - window.location.reload(); - }); + window.location.reload(); } else console.log("Server error"); }); diff --git a/html/index.min.html b/html/index.min.html index 02585ec..41c7bd3 100644 --- a/html/index.min.html +++ b/html/index.min.html @@ -1,2 +1,2 @@ STOP! - Checkpoint

🛑

STOP!


Verifying that you are not a bot. This might take a short moment.

You do not need to do anything.

Why am I seeing this?


This website protects itself from AI bots and scrapers by asking you to complete a cryptographic challenge before allowing you entry.

Difficulty {{ tl:text challengeDifficulty }}, elapsed 0ms, 0h, 0h/s

Powered by checkpoint v{{ tl:text checkpointVersion }}
- \ No newline at end of file + \ No newline at end of file diff --git a/src/core/Handler.cpp b/src/core/Handler.cpp index b5128c9..91802d4 100644 --- a/src/core/Handler.cpp +++ b/src/core/Handler.cpp @@ -4,6 +4,7 @@ #include "../headers/xforwardfor.hpp" #include "../headers/gitProtocolHeader.hpp" #include "../headers/acceptLanguageHeader.hpp" +#include "../headers/setCookieHeader.hpp" #include "../debug/log.hpp" #include "../GlobalState.hpp" #include "../config/Config.hpp" @@ -344,6 +345,8 @@ void CServerHandler::challengeSubmitted(const Pistache::Http::Request& req, Pist resp.success = true; resp.token = TOKEN; + response.headers().add(std::make_shared("CheckpointToken=" + TOKEN + "; HttpOnly; Path=/; Secure; SameSite=Lax")); + response.send(Pistache::Http::Code::Ok, glz::write_json(resp).value()); } diff --git a/src/headers/setCookieHeader.hpp b/src/headers/setCookieHeader.hpp new file mode 100644 index 0000000..ea75fa0 --- /dev/null +++ b/src/headers/setCookieHeader.hpp @@ -0,0 +1,26 @@ +#include +#include + +class SetCookieHeader : public Pistache::Http::Header::Header { + public: + NAME("Set-Cookie"); + + SetCookieHeader(const std::string& cookie = "") : m_cookie(cookie) { + ; + } + + void parse(const std::string& str) override { + m_cookie = str; + } + + void write(std::ostream& os) const override { + os << m_cookie; + } + + std::string from() const { + return m_cookie; + } + + private: + std::string m_cookie = ""; +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 7042cc2..56ae435 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,7 @@ #include "headers/cfHeader.hpp" #include "headers/gitProtocolHeader.hpp" #include "headers/acceptLanguageHeader.hpp" +#include "headers/setCookieHeader.hpp" #include "debug/log.hpp" @@ -76,6 +77,7 @@ int main(int argc, char** argv, char** envp) { Pistache::Http::Header::Registry::instance().registerHeader(); Pistache::Http::Header::Registry::instance().registerHeader(); Pistache::Http::Header::Registry::instance().registerHeader(); + Pistache::Http::Header::Registry::instance().registerHeader(); g_pDB = std::make_unique();