From 0aeef1e4287a86fb69144c13c98dc8ea027dbc12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= <188421097+YuJunZhiXue@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:44:58 +0800 Subject: [PATCH] fix: seal object JSON schemas so redteam preset loads on DSH 0.2.1. --- lib/redteam/tools.js | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/redteam/tools.js b/lib/redteam/tools.js index fa1233d..8a5c44d 100644 --- a/lib/redteam/tools.js +++ b/lib/redteam/tools.js @@ -99,7 +99,36 @@ function loadDefineTool() { throw new Error('dsh-purge/redteam/tools: cannot resolve @deepseek-ai/dsh-tools from host') } -const defineTool = loadDefineTool() +const defineToolRaw = loadDefineTool() + +/** 0.2.1:任何 type=object 都必须显式 additionalProperties,否则整份红队预设加载失败。 */ +function sealObjectSchemas(node) { + if (!node || typeof node !== 'object') return node + if (Array.isArray(node)) { + for (const item of node) sealObjectSchemas(item) + return node + } + if (node.type === 'object' && node.additionalProperties === undefined) { + node.additionalProperties = node.properties ? false : true + } + if (node.properties) { + for (const key of Object.keys(node.properties)) sealObjectSchemas(node.properties[key]) + } + if (node.items) sealObjectSchemas(node.items) + if (node.additionalProperties && typeof node.additionalProperties === 'object') { + sealObjectSchemas(node.additionalProperties) + } + return node +} + +function defineTool(spec) { + if (spec && spec.parameters) sealObjectSchemas(spec.parameters) + const tool = defineToolRaw(spec) + if (tool && tool.parameters) sealObjectSchemas(tool.parameters) + if (tool && tool.inputSchema) sealObjectSchemas(tool.inputSchema) + if (tool && tool.schema) sealObjectSchemas(tool.schema) + return tool +} /** Cordis 插件名。 */ export const name = 'dsh-purge-redteam-tools' @@ -2057,8 +2086,8 @@ export function apply(ctx) { parameters: { engagement: { type: 'string' }, operation: { type: 'string', required: true, description: '操作名,如 "nmap_scan"、"webshell_established"、"sql_injection_confirmed"' }, - parameters: { type: 'object', description: '调用参数(JSON 对象,会参与哈希)' }, - result: { type: 'object', required: true, description: '规范化结果(JSON 对象,会参与哈希)' }, + parameters: { type: 'object', additionalProperties: true, description: '调用参数(JSON 对象,会参与哈希)' }, + result: { type: 'object', additionalProperties: true, required: true, description: '规范化结果(JSON 对象,会参与哈希)' }, confidence: { type: 'string', description: 'claimed | observed | derived | inferred,默认 observed' }, authority: { type: 'string', description: 'tool-output | database-record | screenshot | request-replay | subagent-report | operator-input,默认 tool-output' }, limitations: { type: 'array', items: { type: 'string' }, description: '局限性说明,如 ["只扫了 Top1000 端口"]' }, @@ -2090,8 +2119,8 @@ export function apply(ctx) { parameters: { engagement: { type: 'string' }, operation: { type: 'string', required: true }, - parameters: { type: 'object' }, - result: { type: 'object', required: true }, + parameters: { type: 'object', additionalProperties: true }, + result: { type: 'object', additionalProperties: true, required: true }, confidence: { type: 'string' }, authority: { type: 'string' }, limitations: { type: 'array', items: { type: 'string' } }, @@ -2119,7 +2148,7 @@ export function apply(ctx) { parameters: { engagement: { type: 'string' }, claimed_ev_id: { type: 'string', required: true, description: '要升级的证据 ID' }, - verified_result: { type: 'object', description: '亲自验证后的实际结果' }, + verified_result: { type: 'object', additionalProperties: true, description: '亲自验证后的实际结果' }, verified_by: { type: 'string', description: '谁核实的,默认 coordinator' }, }, output: { schema: { type: 'string' }, render: (_args, value) => text(value) },