Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Upload fails if authentication token is refreshed while on submission form (401Unauthorized error) #3979

Open
MoeBen23 opened this issue Feb 5, 2025 · 3 comments
Labels
authentication: general general authentication issues bug component: submission help wanted Needs a volunteer to claim to move forward high priority

Comments

@MoeBen23
Copy link

MoeBen23 commented Feb 5, 2025

Description

Hi,

Some of our users have reported encountering errors when uploading files after a certain period of time. Specifically, the DSpace client displays an “Error Loading File” message once the JWT token is renewed by the front-end client.

This issue arises when a user’s submission process exceeds 30 minutes. The front-end client renews the token 2 minutes before session timeout; however, it does not use the new token if the user attempts to upload files after the renewal.

We are currently using DSpace 7.6.2. Could you provide any insights or recommendations on resolving this issue?

Thanks.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Log in to DSpace using local authentication.
  2. Start a new submission.
  3. Upload files periodically (e.g., every few minutes). Initially, all uploads succeed.
  4. The DSpace client automatically renews the JWT token via a server call to the /login endpoint.
  5. After the token renewal, any subsequent file upload attempts fail with a 401 Unauthorized error.

Expected behavior

The JWT token timeout is set to 30 minutes. By default, the client renews the token 2 minutes before expiration. Once the new token is received, it should be used for all subsequent file uploads without failure.

Observed Issue

Currently, file uploads continue to use the expired token instead of the newly issued one.
On failed upload requests, the Bearer token in the request header differs from the token stored in the cookie, indicating a mismatch.

Screenshots:

In the screenshot below, I monitored network traffic using Google Chrome Developer Tools

Image1: Three uploads were done successfully

Image

Image 2: DSpace renews the token. This happens 2 min before it expires.

Image

Image 3: All uploads attempts fail after the token renewal. I attempted to upload two files.

Image

Image

Image 4: The failed upload request contains a different token in the header compared to the one in the cookie. It uses the old one in the header, and the new one in the cookie.

Image

@MoeBen23 MoeBen23 added bug needs triage New issue needs triage and/or scheduling labels Feb 5, 2025
@bram-atmire
Copy link
Member

Hi @MoeBen23 Thank you for reporting this!!! I think we may have to tackle this in the Angular front end codebase instead of here, but I already wanted to share here what I found:

It seems we're already defending against the xsrf tokens expiring, but not the JWT tokens in

https://github.com/DSpace/dspace-angular/blob/dspace-7_x/src/app/shared/upload/uploader/uploader.component.ts#L137C1-L150C6

One suggestion could be something along the lines of:

this.uploader.onBeforeUploadItem = (item: any) => {
    const latestJwt = this.authService.getToken(); // Fetch the latest JWT token
    if (latestJwt) {
        item.headers.push({ name: 'Authorization', value: `Bearer ${latestJwt}` });
    }
};

@MoeBen23
Copy link
Author

MoeBen23 commented Feb 11, 2025

Thanks @bram-atmire . That’s great! It took me a while to reproduce this issue. Would you recommend re-creating it in the Angular front-end issue repository so it can potentially be included in an upcoming patch?

@tdonohue tdonohue added component: submission authentication: general general authentication issues high priority help wanted Needs a volunteer to claim to move forward and removed needs triage New issue needs triage and/or scheduling labels Feb 12, 2025
@tdonohue
Copy link
Member

Moving this ticket to dspace-angular as I also think this is frontend bug. Needs a volunteer to investigate a solution and/or create a PR (@bram-atmire if you or someone from Atmire have found a solution, please feel free to create a PR).

@tdonohue tdonohue transferred this issue from DSpace/DSpace Feb 12, 2025
@tdonohue tdonohue changed the title 401 DSpace Unauthorized file upload after refreshing token File Upload fails if authentication token is refreshed while on submission form (401Unauthorized error) Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
authentication: general general authentication issues bug component: submission help wanted Needs a volunteer to claim to move forward high priority
Projects
Development

No branches or pull requests

3 participants