Skip to content

fix(upload): refresh the upload token when Storage reports it expired - #361

Merged
riglar merged 1 commit into
devfrom
fix/signed-upload-expired-token
Nov 24, 2026
Merged

riglar merged 1 commit into
devfrom
fix/signed-upload-expired-token

Conversation

@riglar

@riglar riglar commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What's wrong

When Storage refuses a signed upload because of its token, the CLI should get a fresh token and carry on (#360). It decides that from the error text, and it only looked for "jwt", "signature" or "expired".

Storage checks the token with a JWT library first. For an expired token, that library fails with "exp" claim timestamp check failed, before Storage's own "The provided token has expired." That message contains none of those words.

So a request refused for an expired token failed the signed upload instead of refreshing. The CLI then fell back to the temp path, so the upload still worked, but slower.

It rarely happens, because the CLI already refreshes before any request when the token has under 10 minutes left. It mostly matters when the client's clock is off.

The fix

The check now also matches "exp" claim and JWS. Storage sends "Invalid Compact JWS" for a token that isn't a JWT at all. The comment lists the messages Storage sends:

  • "Invalid signature" and "Invalid Compact JWS": seen against a real Storage instance.
  • The expired-token message: from reading Storage's source. I couldn't trigger it, since tokens last about two hours.

Tests

A unit test now checks all four messages. pnpm lint, pnpm typecheck, pnpm test:unit (780 passing) and pnpm build pass.

🤖 Generated with Claude Code

Storage checks a signed upload token with a JWT library that rejects an
expired token with `"exp" claim timestamp check failed`, before Storage's
own expiry message. The check for a refused token looked only for "jwt",
"signature" or "expired", so it missed that message. A request refused for
an expired token then failed the signed upload instead of getting a fresh
token and carrying on. Also match "Invalid Compact JWS", which Storage
sends for a token that is not a JWT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@riglar
riglar merged commit 161c428 into dev Nov 24, 2026
9 checks passed
@riglar
riglar deleted the fix/signed-upload-expired-token branch November 24, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant