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'; ...@@ -4,6 +4,7 @@ import { type StoreSecretValueType } from '@fastgpt/global/common/secret/type';
import type { RunHTTPToolResult } from '@fastgpt/service/core/app/http'; import type { RunHTTPToolResult } from '@fastgpt/service/core/app/http';
import { runHTTPTool } 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 type { HttpToolConfigType } from '@fastgpt/global/core/app/tool/httpTool/type';
import { authCert } from '@fastgpt/service/support/permission/auth/common';
export type RunHTTPToolQuery = {}; export type RunHTTPToolQuery = {};
...@@ -25,6 +26,8 @@ async function handler( ...@@ -25,6 +26,8 @@ async function handler(
req: ApiRequestProps<RunHTTPToolBody, RunHTTPToolQuery>, req: ApiRequestProps<RunHTTPToolBody, RunHTTPToolQuery>,
res: ApiResponseType<RunHTTPToolResponse> res: ApiResponseType<RunHTTPToolResponse>
): Promise<RunHTTPToolResponse> { ): Promise<RunHTTPToolResponse> {
await authCert({ req, authToken: true });
const { const {
params, params,
baseUrl, baseUrl,
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
type GetMcpToolsBodyType, type GetMcpToolsBodyType,
type GetMcpToolsResponseType type GetMcpToolsResponseType
} from '@fastgpt/global/openapi/core/app/mcpTools/api'; } from '@fastgpt/global/openapi/core/app/mcpTools/api';
import { isInternalAddress, PRIVATE_URL_TEXT } from '@fastgpt/service/common/system/utils';
async function handler( async function handler(
req: ApiRequestProps<GetMcpToolsBodyType>, req: ApiRequestProps<GetMcpToolsBodyType>,
...@@ -15,6 +16,10 @@ async function handler( ...@@ -15,6 +16,10 @@ async function handler(
): Promise<GetMcpToolsResponseType> { ): Promise<GetMcpToolsResponseType> {
const { url, headerSecret } = GetMcpToolsBodySchema.parse(req.body); const { url, headerSecret } = GetMcpToolsBodySchema.parse(req.body);
if (await isInternalAddress(url)) {
return Promise.reject(PRIVATE_URL_TEXT);
}
const mcpClient = new MCPClient({ const mcpClient = new MCPClient({
url, url,
headers: getSecretValue({ headers: getSecretValue({
......
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
type RunMcpToolBodyType, type RunMcpToolBodyType,
type RunMcpToolResponseType type RunMcpToolResponseType
} from '@fastgpt/global/openapi/core/app/mcpTools/api'; } from '@fastgpt/global/openapi/core/app/mcpTools/api';
import { isInternalAddress, PRIVATE_URL_TEXT } from '@fastgpt/service/common/system/utils';
async function handler( async function handler(
req: ApiRequestProps<RunMcpToolBodyType>, req: ApiRequestProps<RunMcpToolBodyType>,
...@@ -14,6 +15,10 @@ async function handler( ...@@ -14,6 +15,10 @@ async function handler(
): Promise<RunMcpToolResponseType> { ): Promise<RunMcpToolResponseType> {
const { url, toolName, headerSecret, params } = RunMcpToolBodySchema.parse(req.body); const { url, toolName, headerSecret, params } = RunMcpToolBodySchema.parse(req.body);
if (await isInternalAddress(url)) {
return Promise.reject(PRIVATE_URL_TEXT);
}
const mcpClient = new MCPClient({ const mcpClient = new MCPClient({
url, url,
headers: getSecretValue({ 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