fix(security): guard cowork-mcp-tools probe against SSRF (#3783)

This commit is contained in:
soroush5
2026-09-05 21:10:15 +07:00
committed by decolua
parent 0da803eef4
commit 97f3ab97b1
2 changed files with 71 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
"use server";
import { NextResponse } from "next/server";
import { assertPublicUrl } from "@/shared/utils/ssrfGuard.js";
import { isLocalRequest } from "@/dashboardGuard";
const TIMEOUT_MS = 8000;
@@ -87,6 +89,14 @@ export async function POST(request) {
if (!url || typeof url !== "string") {
return NextResponse.json({ error: "url required" }, { status: 400 });
}
// SSRF guard for remote callers; local host keeps self-hosted MCP servers.
if (!isLocalRequest(request)) {
try {
assertPublicUrl(url);
} catch {
return NextResponse.json({ error: "URL not allowed" }, { status: 400 });
}
}
const result = await probeMcp(url);
return NextResponse.json(result);
} catch (e) {