GHSA-h754-fxp7-88wx swagger-typescript-api vulnerable to authorization-token exfiltration via spec `$ref`
SummaryWhen the developer supplies an `--authorizationToken` (commonly required to fetch a private spec behind authentication), `swagger-typescript-api` attaches that token to the `Authorization` header of **every** subsequent HTTP request it makes while resolving external `$ref` URLs in the spec — with **no same-origin check, no host allowlist, and no scope-down** for cross-origin requests. A malicious OpenAPI spec containing a `$ref` to an attacker-controlled URL therefore causes the developer's bearer token to be sent verbatim to that URL during code generation.The threat model is identical to the SSRF advisory filed alongside this one (companion finding), but with credential disclosure as the primary impact. The token is typically a high-value secret: a GitHub PAT, an OAuth bearer for the API the spec describes, an enterprise SSO token, an AWS-style API key, or similar. Disclosure to an attacker-controlled URL is one curl-equivalent away from full takeover of whatever scope the token grants.DetailsThe header-builder lives in `src/resolved-swagger-schema.ts:81-92`:There is no check that the request's destination URL shares an origin (or scheme, or host, or even top-level domain) with `this.config.url` — the URL the user originally specified. The headers object is unconditional.`getRemoteRequestHeaders` is called by `fetchRemoteSchemaDocument` (`src/resolved-swagger-schema.ts:374`):…which is in turn called by `warmUpRemoteSchemasCache` (`src/resolved-swagger-schema.ts:399-445`) for every external `$ref` URL discovered while walking the spec.Net effect: a spec whose response schema iscauses the generator to sendto `attacker.example`, regardless of where the original spec was hosted.The `--authorizationToken` flag is the standard mechanism for consuming a spec behind auth — for example, fetching a private GitHub-hosted spec with a Personal Access Token, fetching a vendor API spec behind an OAuth bearer, fetching a Confluence-hosted spec with a session token. Setting `--authorizationToken` is therefore not an exotic configuration; it is the *intended* configuration for any non-public spec.PoCSelf-contained reproducer in comments (install `swagger-typescript-api@13.12.1` into a local `node_modules`, spin up two loopback HTTP servers — one serving the spec, one pretending to be the attacker's exfil endpoint — run the generator with `authorizationToken` set, observe what the attacker endpoint received). Tested on `swagger-typescript-api@13.12.1` and Node `v24.11.1`.**Payload spec** (served from `http://127.0.0.1:<spec-port>/spec.json`):**Steps:****Observed:**The attacker-controlled endpoint received the developer's full `Bearer ...` token verbatim, sent by the generator while resolving the spec's `$ref`.Impact**Type:** Insufficiently Protected Credentials (CWE-522) / Exposure of Sensitive Information to an Unauthorized Actor (CWE-200) / Insertion of Sensitive Information into Sent Data (CWE-201) via missing same-origin check on credentialed HTTP requests.**Affected use cases:****A developer fetching a private OpenAPI spec behind authentication** (GitHub-hosted private spec, vendor-API spec on an OAuth-protected URL, Atlassian / Confluence / enterprise wiki-hosted spec) and the spec author is not the developer. This is the literal documented usage of `--authorizationToken`.**A CI/CD pipeline regenerating clients from a private spec on every build** — the CI's authentication token (often a long-lived service-account credential) leaks on every run.**A multi-tenant SaaS that generates per-tenant clients from tenant-supplied specs** — a tenant's malicious spec captures the SaaS provider's API key.**Any project where a contributor can modify the pinned spec via PR** — the project's CI credentials leak on first build of the malicious PR.**Lifecycle:** generation-time. The token leak happens when the developer or CI pipeline runs `swagger-typescript-api generate`, not when the generated client is later imported.**Privilege of stolen token:** typically the developer's API authentication for the target service — a GitHub PAT (full source-code read/write to whatever repos the PAT scope allows), an OAuth bearer (full impersonation on the API), an AWS-style key (full account access depending on IAM policy), or a CI service-account token (full CI/CD pipeline access). Token capture is functionally equivalent to credential theft — the attacker gains the same scope of access the developer had.**Suggested fix:**The minimum sufficient fix is a same-origin check on the `Authorization` header forwarding:Then update the call site `fetchRemoteSchemaDocument` (`src/resolved-swagger-schema.ts:374`) to pass the destination URL:This is the same model browsers apply to credentialed `fetch` requests by default. It does not break legitimate same-server `$ref`s — those still authenticate normally. It only strips the token when the target's origin differs from the spec source's origin.For deeper hardening, combine this with the SSRF mitigations recommended in the companion advisory (private-IP filter + custom undici dispatcher with redirect re-validation). The two fixes are complementary: the SSRF guard prevents the request from reaching the attacker at all; the same-origin guard prevents credential leakage even if the request does happen.Submitted by: Hamza Haroon (thegr1ffyn)
CVSS v3.1 score: 7.4