fix(ci): narrow Auth.js subject and extend disposable P05 verification

This commit is contained in:
Vib Tools committed 2026-11-22 05:24:04 -08:00
1 parent 42adaba004
commit c27fe3d323
23 files changed
+415 -45

No files matched your search

+9 -5
View File
@@ -48,19 +48,23 @@ export const { handlers, auth, signIn, signOut } = NextAuth(() => {
return token;
},
async session({ session, token }) {
// Narrow the untrusted JWT claim to a string before constructing the
// Auth.js Session. A boolean "valid" expression does not narrow the
// original unknown claim in the callback return type (P05-B01 TS2345).
const subject: string =
typeof token.zitadelSubject === "string" ? token.zitadelSubject : "";
const valid =
typeof token.zitadelSubject === "string" &&
token.zitadelSubject.length > 0 &&
subject.length > 0 &&
typeof token.zitadelTokenExpiresAt === "number" &&
token.zitadelTokenExpiresAt * 1000 > Date.now();
// Never expose an authenticated identity when an OIDC token has expired.
// Every page and API checks nonempty user.id; do not gate on !!session alone.
// Fail closed: expired/missing provider tokens expose no user identity.
// Every page and API checks nonempty user.id, not just !!session.
return {
...session,
user: {
...session.user,
id: valid ? token.zitadelSubject! : ""
id: valid ? subject : ""
}
};
}