


























@@ -1,9 +1,13 @@
11import type { Command } from "commander";
22import { getRuntimeConfig } from "../config/config.js";
3+import type { GatewayAuthMode } from "../config/types.gateway.js";
34import { defaultRuntime } from "../runtime.js";
45import { runSecurityAudit } from "../security/audit.js";
56import { fixSecurityFootguns } from "../security/fix.js";
6-import { normalizeOptionalString } from "../shared/string-coerce.js";
7+import {
8+normalizeOptionalLowercaseString,
9+normalizeOptionalString,
10+} from "../shared/string-coerce.js";
711import { formatDocsLink } from "../terminal/links.js";
812import { isRich, theme } from "../terminal/theme.js";
913import { shortenHomeInString, shortenHomePath } from "../utils.js";
@@ -16,10 +20,45 @@ type SecurityAuditOptions = {
1620json?: boolean;
1721deep?: boolean;
1822fix?: boolean;
23+auth?: string;
1924token?: string;
2025password?: string;
2126};
222728+function parseGatewayAuthMode(value: string | undefined): GatewayAuthMode | undefined {
29+const mode = normalizeOptionalLowercaseString(value);
30+if (!mode) {
31+return undefined;
32+}
33+if (mode === "none" || mode === "token" || mode === "password" || mode === "trusted-proxy") {
34+return mode;
35+}
36+throw new Error(
37+'Invalid --auth value. Expected "none", "token", "password", or "trusted-proxy".',
38+);
39+}
40+41+function buildAuditGatewayAuthOverride(params: {
42+mode?: GatewayAuthMode;
43+token?: string;
44+password?: string;
45+}) {
46+if (!params.mode) {
47+return undefined;
48+}
49+if (params.mode === "token" && !params.token) {
50+throw new Error("Invalid --auth token: pass --token <token> for audit auth override.");
51+}
52+if (params.mode === "password" && !params.password) {
53+throw new Error("Invalid --auth password: pass --password <password> for audit auth override.");
54+}
55+return {
56+mode: params.mode,
57+ ...(params.token ? { token: params.token } : {}),
58+ ...(params.password ? { password: params.password } : {}),
59+};
60+}
61+2362function formatSummary(summary: { critical: number; warn: number; info: number }): string {
2463const rich = isRich();
2564const c = summary.critical;
@@ -50,6 +89,10 @@ export function registerSecurityCli(program: Command) {
5089 "openclaw security audit --deep --password <password>",
5190 "Use explicit password for deep probe.",
5291 ],
92+ [
93+ "openclaw security audit --auth password --password <password>",
94+ "Audit a runtime-only password-mode Gateway secret.",
95+ ],
5396 ["openclaw security audit --fix", "Apply safe remediations and file-permission fixes."],
5497 ["openclaw security audit --json", "Output machine-readable JSON."],
5598 ])}\n\n${theme.muted("Docs:")} ${formatDocsLink("/cli/security", "docs.openclaw.ai/cli/security")}\n`,
@@ -59,13 +102,23 @@ export function registerSecurityCli(program: Command) {
59102.command("audit")
60103.description("Audit config + local state for common security foot-guns")
61104.option("--deep", "Attempt live Gateway probes and plugin-owned collector checks", false)
105+.option(
106+"--auth <mode>",
107+'Runtime gateway auth mode ("none"|"token"|"password"|"trusted-proxy")',
108+)
62109.option("--token <token>", "Use explicit gateway token for deep probe auth")
63110.option("--password <password>", "Use explicit gateway password for deep probe auth")
64111.option("--fix", "Apply safe fixes (tighten defaults + chmod state/config)", false)
65112.option("--json", "Print JSON", false)
66113.action(async (opts: SecurityAuditOptions) => {
114+const authMode = parseGatewayAuthMode(opts.auth);
67115const token = normalizeOptionalString(opts.token);
68116const password = normalizeOptionalString(opts.password);
117+const auditGatewayAuthOverride = buildAuditGatewayAuthOverride({
118+mode: authMode,
119+ token,
120+ password,
121+});
69122const fixResult = opts.fix ? await fixSecurityFootguns().catch((_err) => null) : null;
7012371124const sourceConfig = getRuntimeConfig();
@@ -84,8 +137,12 @@ export function registerSecurityCli(program: Command) {
84137includeChannelSecurity: true,
85138deepProbeAuth:
86139token || password
87- ? { ...(token ? { token } : {}), ...(password ? { password } : {}) }
140+ ? {
141+ ...(token ? { token } : {}),
142+ ...(password ? { password } : {}),
143+}
88144 : undefined,
145+ auditGatewayAuthOverride,
89146});
9014791148if (opts.json) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。