From 305fb11b469a1a296af67d77c34b4a6633bba9ec Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 13 Apr 2025 23:37:22 +0100 Subject: [PATCH] token: add a Domain to the cookie fixes #4 --- src/core/Handler.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/Handler.cpp b/src/core/Handler.cpp index 0a8cf1a..c93aa21 100644 --- a/src/core/Handler.cpp +++ b/src/core/Handler.cpp @@ -249,8 +249,8 @@ void CServerHandler::onTimeout(const Pistache::Http::Request& request, Pistache: } void CServerHandler::challengeSubmitted(const Pistache::Http::Request& req, Pistache::Http::ResponseWriter& response) { - const auto JSON = req.body(); - const auto FINGERPRINT = fingerprintForRequest(req); + const auto JSON = req.body(); + const auto FINGERPRINT = fingerprintForRequest(req); const auto CHALLENGE = CChallenge(req.body()); @@ -263,7 +263,12 @@ void CServerHandler::challengeSubmitted(const Pistache::Http::Request& req, Pist const auto TOKEN = CToken(FINGERPRINT, std::chrono::system_clock::now()); - response.headers().add(std::make_shared(std::string{TOKEN_COOKIE_NAME} + "=" + TOKEN.tokenCookie() + "; HttpOnly; Path=/; Secure; SameSite=Lax")); + auto hostDomain = req.headers().getRaw("Host").value(); + if (hostDomain.contains(":")) + hostDomain = hostDomain.substr(0, hostDomain.find(':')); + + response.headers().add( + std::make_shared(std::string{TOKEN_COOKIE_NAME} + "=" + TOKEN.tokenCookie() + "; Domain=" + hostDomain + "; HttpOnly; Path=/; Secure; SameSite=Lax")); response.send(Pistache::Http::Code::Ok, "Ok"); }