Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vc/src/verification/is-expired.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ describe("isExpired", () => {
expect(isExpired(credential)).toBe(false)
})

it("handles invalid date strings gracefully", () => {
it("treats invalid date strings as expired (fail-closed)", () => {
const credential = buildCredential("invalid-date")

expect(isExpired(credential)).toBe(false)
expect(isExpired(credential)).toBe(true)
})
})
15 changes: 12 additions & 3 deletions packages/vc/src/verification/is-expired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import type { W3CCredential } from "../types"
* Check if a credential is expired
*
* @param credential - The {@link W3CCredential} to check
* @returns `true` if the credential is expired, `false` otherwise
* @returns `true` if the credential is expired or has an unparseable
* `expirationDate`, `false` if it is verifiably not yet expired
*
* An unparseable date is treated as expired rather than "not expired":
* a credential whose expiry cannot be established should not pass an
* expiry check, consistent with the fail-closed approach used elsewhere
* in this verification pipeline (e.g. `resolveStatusListCredential`
* throws on an unreadable `expirationDate` instead of treating it as
* absent).
*/
export function isExpired(credential: W3CCredential): boolean {
if (!credential.expirationDate) {
Expand All @@ -14,8 +22,9 @@ export function isExpired(credential: W3CCredential): boolean {
const expirationDate = new Date(credential.expirationDate)

if (isNaN(expirationDate.getTime())) {
// Expiration date is invalid, so we consider the credential not expired
return false
// An unreadable expiry date cannot be verified — treat as expired
// (fail-closed) rather than silently allowing the credential through.
return true
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

return expirationDate < new Date()
Expand Down