Skip to content

Invalid stored token expiry is treated as a valid session #186

Backlog

Description

@fernandatoledo

Problem

The token expiry check treats an invalid date as "not expired". dayjs().isAfter(dayjs('garbage')) is false, so a stored expiry that isn't a valid date counts as a valid session. This applies to checkToken in AuthProvider (auth.tsx#L126) and to the request interceptor (auth.tsx#L62).

An invalid value can be stored: the response interceptor builds the expiry with dayjs.unix(Number.parseInt(expiryHeader, 10)) (auth.tsx#L87), and an expiry header that isn't numeric gives NaN and an invalid date.

Impact

The session never expires on the client. isAuthenticated stays true, and the request interceptor never clears the tokens. With #183, hasValidSession() reuses the same check to route deep links, so those would open protected screens directly too.

Fix

Treat an invalid expiry as expired, e.g.:

const expiry = dayjs(expiration);
const isExpired = !expiry.isValid() || dayjs().isAfter(expiry);

Also consider not storing tokens when the expiry header doesn't parse. Add a test for a stored expiry that isn't a valid date.

Found while reviewing #183.

Activity

  1. added
    bug
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions