Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor(auth): drop the session rejection reason code

Thiago Araujo da Silva71853b1b4fa2
diff --git a/backend/src/server/plugins/error-handler.ts b/backend/src/server/plugins/error-handler.ts
index 0ca8f01111..cb28431800 100644
--- a/backend/src/server/plugins/error-handler.ts
+++ b/backend/src/server/plugins/error-handler.ts
@@ -130,8 +130,7 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
orgId: req.auth?.orgId,
realIp: req.realIp,
actor: req.auth?.actor,
- details: (error as { details?: unknown }).details,
- detail: (error as { detail?: unknown }).detail
+ details: (error as { details?: unknown }).details
},
`client error: ${error.name}`
);
diff --git a/backend/src/services/auth-token/auth-token-service.test.ts b/backend/src/services/auth-token/auth-token-service.test.ts
index 8341a6f546..2ab22880a0 100644
--- a/backend/src/services/auth-token/auth-token-service.test.ts
+++ b/backend/src/services/auth-token/auth-token-service.test.ts
@@ -345,14 +345,16 @@ describe("tokenServiceFactory — org scope of user tokens", () => {
});
// UnauthorizedError, not NotFoundError: clients only treat a 401 as "log in again", and a 404 reads as a missing resource.
- // Every such case shares one public name and message; only `detail`, which is logged and never sent, tells them apart.
test("a token whose session no longer exists is refused with UnauthorizedError", async () => {
const { service } = build({ session: null });
const err = await expectRejected(
service.fnValidateJwtIdentity(accessToken({ organizationId: ROOT })),
UnauthorizedError
);
- expect(err).toMatchObject({ name: "InvalidToken", detail: { reasonCode: "session_not_found" } });
+ expect(err).toMatchObject({
+ name: "InvalidToken",
+ message: "Your session is no longer valid, please re-authenticate"
+ });
});
test("a token issued before its session was invalidated is refused with UnauthorizedError", async () => {
@@ -361,7 +363,10 @@ describe("tokenServiceFactory — org scope of user tokens", () => {
service.fnValidateJwtIdentity(accessToken({ organizationId: ROOT })),
UnauthorizedError
);
- expect(err).toMatchObject({ name: "InvalidToken", detail: { reasonCode: "session_stale" } });
+ expect(err).toMatchObject({
+ name: "InvalidToken",
+ message: "Your session is no longer valid, please re-authenticate"
+ });
});
test("a token whose user no longer exists is refused with UnauthorizedError", async () => {
@@ -370,7 +375,10 @@ describe("tokenServiceFactory — org scope of user tokens", () => {
service.fnValidateJwtIdentity(accessToken({ organizationId: ROOT })),
UnauthorizedError
);
- expect(err).toMatchObject({ name: "InvalidToken", detail: { reasonCode: "user_unavailable" } });
+ expect(err).toMatchObject({
+ name: "InvalidToken",
+ message: "Your session is no longer valid, please re-authenticate"
+ });
});
test("a token whose user is not accepted is refused with UnauthorizedError", async () => {
diff --git a/backend/src/services/auth-token/auth-token-service.ts b/backend/src/services/auth-token/auth-token-service.ts
index 468841d817..6d44021890 100644
--- a/backend/src/services/auth-token/auth-token-service.ts
+++ b/backend/src/services/auth-token/auth-token-service.ts
@@ -358,12 +358,10 @@ export const tokenServiceFactory = ({ tokenDAL, userDAL, orgDAL, keyStore }: TAu
return { newRefreshToken, updatedSession };
};
- // The caller learns only that it must log in again; why the session ended stays in the server log via `detail`.
- const sessionNoLongerValid = (reasonCode: "session_not_found" | "session_stale" | "user_unavailable") =>
+ const sessionNoLongerValid = () =>
new UnauthorizedError({
name: "InvalidToken",
- message: "Your session is no longer valid, please re-authenticate",
- detail: { reasonCode }
+ message: "Your session is no longer valid, please re-authenticate"
});
const validateUserSessionFreshness = async ({
@@ -380,13 +378,13 @@ export const tokenServiceFactory = ({ tokenDAL, userDAL, orgDAL, keyStore }: TAu
const session = await tokenDAL.findOneTokenSession({ id: tokenVersionId, userId }, undefined, {
readFromPrimary
});
- if (!session) throw sessionNoLongerValid("session_not_found");
- if (accessVersion !== session.accessVersion) throw sessionNoLongerValid("session_stale");
+ if (!session) throw sessionNoLongerValid();
+ if (accessVersion !== session.accessVersion) throw sessionNoLongerValid();
const user = await requestMemoize(requestMemoKeys.userFindById(session.userId), () =>
userDAL.findById(session.userId)
);
- if (!user || !user.isAccepted) throw sessionNoLongerValid("user_unavailable");
+ if (!user || !user.isAccepted) throw sessionNoLongerValid();
if (isUserLocked(user)) {
throw new UnauthorizedError({ message: "Account is locked" });