diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestHandler.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestHandler.java index debfe59c0..b8cae1cce 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestHandler.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestHandler.java @@ -146,7 +146,7 @@ public class RequestHandler implements HttpHandler { String directTo = StringUtils.startsWithAny(from, "/auth/", "/login") ? "/login" : "/login?from=." + from; response = Response.builder() .redirectTo(directTo) - .setHeader("Set-Cookie", "auth=expired; Path=/; Max-Age=1; SameSite=Lax; Secure;") + .setHeader("Set-Cookie", "auth=expired; Path=/; Max-Age=0; SameSite=Lax; Secure;") .build(); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieExpiryCleanupTask.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieExpiryCleanupTask.java index bbead20d1..771d5e83a 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieExpiryCleanupTask.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/ActiveCookieExpiryCleanupTask.java @@ -17,9 +17,12 @@ package com.djrapitops.plan.delivery.webserver.auth; import com.djrapitops.plan.TaskSystem; +import com.djrapitops.plan.settings.config.PlanConfig; +import com.djrapitops.plan.settings.config.paths.PluginSettings; import dagger.Lazy; import net.playeranalytics.plugin.scheduling.RunnableFactory; import net.playeranalytics.plugin.scheduling.TimeAmount; +import net.playeranalytics.plugin.server.PluginLogger; import javax.inject.Inject; import javax.inject.Singleton; @@ -32,13 +35,17 @@ import java.util.concurrent.TimeUnit; @Singleton public class ActiveCookieExpiryCleanupTask extends TaskSystem.Task { + private final PlanConfig config; private final Lazy activeCookieStore; + private final PluginLogger logger; private final Map expiryDates; @Inject - public ActiveCookieExpiryCleanupTask(Lazy activeCookieStore) { + public ActiveCookieExpiryCleanupTask(PlanConfig config, Lazy activeCookieStore, PluginLogger logger) { + this.config = config; this.activeCookieStore = activeCookieStore; + this.logger = logger; this.expiryDates = new ConcurrentHashMap<>(); } @@ -56,14 +63,21 @@ public class ActiveCookieExpiryCleanupTask extends TaskSystem.Task { Set removed = new HashSet<>(); for (Map.Entry entry : expiryDates.entrySet()) { Long expiryTime = entry.getValue(); - if (expiryTime >= time) { + if (config.isTrue(PluginSettings.DEV_MODE)) { + logger.info("Cookie " + entry.getKey() + " will expire " + expiryTime); + } + if (expiryTime <= time) { String cookie = entry.getKey(); activeCookieStore.get().removeCookie(cookie); + removed.add(cookie); } } for (String removedCookie : removed) { expiryDates.remove(removedCookie); + if (config.isTrue(PluginSettings.DEV_MODE)) { + logger.info("Cookie " + removedCookie + " has expired: " + time); + } } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/auth/LogoutResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/auth/LogoutResolver.java index 356481ecd..69def1397 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/auth/LogoutResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/auth/LogoutResolver.java @@ -63,7 +63,7 @@ public class LogoutResolver implements NoAuthResolver { public Response getResponse() { return Response.builder() .redirectTo("/login") - .setHeader("Set-Cookie", "auth=expired; Max-Age=1; SameSite=Lax; Secure;") + .setHeader("Set-Cookie", "auth=expired; Max-Age=0; SameSite=Lax; Secure;") .build(); } }