Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ secret. It does not store, resolve or authorize credentials; the host and
header, host-supplied extra origins, and no header for an empty or keyless
secret.
- Extra origins are host-supplied and keyed by the pinned origin. No vendor
origin lives in source.
origin lives in source. A secret is sent only to `https`, or to `http` on
loopback (`localhost`, `127.0.0.1`, `::1`). Other schemes are refused before
the credential is attached.
- `FetchLike` comes from `@intx/harness`; do not redeclare it.

## Local development
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ For plain Bearer APIs, use the built-in `http` provider from `@intx/harness`.
## Install

```bash
bun add @corbits/credential-http @intx/harness@^0.4.0 @intx/types@^0.4.0
bun add @corbits/credential-http @intx/harness@^0.5.0 @intx/types@^0.5.0
```

Runs on Bun >= 1.2 or Node >= 24.
Runs on Bun >= 1.2 or Node >= 24. `@intx/harness` and `@intx/types` `^0.4.0` are also accepted peer ranges.

## Quickstart

Expand Down Expand Up @@ -90,7 +90,7 @@ The keys are also exported as `X_API_KEY_PROVIDER_KEY`, `RAW_AUTHORIZATION_PROVI
| `extraOrigins` | `Record<string, readonly string[]>` | `{}` |
| `fetch` | `FetchLike` from `@intx/harness` | global `fetch` |

`extraOrigins` is keyed by the pinned origin, so one credential's allowance never applies to another. `{ "https://mcp.example.com": ["https://auth.example.com"] }` lets only a credential pinned to `https://mcp.example.com` also call `https://auth.example.com`.
`extraOrigins` is keyed by the pinned origin, so one credential's allowance never applies to another. `{ "https://mcp.example.com": ["https://auth.example.com"] }` lets only a credential pinned to `https://mcp.example.com` also call `https://auth.example.com`. Every origin a secret can be sent to, including these, must be `https`. `http` is accepted only for loopback (`localhost`, `127.0.0.1`, and `::1`). Anything else is refused before the secret is attached. A redirect is still never followed.

### `createHeaderCredentialProvider(opts)`

Expand All @@ -106,7 +106,7 @@ createHeaderCredentialProvider({

### `createOriginPinnedFetch(opts)`

The pinned `fetch` every handle uses, for code that holds a secret outside the provider registry, such as a hub route. `opts` is `{ origin, header, readValue, extraOrigins?, fetch? }`. `readValue` runs per request; `undefined` or `""` sends no header.
The pinned `fetch` every handle uses, for code that holds a secret outside the provider registry, such as a hub route. `opts` is `{ origin, header, readValue, extraOrigins?, fetch? }`. `readValue` runs per request; `undefined` or `""` sends no header. `Request` and `RequestInit` follow fetch's override rules, except the credential header and `redirect: "manual"` always win. Passing a `Request` does not drop `init` (including its abort signal). The URL is copied to a string and authorized before headers are read or the credential is attached, and the delegate is called with that string rather than the original `URL` or `Request`. `blob:` and every protocol other than `https` (or `http` on loopback) is refused before the secret is read.

### `MCP_NO_TOKEN_SENTINEL`

Expand Down
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"typescript": "6.0.3"
},
"peerDependencies": {
"@intx/harness": "^0.5.0",
"@intx/types": "^0.5.0"
"@intx/harness": "^0.4.0 || ^0.5.0",
"@intx/types": "^0.4.0 || ^0.5.0"
},
"engines": {
"bun": ">=1.2.0",
Expand Down
5 changes: 3 additions & 2 deletions src/credential-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
import {
assertHeaderName,
createOriginPinnedFetch,
credentialTransportOrigin,
} from "./origin-pinned-fetch.js";

/** Plugin key of the `x-api-key` preset. */
Expand Down Expand Up @@ -113,8 +114,8 @@ function createPinnedProvider(
const fetchImpl: FetchLike = opts.fetch ?? globalThis.fetch;
const extraOrigins = new Map(
Object.entries(opts.extraOrigins ?? {}).map(([origin, extras]) => [
new URL(origin).origin,
extras,
credentialTransportOrigin(origin),
extras.map((extra) => credentialTransportOrigin(extra)),
]),
);

Expand Down
Loading
Loading