Skip to content

[Hackathon] fix(http): a redirect forwards the API key to the next host #446

Open

Description

@Ololadestephen

Verified against (commit SHA or released version)

commit 988c035 (main HEAD)

Discord Username / User ID

ololadestephen

What does this improvement do?

HttpClient calls fetch in src/lib/http.ts with no redirect option, so Node follows redirects. The API key is sent as the custom header x-api-key. Node strips Authorization on a cross-origin redirect, but it forwards x-api-key.

Verified with Node's own fetch: a 302 from one local port to another delivered x-api-key to the second server.

The CLI is supposed to talk only to the configured API endpoint. A redirect from that host, or from a proxy in front of it, sends the key to the next host.

Fix: do not follow a cross-origin redirect. Same-host redirects can still be followed. Add a test that a 302 to another origin does not receive x-api-key.

Details / implementation notes

The fetch call is in requestWithMeta (src/lib/http.ts, around the this.fetchImpl(url, …) call). buildHeaders sets x-api-key on every authenticated request. No new dependency.

Confirmations

  • I have searched existing issues and this is not a duplicate.
  • I have provided my Discord identity above for reward coordination.

Activity

  1. fyZhang66 commented on Oct 20, 2026

    @fyZhang66
    Contributor

    Confirmed on v0.15.0, thanks @Ololadestephen. fetch in http.ts follows redirects with default settings, and x-api-key is a custom header, so a cross-origin 302 carries the key to the next host. No user has hit this (our API never redirects cross-origin), but it is a one-line hardening. Accepted, scope:

    • redirect: 'error' on the shared client (or follow same-origin redirects only); a cross-origin redirect becomes a typed transport error naming both hosts.
    • Tests (must fail before the fix): a 302 to another origin never receives the key; same-origin behaviour unchanged.

    We'll review #500 against this. No new dependency.

  2. added
    acceptedTriaged and accepted — a PR for this will be reviewed
    and removed
    needs-triageNew issue/PR awaiting first triage
    on Oct 20, 2026
  3. Ololadestephen commented on Oct 20, 2026

    @Ololadestephen
    Author

    /assign

  4. testsprite-hob commented on Oct 20, 2026

    @testsprite-hob

    Assigned to @Ololadestephen. Thanks for taking this on. (2 more slots available.)

    Your open assigned issues (1/3):
    (none)

  5. Ololadestephen commented on Oct 20, 2026

    @Ololadestephen
    Author

    @fyZhang66 Thanks for confirming and accepting this. I’ve claimed the issue and will implement the scoped fix and regression tests. One clarification: you mentioned reviewing #500 against this issue, but its title concerns the raw API command. Is #500 the intended reference, or should I open a separate PR for #446?

  6. fyZhang66 commented on Oct 20, 2026

    @fyZhang66
    Contributor

    @Ololadestephen my bad #500 is unrelated, let's open a seperate pr for this issue, thank you.

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

Metadata

Metadata

Labels

acceptedTriaged and accepted — a PR for this will be reviewedhackathonCLI hackathon submissionsin-progressAssigned and actively being worked on

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions