Commit bc7eae2e by Archer Committed by GitHub

mcp ssrf check (#6640)

parent b15d7d78
......@@ -4,6 +4,7 @@ import { type StoreSecretValueType } from '@fastgpt/global/common/secret/type';
import type { RunHTTPToolResult } from '@fastgpt/service/core/app/http';
import { runHTTPTool } from '@fastgpt/service/core/app/http';
import type { HttpToolConfigType } from '@fastgpt/global/core/app/tool/httpTool/type';
import { authCert } from '@fastgpt/service/support/permission/auth/common';
export type RunHTTPToolQuery = {};
......@@ -25,6 +26,8 @@ async function handler(
req: ApiRequestProps<RunHTTPToolBody, RunHTTPToolQuery>,
res: ApiResponseType<RunHTTPToolResponse>
): Promise<RunHTTPToolResponse> {
await authCert({ req, authToken: true });
const {
params,
baseUrl,
......
......@@ -8,6 +8,7 @@ import {
type GetMcpToolsBodyType,
type GetMcpToolsResponseType
} from '@fastgpt/global/openapi/core/app/mcpTools/api';
import { isInternalAddress, PRIVATE_URL_TEXT } from '@fastgpt/service/common/system/utils';
async function handler(
req: ApiRequestProps<GetMcpToolsBodyType>,
......@@ -15,6 +16,10 @@ async function handler(
): Promise<GetMcpToolsResponseType> {
const { url, headerSecret } = GetMcpToolsBodySchema.parse(req.body);
if (await isInternalAddress(url)) {
return Promise.reject(PRIVATE_URL_TEXT);
}
const mcpClient = new MCPClient({
url,
headers: getSecretValue({
......
......@@ -7,6 +7,7 @@ import {
type RunMcpToolBodyType,
type RunMcpToolResponseType
} from '@fastgpt/global/openapi/core/app/mcpTools/api';
import { isInternalAddress, PRIVATE_URL_TEXT } from '@fastgpt/service/common/system/utils';
async function handler(
req: ApiRequestProps<RunMcpToolBodyType>,
......@@ -14,6 +15,10 @@ async function handler(
): Promise<RunMcpToolResponseType> {
const { url, toolName, headerSecret, params } = RunMcpToolBodySchema.parse(req.body);
if (await isInternalAddress(url)) {
return Promise.reject(PRIVATE_URL_TEXT);
}
const mcpClient = new MCPClient({
url,
headers: getSecretValue({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment