Skip to content

Docs: with X-Requested-With an ended session answers 403, not 401 - #69

Merged
jallers merged 2 commits into
masterfrom
claude/expired-session-docs
Nov 27, 2026
Merged

jallers merged 2 commits into
masterfrom
claude/expired-session-docs

Conversation

@jallers

@jallers jallers commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Documentation only: no behaviour changes, and the version is not bumped. v1.0.0-alpha.12 is already tagged, so this is the first change towards alpha.13; its changelog entry sits under an "Unreleased" heading for the release pull request to rename.

What was wrong

createFetchTransport's comment on credentials advised a cookie-session browser app to send X-Requested-With: XMLHttpRequest "so the server answers 401 rather than a login page".

A browser-app consumer ended a real session (one product release, OIDC sign-in, the provider refusing to refresh) and saw the opposite effect:

Request Status WWW-Authenticate Body
without the header 401 Bearer realm=… {"error":"Unauthorized"}
with X-Requested-With: XMLHttpRequest 403 the same the same

Neither was a redirect. onUnauthorized runs for unauthorizedStatuses, default [401], so an app that followed the advice never had its hook called when a session ended.

What this changes

  • The credentials comment says what was seen, and what follows: without the header an ended session is a 401 and the hook runs by default; with it, set unauthorizedStatuses: [401, 403].
  • The unauthorizedStatuses comment says a hook called for a 403 should first check that the session is really gone (a one-row read with reauthorize: false), because a 403 may also be a permission denial.
  • The "retry-write" comment records that a write refused with that 403 was not applied and landed once when replayed.
  • Example 09, a README line and a changelog entry with the migration line say the same.

What is not checked, and is said so

  • Other releases and other ways of signing in.
  • Whether a 403 for a genuine permission denial carries the same challenge. Until that is known the SDK still classifies every 403 as kind: "forbidden"; whether a 403 with a challenge should count as an auth failure is a separate decision, not made here.

Verification

npm run verify: 289 unit tests in 36 files, all passing (the example compiles). The expiry itself rests on the consumer's evidence; it cannot be reproduced where this was written, because every request there is authenticated.


Generated by Claude Code

… it an ended session answers 403, not 401

Documentation only. The transport's comment advised the header so that
the server would answer 401; a consumer who ended a real session saw a
401 without it and a 403 with it. An app sending the header needs
unauthorizedStatuses [401, 403] and a session check in its hook.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rgicmffzzwb2CzyeDSEhBm
…st for client.lists

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rgicmffzzwb2CzyeDSEhBm
@jallers
jallers merged commit d5f8ee0 into master Nov 27, 2026
4 checks passed
@jallers
jallers deleted the claude/expired-session-docs branch November 27, 2026 01:34
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.

2 participants