Skip to content

Frontend: handle 401 responses by clearing session, and skip sending expired JWTs #5391

Closed

Description

@Yicong-Huang

What happened?

frontend/src/app/app.module.ts configured JwtModule.forRoot with skipWhenExpired: false, and the app had no global HttpInterceptor that observed 401 responses. Two consequences:

  1. Whenever localStorage held a JWT, that token was attached as Authorization: Bearer … to every non-disallowedRoutes request — including the anonymous pre-login config fetch — even after its exp was in the past. The backend then rejected the stale token, breaking page bootstrap.
  2. Individual services scattered their own catchError calls but none cleared the session or redirected to the landing page, so a backend-rejected token left the user "logged in" client-side: header still showed the user, but every authenticated request errored out.

The earlier eager-JwtAuthFilter attempt (PR #4903) merged on main and the very next day a user with a stale localStorage token reproduced this — the login page itself returned 401 for GET /api/config/gui and /api/config/user-system, which triggered the revert in PR #5025 (issue #5026).

How to reproduce?

  1. Reach a state where localStorage contains an access_token whose exp claim is in the past — e.g. open DevTools and run localStorage.setItem("access_token", "<old-token-from-a-prior-session>"), or close the tab for longer than the configured expiration-in-minutes (7 days as of PR feat(auth): removed token refresh functionality #3765) and re-open.
  2. Visit the app at /about.
  3. Observe (against the pre-fix(frontend): handle 401 by clearing session, skip sending expired JWTs #5392 commit 8a4cb29e1):
    • Every request, including the anonymous /api/config/pre-login and /api/config/gui fetches, carries the stale Authorization header.
    • Backend (amber toastshaman filter, or JwtAuthFilter once eager-401 is enabled) rejects with 401.
    • No global handler clears the bad token or redirects, so the user sees a generic error toast and the page stays in a broken state.

Branch

main

Commit Hash (Optional)

8a4cb29 (immediately before PR #5392 landed)

What browsers are you seeing the problem on?

  • Chrome / Chromium

Relevant log output

ERROR org.apache.texera.auth.JwtParser$: Failed to parse JWT: JWT (claims->{"sub":"texera","userId":1,"role":"ADMIN","exp":1777324924}) rejected due to invalid claims or other invalid content. Additional details: [[1] The JWT is no longer valid - the evaluation time NumericDate{... May 11, 2026, 12:33:08 PM PDT} is on or after the Expiration Time (exp=NumericDate{... Apr 27, 2026, 2:22:04 PM PDT}) claim value (even when providing 30 seconds of leeway to account for clock skew).]
WARN  org.apache.texera.auth.JwtAuthFilter: Invalid JWT: Unable to parse token
INFO  org.eclipse.jetty.server.RequestLog: [0:0:0:0:0:0:0:1] - "GET /api/config/user-system HTTP/1.1" 401
INFO  org.eclipse.jetty.server.RequestLog: [0:0:0:0:0:0:0:1] - "GET /api/config/gui HTTP/1.1" 401

Activity

  1. added theissue type on Jun 5, 2026
  2. added a commit that references this issue on Jun 6, 2026
    184da39
  3. added a commit that references this issue on Jun 6, 2026
    749798d
  4. changed the issue type fromtoon Jun 6, 2026
  5. added a commit that references this issue on Jun 22, 2026
    f131cda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions