You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2026/06/29 17:49:40 UTC

(airavata-custos) branch web updated: Rename session cookie to custos.session-token and shorten the lifetime

This is an automated email from the ASF dual-hosted git repository.

lahirujayathilake pushed a commit to branch web
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git


The following commit(s) were added to refs/heads/web by this push:
     new be4d613ce Rename session cookie to custos.session-token and shorten the lifetime
be4d613ce is described below

commit be4d613ce5d6a6c693a173b722f2b9c4ccb5f069
Author: lahiruj <la...@gmail.com>
AuthorDate: Mon Jun 29 13:49:33 2026 -0400

    Rename session cookie to custos.session-token and shorten the lifetime
---
 web/src/app/api/auth/end-session/route.ts | 12 ++++++------
 web/src/shared/auth/auth.ts               | 22 +++++++++++++++++++++-
 web/tests/fixtures/auth.ts                |  4 ++--
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/web/src/app/api/auth/end-session/route.ts b/web/src/app/api/auth/end-session/route.ts
index 9827e983b..ff8451b70 100644
--- a/web/src/app/api/auth/end-session/route.ts
+++ b/web/src/app/api/auth/end-session/route.ts
@@ -21,15 +21,15 @@ import { auth } from "@/shared/auth/auth";
 
 export const runtime = "nodejs";
 
-// next-auth v5 session cookie names — cleared inline so the redirect lands on
-// /sign-in already-signed-out, regardless of whether Keycloak round-trips.
-const NEXT_AUTH_COOKIES = [
-  "authjs.session-token",
-  "__Secure-authjs.session-token",
+// Cleared inline so the redirect lands on /sign-in already-signed-out,
+// regardless of whether the IdP round-trips.
+const SESSION_COOKIES = [
+  "custos.session-token",
+  "__Secure-custos.session-token",
 ];
 
 function clearAuthCookies(res: NextResponse) {
-  for (const name of NEXT_AUTH_COOKIES) {
+  for (const name of SESSION_COOKIES) {
     res.cookies.set({ name, value: "", path: "/", maxAge: 0 });
   }
 }
diff --git a/web/src/shared/auth/auth.ts b/web/src/shared/auth/auth.ts
index a8114302f..9ad6496b8 100644
--- a/web/src/shared/auth/auth.ts
+++ b/web/src/shared/auth/auth.ts
@@ -24,11 +24,31 @@ function looksLikeJwt(token: string | null | undefined): boolean {
   return typeof token === "string" && token.split(".").length === 3;
 }
 
+const isProduction = serverEnv.NODE_ENV === "production";
+const sessionCookieName = isProduction
+  ? "__Secure-custos.session-token"
+  : "custos.session-token";
+
+// Match the access_token's natural lifetime; without refresh-token handling a
+// longer session is misleading — the inner bearer dies first.
+const SESSION_MAX_AGE_SECONDS = 60 * 60;
+
 export const authConfig: NextAuthConfig = {
   trustHost: true,
   secret: serverEnv.NEXTAUTH_SECRET,
-  session: { strategy: "jwt" },
+  session: { strategy: "jwt", maxAge: SESSION_MAX_AGE_SECONDS },
   pages: { signIn: "/sign-in" },
+  cookies: {
+    sessionToken: {
+      name: sessionCookieName,
+      options: {
+        httpOnly: true,
+        sameSite: "lax",
+        path: "/",
+        secure: isProduction,
+      },
+    },
+  },
   providers: [
     Keycloak({
       id: "oidc",
diff --git a/web/tests/fixtures/auth.ts b/web/tests/fixtures/auth.ts
index 040ce6c44..c0746d873 100644
--- a/web/tests/fixtures/auth.ts
+++ b/web/tests/fixtures/auth.ts
@@ -51,7 +51,7 @@ export async function signInAs(page: Page, persona: Persona = "admin") {
   }
 
   const token = await encode({
-    salt: "authjs.session-token",
+    salt: "custos.session-token",
     secret,
     token: {
       sub: `test-${persona}`,
@@ -65,7 +65,7 @@ export async function signInAs(page: Page, persona: Persona = "admin") {
   const port = process.env.PORT ?? "3217";
   await page.context().addCookies([
     {
-      name: "authjs.session-token",
+      name: "custos.session-token",
       value: token,
       url: `http://localhost:${port}`,
       httpOnly: true,