Skip to content

fix: send profile auth headers when fetching the OpenAPI spec (supersedes #22) - #23

Merged
EvilFreelancer merged 4 commits into
mainfrom
fix/spec-auth-headers
Sep 4, 2026
Merged

fix: send profile auth headers when fetching the OpenAPI spec (supersedes #22)#23
EvilFreelancer merged 4 commits into
mainfrom
fix/spec-auth-headers

Conversation

@EvilFreelancer

Copy link
Copy Markdown
Owner

Summary

Supersedes #22 by @itsyoboieltr and keeps its two commits verbatim, with the original authorship. That change sent the profile credentials (--api-basic-auth, --api-bearer-token, --custom-headers) with the OpenAPI spec download, so a spec served behind auth could finally be loaded. A cross-review (Codex, Cursor, Coddy, plus a manual reproduction against a local HTTP server) found the issues below, which are fixed on top.

Added on top of #22

  • Credential leak to third-party hosts. The headers were forwarded to every external $ref URL, so a spec referencing https://evil.example/schema.yaml handed that host the user's Authorization header and custom headers. Headers now go only to the origins of --openapi-spec and --api-base-url; $ref documents on any other host are fetched anonymously. Reproduced with two local origins before the fix.
  • Headers lost on nested $ref. resolveRef rebuilt the resolve context without headers, so a root -> A -> B chain behind auth got 401 on B. The context now carries the auth scope through every hop. Reproduced with a three-document chain.
  • Injectable HTTP client for the loader. OpenapiLoader accepts an optional httpClient; tests inject a fake instead of jest.mock("axios"), which the project testing rules forbid. Neither test file patches the axios module any more.
  • Actionable error on 401/403. Download failures are raised as SpecFetchError with the URL and HTTP status, and profiles add prints Failed to fetch OpenAPI document <url>: HTTP 401. Check --api-basic-auth, --api-bearer-token, or --custom-headers of profile <name>.
  • Docs. README gets an "Authentication and custom headers" section; profiles add --help now describes --openapi-spec and the auth flags.

Verification

  • npm test: 146 passed (6 new); npm run build clean.
  • End-to-end against local servers: a protected spec loads and the API call carries the token; a wrong token prints the hint; a cross-origin $ref arrives without any profile header; a three-hop same-origin chain loads.

Known limitation, unchanged by this PR: on a cross-host redirect axios (follow-redirects) drops Authorization but keeps custom headers such as x-api-key.

🤖 Generated with Claude Code

itsyoboieltr and others added 4 commits September 4, 2026 12:58
…nested refs

Follow-up to the auth-headers change from PR #22:

- headers passed to OpenapiLoader.loadSpec() are sent only to the origins of
  --openapi-spec and --api-base-url; external $ref documents on any other
  host are fetched anonymously, so a spec cannot leak profile credentials
- the resolve context now carries the auth scope into nested $ref documents,
  so a root -> A -> B chain behind auth loads instead of failing on B
- OpenapiLoader accepts an injectable httpClient; tests use it instead of
  jest.mock("axios"), as the testing rules require
- download failures surface as SpecFetchError with the URL and HTTP status;
  cli.ts turns 401/403 into a hint naming the auth flags

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@EvilFreelancer
EvilFreelancer merged commit 670eb52 into main Sep 4, 2026
1 check passed
@itsyoboieltr

Copy link
Copy Markdown
Contributor

@EvilFreelancer can we release this please? Thanks!

@EvilFreelancer

Copy link
Copy Markdown
Owner Author

@itsyoboieltr hi! Try 0.1.21

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