Fix security scan findings: confirm gate, exit codes, redaction, CI tag env (#180)
- Gate rules push behind --yes at CLI and domain layers (fail-closed on
dryRun=false without confirm)
- Raise webhook replay partial failure as CliError so exit 1 survives
cli.ts exitCode overwrite; route webhook stdout through printJson for
exit-12 protection and --output-file support
- Narrow MCP read-only allowlist: drop config mode/lint (write forms are
indistinguishable under token-prefix matching; config get covers reads)
- Extract redactSensitiveText to core, extend credential patterns, apply
to HTTP sendError/500 and domain error messages
- Pass release TAG_NAME via env instead of inline ${{ }} interpolation
to close script injection through crafted tag names
- Track .zcodeignore so enterprise credential exclusions travel with the
repo
- Add .agents/rules/security-posture.md documenting usability-first
accepted risks (loopback adapter auth, update verification, mutation
command gates, skill dump stdout); register skill dump as a documented
stdout Markdown exception in AGENTS.md and cli-protocol.md
- Rebuild dist/mcp/server.js
This commit is contained in:
1 parent
3d9df01c31
commit
f8e083f3b2
15 files changed
+283
-151
No files matched your search
@@ -207,6 +207,13 @@ export async function handleRulesCommand(
|
||||
const publish = booleanOption(args.options.publish);
|
||||
const versionName = stringOption(args.options.versionName) ?? stringOption(args.options["version-name"]);
|
||||
|
||||
if (!confirmed && !dryRun) {
|
||||
throw confirmationRequired(
|
||||
"Refusing to push rules without --yes. Use --dry-run to preview.",
|
||||
`seal-use rules push --file ${file ?? "./rules.local.json"} --corp ${corp.id} --dry-run`
|
||||
);
|
||||
}
|
||||
|
||||
const result = await runToolResult(
|
||||
"seal_approval_rules_push",
|
||||
client!,
|
||||
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
webhookRateOption,
|
||||
webhookShowSecretOption
|
||||
} from "../parser.js";
|
||||
import { outputOptions } from "../printer.js";
|
||||
import { outputOptions, printJson } from "../printer.js";
|
||||
import type { ParsedArgs } from "../types.js";
|
||||
import type { MaterialPackFilePolicyPatch } from "../../domains/seal/material-pack/policy.js";
|
||||
import { CliError, confirmationRequired, usageError } from "../errors.js";
|
||||
@@ -39,7 +39,7 @@ export async function handleWebhookResourcePackPreview(
|
||||
) {
|
||||
if (!existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
|
||||
const input = readMaterialPackFile(filePath);
|
||||
console.log(JSON.stringify(await previewMaterialPack(input.fileBuffer, input.fileName, filePolicy), null, 2));
|
||||
printJson(await previewMaterialPack(input.fileBuffer, input.fileName, filePolicy));
|
||||
}
|
||||
|
||||
export const handleWebhookMaterialPackPreview = handleWebhookResourcePackPreview;
|
||||
@@ -83,7 +83,7 @@ export async function handleWebhookCommand(
|
||||
console.error(`🔴 准备阶段未通过: ${result.statusMessage}`);
|
||||
console.error(`👉 Next action: ${result.nextAction}`);
|
||||
}
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
printJson(result, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ export async function handleWebhookCommand(
|
||||
console.error(
|
||||
`[webhook-replay] 预览模式:已成功从 ${sourceCorp.name} 提取单据并转换为 Webhook Payload(未实际推送)。`
|
||||
);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
printJson(result, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -197,9 +197,15 @@ export async function handleWebhookCommand(
|
||||
);
|
||||
}
|
||||
console.error(`👉 Next action: seal-use approval-runs list --corp ${targetCorp.id} --limit ${result.totalCount}`);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
printJson(result, outputOptions(args.options));
|
||||
if (!result.success) {
|
||||
process.exitCode = 1;
|
||||
// The partial-failure signal must survive cli.ts overwriting process.exitCode with the
|
||||
// dispatch result, so it is raised as a CliError instead of set on the process.
|
||||
throw new CliError(
|
||||
`Webhook replay finished with failures (success ${result.successCount}, failed ${result.failureCount}).`,
|
||||
1,
|
||||
`seal-use approval-runs list --corp ${targetCorp.id} --limit ${result.totalCount}`
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -263,7 +269,7 @@ export async function handleWebhookCommand(
|
||||
`🟢 成功导出 Webhook 资源包: ${result.filePath} (共 ${result.recordCount} 条单据,${result.attachmentCount} 个附件,${(result.fileSizeBytes / 1024).toFixed(1)} KB)`
|
||||
);
|
||||
console.error(`👉 Next action: ${result.nextAction}`);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
printJson(result, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -275,7 +281,7 @@ export async function handleWebhookCommand(
|
||||
if (!existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
|
||||
const input = readMaterialPackFile(filePath);
|
||||
if (operation === "preview") {
|
||||
console.log(JSON.stringify(await previewMaterialPack(input.fileBuffer, input.fileName), null, 2));
|
||||
printJson(await previewMaterialPack(input.fileBuffer, input.fileName), outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
if (operation !== "push") throw new Error("Usage: seal-use webhook resource-pack <export|preview|push> [options]");
|
||||
@@ -305,7 +311,7 @@ export async function handleWebhookCommand(
|
||||
});
|
||||
console.error(`🟢 Webhook 资源包推送完成 (成功 ${result.results.length} 条单据)`);
|
||||
console.error(`👉 Next action: seal-use approval-runs list --corp ${corp.id} --limit ${result.results.length}`);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
printJson(result, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
if (action === "list") {
|
||||
|
||||
+3
-6
@@ -1,8 +1,11 @@
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { booleanOption, stringOption } from "./parser.js";
|
||||
import { PayloadTooLargeError } from "./errors.js";
|
||||
import { redactSensitiveText } from "../core/redact.js";
|
||||
import type { OutputOptions } from "./types.js";
|
||||
|
||||
export { redactSensitiveText };
|
||||
|
||||
const RULE_LIST_FULL_COUNT_LIMIT = 100;
|
||||
const RULE_LIST_FULL_BYTES_LIMIT = 120_000;
|
||||
export const RULE_SUMMARY_FIELDS = ["code", "status", "strictness", "scope", "updatedAt"];
|
||||
@@ -17,12 +20,6 @@ export function joinOutput(lines: string[]): string {
|
||||
return `${lines.join("\n")}\n`;
|
||||
}
|
||||
|
||||
export function redactSensitiveText(value: string): string {
|
||||
return value
|
||||
.replace(/([?&](?:accessToken|token|returnToken)=)[^&\s]+/gi, "$1<redacted>")
|
||||
.replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1<redacted>");
|
||||
}
|
||||
|
||||
export function printJson(value: unknown, options: OutputOptions = {}) {
|
||||
protectLargeOutput(value, options);
|
||||
const json = `${JSON.stringify(value, null, 2)}\n`;
|
||||
|
||||
@@ -23,7 +23,8 @@ const AREA_ALIASES: Record<string, string> = {
|
||||
/**
|
||||
* Commands that only read tenant state, produce a local file, or inspect local configuration.
|
||||
* Deliberately excluded even though they look harmless: anything that writes local config
|
||||
* (`corps switch`, `config test-dir`), mints or prints credentials (`auth keys`, `corps keys`),
|
||||
* (`corps switch`, `config test-dir`, `config mode <value>`, `config lint <subaction>`), mints
|
||||
* or prints credentials (`auth keys`, `corps keys`),
|
||||
* self-updates (`update`), or stands up a long-running server (`http`, `mcp`, `service run`).
|
||||
*/
|
||||
const READ_ONLY_COMMANDS: Record<string, string[]> = {
|
||||
@@ -62,7 +63,10 @@ const READ_ONLY_COMMANDS: Record<string, string[]> = {
|
||||
],
|
||||
deploy: ["hosecloud requirements", "hosecloud list", "hosecloud get", "hosecloud status"],
|
||||
preference: ["get", "thinking-depth policies list"],
|
||||
config: ["paths", "get", "mode", "lint"],
|
||||
// `config mode`/`config lint` are omitted: classification is token-prefix based, so their
|
||||
// read forms cannot be separated from the value-taking write forms. `config get` returns
|
||||
// the same summary (mode + lint included), so read access loses nothing.
|
||||
config: ["paths", "get"],
|
||||
auth: ["check", "diagnose", "status", "test", "doctor", "link list"],
|
||||
users: ["search", "get", "delegation"],
|
||||
contacts: ["departments", "children", "users", "sync-time"],
|
||||
|
||||
Reference in new issue
Block a user