From 24f020e457750f6720f0ad13582198690e618df7 Mon Sep 17 00:00:00 2001 From: jade Date: Tue, 7 Jul 2026 13:04:31 +0900 Subject: [PATCH] fix: Block direct execution of unregistered tools in BusinessToolController --- .../controller/BusinessToolController.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/axhub-tool-core/src/main/java/io/shinhanlife/axhub/biz/mcp/tool/controller/BusinessToolController.java b/axhub-tool-core/src/main/java/io/shinhanlife/axhub/biz/mcp/tool/controller/BusinessToolController.java index 77a722f..c35cc84 100644 --- a/axhub-tool-core/src/main/java/io/shinhanlife/axhub/biz/mcp/tool/controller/BusinessToolController.java +++ b/axhub-tool-core/src/main/java/io/shinhanlife/axhub/biz/mcp/tool/controller/BusinessToolController.java @@ -22,6 +22,7 @@ import com.networknt.schema.ValidationMessage; import org.springframework.context.ApplicationContext; import io.shinhanlife.axhub.biz.mcp.tool.annotation.McpTool; import io.shinhanlife.axhub.biz.mcp.tool.annotation.McpFunction; +import io.shinhanlife.axhub.biz.mcp.tool.config.McpProperties; import java.lang.reflect.Method; import io.shinhanlife.axhub.biz.mcp.tool.util.JsonSchemaGenerator; @@ -35,6 +36,7 @@ public class BusinessToolController { private final ApplicationContext applicationContext; private final ObjectMapper objectMapper; + private final McpProperties mcpProperties; // JSON RPC 기반 단일 라우팅 엔드포인트 @PostMapping("/mcp/api/v1/tools/call") @@ -80,6 +82,22 @@ public class BusinessToolController { return error; } + // --- 비공개 툴(register=false)에 대한 강제 실행 접근 원천 차단 로직 --- + McpProperties.FunctionProp prop = null; + if (mcpProperties != null && mcpProperties.getFunctions() != null) { + prop = mcpProperties.getFunctions().get(targetFunctionAnnotation.name()); + } + boolean isRegister = prop != null && prop.getRegister() != null ? prop.getRegister() : targetFunctionAnnotation.register(); + + if (!isRegister) { + log.warn("[Tool] 비공개 툴에 대한 강제 접근 시도 차단: {}", functionName); + Map error = new HashMap<>(); + error.put("jsonrpc", "2.0"); + error.put("error", Map.of("code", -32001, "message", "접근이 차단된 비공개 툴입니다: " + functionName)); + error.put("id", payload != null ? payload.get("id") : null); + return error; + } + // 2. 파라미터 유효성 검증 (JSON Schema) if (targetMethod.getParameterCount() > 0) { Class paramType = targetMethod.getParameterTypes()[0];