@mcpfn/auth 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/index.cjs +78 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +78 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -43,6 +43,25 @@ Pass it to `streamableHttpTarget`. Complete interactive authorization with
|
|
|
43
43
|
fails before token exchange. Dynamic loopback ports are accepted only when the
|
|
44
44
|
registered URI omits the port. Other redirect URIs require exact equality.
|
|
45
45
|
|
|
46
|
+
Native private-use redirects use RFC 8252's reverse-domain scheme policy by
|
|
47
|
+
default, accepting values such as `com.example.app:/oauth/callback`. Hosts can
|
|
48
|
+
set `redirectPolicy.privateUseSchemePolicy: "disabled"` to reject all native
|
|
49
|
+
schemes, or opt into `"compatible"` for well-formed non-web schemes used by
|
|
50
|
+
native clients and name those schemes explicitly, for example
|
|
51
|
+
`compatiblePrivateUseSchemes: ["cursor"]` for
|
|
52
|
+
`cursor://anysphere.cursor-mcp/oauth/callback`. Compatibility mode still rejects
|
|
53
|
+
web, network, launcher, and dangerous schemes, non-loopback HTTP, credentials,
|
|
54
|
+
fragments, wildcards, and malformed or opaque callbacks. Authorization always
|
|
55
|
+
requires exact matching; dynamic-port matching remains restricted to loopback
|
|
56
|
+
HTTP. Successful dynamic
|
|
57
|
+
registrations expose compatibility scheme names and counts through the hosted
|
|
58
|
+
authorization diagnostics hook so hosts can audit use without recording callback
|
|
59
|
+
queries.
|
|
60
|
+
|
|
61
|
+
The deprecated `allowPrivateUseSchemes` boolean remains accepted for 0.0.3
|
|
62
|
+
callers: `false` maps to `disabled` and `true` maps to `rfc8252`. When neither
|
|
63
|
+
field is provided, 0.0.4 defaults to `rfc8252`.
|
|
64
|
+
|
|
46
65
|
## Hosted compatibility
|
|
47
66
|
|
|
48
67
|
`createMcpAuthorizationCompatibilityHandler()` publishes authorization-server
|
package/dist/index.cjs
CHANGED
|
@@ -171,7 +171,7 @@ function normalizeMcpRedirectUri(value, policy = {}) {
|
|
|
171
171
|
}
|
|
172
172
|
if (url.protocol === "https:") return url.toString();
|
|
173
173
|
if (url.protocol === "http:" && isLoopback(url, policy)) return url.toString();
|
|
174
|
-
if (
|
|
174
|
+
if (isAllowedPrivateUseRedirect(url, policy)) {
|
|
175
175
|
return url.toString();
|
|
176
176
|
}
|
|
177
177
|
throw new McpFnRedirectMismatchError(url.toString());
|
|
@@ -197,6 +197,68 @@ function matchMcpRedirectUri(requested, registeredRedirectUris, policy = {}) {
|
|
|
197
197
|
}
|
|
198
198
|
throw new McpFnRedirectMismatchError(actual.toString());
|
|
199
199
|
}
|
|
200
|
+
function isMcpFnCompatiblePrivateUseRedirect(value) {
|
|
201
|
+
let url;
|
|
202
|
+
try {
|
|
203
|
+
url = new URL(value.toString());
|
|
204
|
+
} catch {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
return isSafePrivateUseRedirect(url) && !isReverseDomainPrivateUseScheme(url.protocol);
|
|
208
|
+
}
|
|
209
|
+
var unsafeNativeProtocols = /* @__PURE__ */ new Set([
|
|
210
|
+
"about:",
|
|
211
|
+
"android-app:",
|
|
212
|
+
"blob:",
|
|
213
|
+
"chrome:",
|
|
214
|
+
"chrome-extension:",
|
|
215
|
+
"data:",
|
|
216
|
+
"facetime:",
|
|
217
|
+
"file:",
|
|
218
|
+
"filesystem:",
|
|
219
|
+
"ftp:",
|
|
220
|
+
"ftps:",
|
|
221
|
+
"geo:",
|
|
222
|
+
"gopher:",
|
|
223
|
+
"intent:",
|
|
224
|
+
"javascript:",
|
|
225
|
+
"ldap:",
|
|
226
|
+
"ldaps:",
|
|
227
|
+
"mailto:",
|
|
228
|
+
"market:",
|
|
229
|
+
"ms-settings:",
|
|
230
|
+
"ms-windows-store:",
|
|
231
|
+
"nntp:",
|
|
232
|
+
"resource:",
|
|
233
|
+
"sftp:",
|
|
234
|
+
"shell:",
|
|
235
|
+
"smb:",
|
|
236
|
+
"sms:",
|
|
237
|
+
"ssh:",
|
|
238
|
+
"tel:",
|
|
239
|
+
"urn:",
|
|
240
|
+
"vbscript:",
|
|
241
|
+
"view-source:",
|
|
242
|
+
"ws:",
|
|
243
|
+
"wss:"
|
|
244
|
+
]);
|
|
245
|
+
function isAllowedPrivateUseRedirect(url, policy) {
|
|
246
|
+
const effectivePolicy = policy.privateUseSchemePolicy ?? (policy.allowPrivateUseSchemes === false ? "disabled" : "rfc8252");
|
|
247
|
+
if (effectivePolicy === "disabled") return false;
|
|
248
|
+
if (!isSafePrivateUseRedirect(url)) return false;
|
|
249
|
+
if (isReverseDomainPrivateUseScheme(url.protocol)) return true;
|
|
250
|
+
if (effectivePolicy !== "compatible") return false;
|
|
251
|
+
const scheme = url.protocol.slice(0, -1).toLowerCase();
|
|
252
|
+
return policy.compatiblePrivateUseSchemes?.some(
|
|
253
|
+
(candidate) => candidate === candidate.toLowerCase() && candidate === scheme
|
|
254
|
+
) === true;
|
|
255
|
+
}
|
|
256
|
+
function isSafePrivateUseRedirect(url) {
|
|
257
|
+
if (url.username || url.password || url.hash || url.hostname.includes("*") || url.protocol === "http:" || url.protocol === "https:" || unsafeNativeProtocols.has(url.protocol) || !url.hostname && !url.pathname.startsWith("/")) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
200
262
|
function isReverseDomainPrivateUseScheme(protocol) {
|
|
201
263
|
const scheme = protocol.slice(0, -1).toLowerCase();
|
|
202
264
|
return /^[a-z](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/.test(
|
|
@@ -579,9 +641,22 @@ async function handleRegistrationRequest(options, request) {
|
|
|
579
641
|
redirectPolicy: options.redirectPolicy
|
|
580
642
|
});
|
|
581
643
|
assertCompatibleClientRegistration(registration, supportedMethods, options.supportedScopes);
|
|
644
|
+
const compatibilityRedirects = registration.redirectUris.filter(
|
|
645
|
+
isMcpFnCompatiblePrivateUseRedirect
|
|
646
|
+
);
|
|
647
|
+
const compatibilityRedirectSchemes = unique(
|
|
648
|
+
compatibilityRedirects.map(
|
|
649
|
+
(redirect) => new URL(redirect).protocol.slice(0, -1)
|
|
650
|
+
)
|
|
651
|
+
);
|
|
582
652
|
await emit(options, "client-registration", "succeeded", void 0, {
|
|
583
653
|
clientId: registration.clientId,
|
|
584
|
-
source: registration.source
|
|
654
|
+
source: registration.source,
|
|
655
|
+
...compatibilityRedirectSchemes.length > 0 ? {
|
|
656
|
+
privateUseSchemePolicy: "compatible",
|
|
657
|
+
compatibilityRedirectSchemes,
|
|
658
|
+
compatibilityRedirectCount: compatibilityRedirects.length
|
|
659
|
+
} : {}
|
|
585
660
|
});
|
|
586
661
|
return json2(201, {
|
|
587
662
|
...registration.metadata,
|
|
@@ -1928,6 +2003,7 @@ exports.createOAuthResourceServerHandler = createOAuthResourceServerHandler;
|
|
|
1928
2003
|
exports.createProtectedResourceMetadata = createProtectedResourceMetadata;
|
|
1929
2004
|
exports.diagnoseMcpAuthorization = diagnoseMcpAuthorization;
|
|
1930
2005
|
exports.enterpriseManagedAuthorizationClientMetadata = enterpriseManagedAuthorizationClientMetadata;
|
|
2006
|
+
exports.isMcpFnCompatiblePrivateUseRedirect = isMcpFnCompatiblePrivateUseRedirect;
|
|
1931
2007
|
exports.matchMcpRedirectUri = matchMcpRedirectUri;
|
|
1932
2008
|
exports.normalizeMcpClientRegistration = normalizeMcpClientRegistration;
|
|
1933
2009
|
exports.normalizeMcpRedirectUri = normalizeMcpRedirectUri;
|