feat(v2.6.0): authentic 4-courier cancellation, 3-column docs and AI connector fixes
This commit is contained in:
+48
-7
@@ -211,25 +211,52 @@ export function optionalAuthMiddleware(req: Request, _res: Response, next: NextF
|
||||
|
||||
/**
|
||||
* Strict /mcp Authentication & Per-Key Rate Limit Guard
|
||||
* F14: Allows unauthenticated read-only discovery on tools/list.
|
||||
* Allows unauthenticated discovery handshakes (initialize, notifications/initialized, tools/list, ping, list_couriers)
|
||||
* so AI agent connectors (Claude Desktop, Cursor, Glama, LibreChat, Smithery) can connect seamlessly.
|
||||
*/
|
||||
export function requireMcpAuth(req: Request, res: Response, next: NextFunction): void {
|
||||
// Allow unauthenticated MCP initialize handshake for AI agent connector negotiation
|
||||
const body = req.body || {};
|
||||
const isInit = body && typeof body === "object" && body.method === "initialize";
|
||||
if (isInit) {
|
||||
const method = body && typeof body === "object" ? body.method : undefined;
|
||||
const ctx = req.auraAuth || resolveAuthContext(req);
|
||||
req.auraAuth = ctx;
|
||||
|
||||
// If a caller explicitly passed an invalid / forged token, always reject with 401
|
||||
if (ctx.tenantId === "invalid") {
|
||||
res.status(401).json(
|
||||
wrapError(
|
||||
new McpToolError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "Invalid or forged Authorization token.",
|
||||
retryable: false,
|
||||
source: "validator",
|
||||
})
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow unauthenticated discovery handshakes (initialize, notifications/initialized, tools/list, ping)
|
||||
const isDiscovery =
|
||||
method === "initialize" ||
|
||||
method === "notifications/initialized" ||
|
||||
method === "tools/list" ||
|
||||
method === "ping";
|
||||
|
||||
if (isDiscovery) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const ctx = req.auraAuth || resolveAuthContext(req);
|
||||
req.auraAuth = ctx;
|
||||
// BYOK headers (x-steadfast-api-key, etc.) allow tool execution with caller's carrier credentials
|
||||
if (ctx.isByok) {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (!ctx.authenticated) {
|
||||
res.status(401).json(
|
||||
wrapError(
|
||||
new McpToolError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "Missing or invalid Authorization: Bearer <key> header on /mcp.",
|
||||
message: "Missing or invalid Authorization: Bearer <key> header on /mcp. Please provide your API key or BYOK carrier keys.",
|
||||
retryable: false,
|
||||
source: "validator",
|
||||
})
|
||||
@@ -274,11 +301,25 @@ export function isActionPermitted(
|
||||
): { permitted: boolean; reason?: string } {
|
||||
const ctx = req.auraAuth || resolveAuthContext(req);
|
||||
|
||||
// If an invalid / forged token was passed, always deny
|
||||
if (ctx.tenantId === "invalid") {
|
||||
recordAuditLog(ctx.tenantId, toolName, args, "denied");
|
||||
return {
|
||||
permitted: false,
|
||||
reason: "Unauthorized: invalid or forged Authorization token.",
|
||||
};
|
||||
}
|
||||
|
||||
// F14: list_couriers is allowed for discovery
|
||||
if (toolName === "list_couriers") {
|
||||
return { permitted: true };
|
||||
}
|
||||
|
||||
// BYOK mode: caller provided specific courier credentials in headers
|
||||
if (ctx.isByok) {
|
||||
return { permitted: true };
|
||||
}
|
||||
|
||||
if (!ctx.authenticated) {
|
||||
recordAuditLog(ctx.tenantId, toolName, args, "denied");
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user