token: add a Domain to the cookie

fixes #4
This commit is contained in:
Vaxry
2025-04-13 23:37:22 +01:00
parent 4e307c314b
commit 305fb11b46

View File

@@ -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<SetCookieHeader>(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<SetCookieHeader>(std::string{TOKEN_COOKIE_NAME} + "=" + TOKEN.tokenCookie() + "; Domain=" + hostDomain + "; HttpOnly; Path=/; Secure; SameSite=Lax"));
response.send(Pistache::Http::Code::Ok, "Ok");
}