Skip to content

fix(sdk): keep credentials inside the origin when a redirect leaves it - #398

Open
carmelc wants to merge 1 commit into
mainfrom
fix/strip-credentials-on-cross-origin-redirect
Open

carmelc wants to merge 1 commit into
mainfrom
fix/strip-credentials-on-cross-origin-redirect

Conversation

@carmelc

@carmelc carmelc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

What

Credentialed requests from the SDK set no redirect handling. When a redirect leads to another origin, the HTTP client follows it and only drops Authorization; the SDK's custom credential headers stay on the request.

This PR keeps following redirects and removes the credentials on a hop to another origin.

  • fetchWithAuth: when the request carries a server credential (Base44-Service-Authorization or Base44-State), the SDK follows redirects itself. A hop to another origin goes without Authorization, Base44-Service-Authorization and Base44-State. They are not restored if a later hop returns to the app.
  • axios clients: sensitiveHeaders (axios ≥ 1.20, already our minimum) lists Authorization, on-behalf-of, Base44-Service-Authorization and Base44-State. axios drops them on a redirect to another origin and keeps them on a same-origin one.

Why not redirect: "manual" / maxRedirects: 0

Turning redirect following off is the usual fix, and it is shorter. It also changes behaviour for every app whose route or API call redirects today:

Stop following (manual / maxRedirects: 0) This PR
Same-origin redirect (route A → route B, trailing slash) Caller now gets a 3xx and has to follow it by hand Followed, credentials kept, as today
Redirect to another origin that needs no credentials (signed storage URL, CDN) Caller now gets a 3xx Followed, as today, without our tokens
Redirect to another origin that relied on receiving our tokens Broken Broken (this is the case being closed)
Browser clients manual returns an opaque response that cannot be followed Untouched: the guard only runs when a server credential is on the request

So the only code that behaves differently is code that depended on the tokens arriving at another origin.

Other cases that stay as they are:

  • A caller who sets redirect in init keeps full control; the SDK does not step in.
  • An in-process transport (Nitro's fetch) returns the 3xx without a url and never followed redirects. The SDK returns that response as it is.

Differences from native fetch on the guarded path

  • response.redirected is false on the final response, since each hop is its own request. response.url is still the final URL.
  • A 307/308 with a streamed body throws, as fetch does, with the SDK's own message.

Verification

  • New tests/unit/redirect-credentials.test.ts runs real fetch and axios against two local HTTP servers. Three of its tests fail on main and pass here; the rest pin the behaviour that must not change (same-origin, 303/307 method rules, in-process transport, caller-set redirect).
  • Full suite: 493 tests pass. Lint and type tests pass. create-docs generates.
  • Cloudflare Workers, on a deployed probe app with placeholder tokens:
    • before: a cross-origin redirect delivered Base44-Service-Authorization to the other origin;
    • with this logic: the other origin receives neither it nor Authorization, and a same-origin redirect still receives both;
    • redirect: "manual" returns the real 3xx with url set, which the guard relies on.

Not covered

  • axios's fetch adapter ignores sensitiveHeaders. On Workers axios uses the Node http adapter, where a redirect currently fails before any second request is sent, so nothing leaves there either way.
  • Deno Deploy was not tested.

🤖 Generated with Claude Code

https://claude.ai/code/session_018bQbJdizPXhMxLN3cpSWj4

fetchWithAuth and the axios clients set no redirect handling, so a redirect
to another origin was followed with the custom credential headers still on
the request: fetch and follow-redirects only drop Authorization.

Redirects are still followed. On a hop to another origin the request goes
on without Authorization, on-behalf-of, Base44-Service-Authorization and
Base44-State.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018bQbJdizPXhMxLN3cpSWj4
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.8.64-pr.398.d867f81

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.64-pr.398.d867f81"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.8.64-pr.398.d867f81"
  }
}

Preview published to npm registry — try new features instantly!

@github-actions github-actions Bot added the docs-draft PR has auto-drafted documentation suggestions label Nov 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-draft PR has auto-drafted documentation suggestions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant