Skip to content

fix(api): prevent credential forwarding across redirects - #239

Merged
paulkr merged 4 commits into
withoneai:mainfrom
RachitSrivastava12:fix/api-cross-origin-redirect-secrets
Nov 19, 2026
Merged

paulkr merged 4 commits into
withoneai:mainfrom
RachitSrivastava12:fix/api-cross-origin-redirect-secrets

Conversation

@RachitSrivastava12

Copy link
Copy Markdown
Contributor

Native fetch strips standard auth headers on cross-origin redirects, but custom headers like x-one-secret and x-one-connection-key can still be forwarded.

This change adds explicit redirect handling to OneApi so credential-bearing requests only follow same-origin redirects.

It also sets redirect: "error" in the generated fetch examples, since those requests carry the same credentials.

Added regression tests for cross-origin redirects, relative URLs, redirect loops, malformed locations, and 301/302/303/307/308 behavior.

Tested

  • TMPDIR=/private/tmp npm test — 871 passed
  • npm run typecheck
  • npm run build
  • git diff --check

I reproduced the header forwarding behavior locally with dummy credentials. I haven't verified whether the hosted passthrough backend returns upstream redirects to the CLI.

RachitSrivastava12 and others added 4 commits November 19, 2026 05:51
…e-safe

- Follow 20 same-origin redirects before failing, as native fetch does
  (the guard stopped after 19).
- Name the refused origin in the redirect error. Only the origin: a
  redirect's path and query can carry tokens.
- Generated fetch code uses redirect: "manual" plus a 3xx check instead of
  redirect: "error". Cloudflare Workers throws a TypeError on "error", so
  every call from a Worker built from the snippet failed.
- Test that the generated code returns an ordinary response unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main moved to 2.15.0 (withoneai#240); this fix ships as the next patch.

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

paulkr commented Nov 19, 2026

Copy link
Copy Markdown
Member

Thanks @RachitSrivastava12, this is a good catch. I reproduced it on main: a cross-origin 307 from the API host sent x-one-secret, x-one-connection-key and the caller's headers to the other origin, and the CLI returned that origin's response as the real one. Your branch blocks both, and the tests fail without the fix.

I pushed a few changes to your branch so we can ship it:

  • Generated snippet: switched redirect: "error" to redirect: "manual" plus a 3xx check. Cloudflare Workers throws a TypeError on "error" (it only accepts follow and manual), so every call from a Worker built from the snippet would have failed. I checked it in workerd.
  • Redirect limit: the guard now follows 20 redirects before failing, the same as native fetch. It stopped at 19 before.
  • Error message: the refused-redirect error now names the origin it refused, without the path or query.
  • Tests: added one that checks the snippet passes normal responses through.
  • Version: merged main and bumped to 2.15.1.

CI is green on Ubuntu and Windows for Node 22, 24 and 26. Thanks again for the report and the thorough tests.

@paulkr
paulkr merged commit 27767ce into withoneai:main Nov 19, 2026
8 checks passed
@RachitSrivastava12

Copy link
Copy Markdown
Contributor Author

Thanks @RachitSrivastava12, this is a good catch. I reproduced it on main: a cross-origin 307 from the API host sent x-one-secret, x-one-connection-key and the caller's headers to the other origin, and the CLI returned that origin's response as the real one. Your branch blocks both, and the tests fail without the fix.

I pushed a few changes to your branch so we can ship it:

  • Generated snippet: switched redirect: "error" to redirect: "manual" plus a 3xx check. Cloudflare Workers throws a TypeError on "error" (it only accepts follow and manual), so every call from a Worker built from the snippet would have failed. I checked it in workerd.
  • Redirect limit: the guard now follows 20 redirects before failing, the same as native fetch. It stopped at 19 before.
  • Error message: the refused-redirect error now names the origin it refused, without the path or query.
  • Tests: added one that checks the snippet passes normal responses through.
  • Version: merged main and bumped to 2.15.1.

CI is green on Ubuntu and Windows for Node 22, 24 and 26. Thanks again for the report and the thorough tests.

Thanks @paulkr! Appreciate you checking this and making the compatibility fixes.

I also opened #241 to address flow actions continuing after timeout, with cancellation propagation and regression tests. Would appreciate a look when you get a chance!

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