Fix Secure

This commit is contained in:
Sergio R. Caprile 2023-05-30 11:47:07 -03:00
parent dd5f469c83
commit 771696fda8

View File

@ -123,18 +123,20 @@ static struct user *authenticate(struct mg_http_message *hm) {
static void handle_login(struct mg_connection *c, struct user *u) {
char cookie[256];
mg_snprintf(cookie, sizeof(cookie),
"Set-Cookie: access_token=%s;Path=/;"
"HttpOnly;SameSite=Lax;Max-Age=%d\r\n",
u->access_token, 3600 * 24);
"Set-Cookie: access_token=%s; Path=/; "
"%sHttpOnly; SameSite=Lax; Max-Age=%d\r\n",
u->access_token, c->is_tls ? "Secure; " : "", 3600 * 24);
mg_http_reply(c, 200, cookie, "{%m:%m}", MG_ESC("user"), MG_ESC(u->name));
}
static void handle_logout(struct mg_connection *c) {
mg_http_reply(c, 200,
"Set-Cookie: access_token=; Path=/; "
"Expires=Thu, 01 Jan 1970 00:00:00 UTC; "
"Secure; HttpOnly; Max-Age=0; \r\n",
"true\n");
char cookie[256];
mg_snprintf(cookie, sizeof(cookie),
"Set-Cookie: access_token=; Path=/; "
"Expires=Thu, 01 Jan 1970 00:00:00 UTC; "
"%sHttpOnly; Max-Age=0; \r\n",
c->is_tls ? "Secure; " : "");
mg_http_reply(c, 200, cookie, "true\n");
}
static void handle_debug(struct mg_connection *c, struct mg_http_message *hm) {