Skip to content

fix(provider-pollo): stop following redirects with the API key - #466

Open
wjsoj wants to merge 2 commits into
hypit-ai:mainfrom
wjsoj:fix/pollo-api-key-redirect
Open

wjsoj wants to merge 2 commits into
hypit-ai:mainfrom
wjsoj:fix/pollo-api-key-redirect

Conversation

@wjsoj

@wjsoj wjsoj commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Closes #476

Problem

PolloClient.json() authenticates every Pollo API request with an x-api-key header and lets fetch follow redirects (the default redirect: "follow"). On a cross-origin redirect, Node's fetch (undici) drops authorization, cookie and proxy-authorization, but it keeps custom headers. x-api-key is a custom header, so it goes to whatever host the Location header names. Fetch also follows an https: to http: redirect, which would send the key in cleartext.

The other gateway Providers (BeatAPI, HiAPI, Monid, TokenDance, HypiHub) use authorization: Bearer, which fetch already strips on a cross-origin hop. Pollo is the only one whose credential survives the redirect.

Impact

Low to medium. Exploiting this needs a 3xx from the configured Pollo API origin: an open redirect on that host, a misconfigured gateway or proxy in front of it, or a custom baseUrl pointing at a service that redirects. When that happens, the user's Pollo API key (a billing credential) goes to a third-party host with no warning.

Reproduction

The new test packages/provider-pollo/test/redirect.test.ts starts two loopback servers. The "Pollo API" answers with 307 Location: http://127.0.0.1:<other>/collect?signature=... (a different port, so a different origin), and the other server records the x-api-key it receives. It runs once for the status poll and once for the POST submit (start). On main, the second server receives POLLO_SECRET_KEY:

AssertionError: the redirect target must not be contacted with the API key
+ [ 'POLLO_SECRET_KEY' ]
- []

Fix

Authenticated Pollo API requests now use redirect: "manual". A redirect from the API comes back as a non-OK response and is reported through the existing PolloHttpError path (same POLLO_HTTP_ERROR code, not retried). For a 3xx, the message now says the redirect was not followed, names only the origin of its Location (scheme, host and port, never the path or query, so a signed URL does not leak), and suggests setting baseUrl to that origin if it is the genuine Pollo API. For example, a baseUrl on www.pollo.ai that redirects to pollo.ai gives:

Pollo HTTP 301; POLLO_HTTP_ERROR; GET /v1/...; redirect to https://pollo.ai not followed; the API key is never sent to a redirect target. If https://pollo.ai is the genuine Pollo API, set baseUrl to that origin
``` Result downloads (`download()`) carry no credential and are unchanged.

## Tests

- `node --import tsx --test packages/provider-pollo/test/*.test.ts`: 5 passed. The two redirect tests (poll and submit) fail on main and pass with the change. They also check that the error names the refused redirect and its origin, and contains neither the redirect path/query nor the API key.
- `pnpm check`: passed
- `pnpm test`: passes in CI (Linux and Windows); all checks on this PR are green.



wjsoj added 2 commits November 5, 2026 08:00
Pollo authenticates with an x-api-key header. Fetch strips authorization
on a cross-origin redirect but forwards custom headers, so any 3xx from
the Pollo API host handed the key to the host named in Location,
including a plain-HTTP one. Send API requests with redirect: manual so
a redirect surfaces as an HTTP error instead of being followed.
A 3xx from Pollo now says the redirect was not followed, names only the
origin of its Location (never path or query), and suggests setting
baseUrl to that origin if it is the genuine Pollo API. The redirect test
now covers both submit and poll, redirecting to 127.0.0.1 on a second port.
SanHsien added a commit to SanHsien/hypit that referenced this pull request Nov 7, 2026
…i#460-hypit-ai#474; advance watermarks

No PR was merged upstream, so nothing was cherry-picked: 11 PRs = 5 defer
(hypit-ai#464 hypit-ai#466 hypit-ai#467 hypit-ai#469 hypit-ai#471, pinned in monitored) + 6 not applicable; 5 issues =
1 defer (hypit-ai#473) + 4 not applicable. hypit-ai#464 npm pin is moot because the fork gates
publish jobs to upstream (b641cce). ROADMAP row updated with the deferred items.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
SanHsien added a commit to SanHsien/hypit that referenced this pull request Nov 7, 2026
…f upstream PR hypit-ai#466)

Ported before upstream merge: x-api-key is a custom header that fetch forwards
across a cross-origin redirect. Authenticated requests now use redirect:
"manual"; a 3xx is reported through PolloHttpError naming only the target
origin. Tests from the PR fail before the change (2) and pass after (5/5).
Replace with upstream's version once hypit-ai#466 is merged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Pollo API key is forwarded to the redirect target when the Pollo API answers with a 3xx

1 participant