Repository navigation
CLI: expand config set with SecretRef/provider builders and dry-run - #49296
Conversation
🔒 Aisle Security AnalysisWe found 2 potential security issue(s) in this PR:
1. 🔵
|
| Property | Value |
|---|---|
| Severity | Low |
| CWE | CWE-78 |
| Location | src/cli/config-cli.ts:795-812 |
Description
The new openclaw config set --dry-run path performs resolvability checks by calling resolveSecretRefValue() for each affected SecretRef.
This has two security impacts:
- Unintended command execution / side effects in dry-run:
resolveSecretRefValue()can invokeexecsecret providers, which spawn a child process (spawn(...)insrc/secrets/resolve.ts). As a result, running--dry-run(including on batch payloads) can execute configured commands, potentially causing network calls, state changes, or other side effects, contrary to typical “dry run” expectations. - Potential secret leakage via error strings: failures are captured as
message: String(err)and emitted to the terminal (non-JSON mode) or included inerrors[].message(JSON mode). For exec providers, the error message may incorporate provider-supplied text (e.g.,entry.messagefrom the exec provider response), which could include sensitive material (such as tokens embedded in provider error messages).
Vulnerable code (dry-run resolvability loop):
for (const ref of params.refs) {
try {
await resolveSecretRefValue(ref, {
config: params.config,
env: process.env,
});
} catch (err) {
failures.push({ kind: "resolvability", message: String(err), ref: `${ref.source}:${ref.provider}:${ref.id}` });
}
}Because collectDryRunRefs() can include all refs that use a touched provider alias, a single provider update in dry-run may trigger many provider executions (and this code does not pass a cache/batch to coalesce calls), increasing the side-effect/DoS risk.
Recommendation
Safer dry-run behavior
-
Do not execute exec providers by default in
--dry-run(or require an explicit opt-in).- Add a flag such as
--dry-run --check-resolvabilityor--dry-run --allow-exec. - In default
--dry-run, restrict checks to:- config schema validation
- SecretRef/provider shape validation
- exec provider command path security checks (ownership/permissions/trustedDirs)
- Add a flag such as
-
Redact/limit error strings returned to users:
- Prefer structured errors with safe fields (
scope,source,provider,refId, and a fixed message). - Avoid embedding provider-supplied strings directly into CLI output.
- Prefer structured errors with safe fields (
-
Reduce repeated executions if resolvability remains enabled:
- Batch by provider and use the existing resolver’s grouping (
resolveSecretRefValues(refs, { cache })) to execute each provider at most once per dry-run.
- Batch by provider and use the existing resolver’s grouping (
Example: avoid exec by default and sanitize messages:
try {
if (ref.source === "exec" && !opts.allowExecInDryRun) {
throw new Error("Exec SecretRef resolvability is disabled in --dry-run (use --allow-exec).")
}
await resolveSecretRefValue(ref, { config: params.config, env: process.env });
} catch (err) {
failures.push({
kind: "resolvability",
message: err instanceof Error ? err.message : "SecretRef resolution failed",
ref: `${ref.source}:${ref.provider}:${ref.id}`,
});
}2. 🔵 Unbounded synchronous read of --batch-file enables local denial of service
| Property | Value |
|---|---|
| Severity | Low |
| CWE | CWE-400 |
| Location | src/cli/config-set-input.ts:124-129 |
Description
The batch mode parser reads the user-supplied --batch-file path using fs.readFileSync() with no size limit and then parses it with JSON5.
Impact:
- A very large file (or special file like
/dev/zeroon Unix) can cause excessive memory usage / blocking CPU, freezing the CLI process. - Because it is synchronous I/O, the process is blocked until the entire file is read.
Vulnerable code:
const raw = fs.readFileSync(pathname, "utf8");
return parseBatchEntries(raw, "--batch-file");Recommendation
Add defensive limits and avoid reading unbounded/special files.
Suggested mitigation (size cap + clearer error):
import fs from "node:fs";
const MAX_BATCH_BYTES = 1024 * 1024; // 1 MiB (tune as needed)
const stat = fs.statSync(pathname);
if (!stat.isFile()) {
throw new Error("--batch-file must point to a regular file.");
}
if (stat.size > MAX_BATCH_BYTES) {
throw new Error(`--batch-file is too large (${stat.size} bytes > ${MAX_BATCH_BYTES}).`);
}
const raw = fs.readFileSync(pathname, "utf8");Optionally:
- make the limit configurable (e.g.
--batch-max-bytes) - use async I/O (
fs.promises.readFile) to reduce blocking (still keep a size cap).
Analyzed PR: #49296 at commit dc9f4ab
Last updated on: 2026-03-17T23:58:52Z
Greptile SummaryThis PR significantly expands the Two issues worth addressing before merge:
Confidence Score: 3/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/cli/config-set-input.ts
Line: 38-44
Comment:
**Exported `hasBatchMode` is dead code — logic duplicated inline in `runConfigSet`**
`hasBatchMode` is exported here but is never imported by `config-cli.ts`. Instead, `config-cli.ts` (lines 860–864) contains an inline duplicate of the same boolean expression:
```ts
// config-cli.ts (duplicated inline, never uses the export)
const hasBatchMode = Boolean(
(opts.cliOptions.batchJson && opts.cliOptions.batchJson.trim().length > 0) ||
(opts.cliOptions.batchFile && opts.cliOptions.batchFile.trim().length > 0),
);
```
If the batch-detection logic changes in `config-set-input.ts` (e.g. adding a new batch flag), the change won't propagate to `runConfigSet`, and the two copies will silently diverge. Either import and call `hasBatchMode(opts.cliOptions)` inside `runConfigSet`, or remove the export entirely and keep the logic local.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/cli/config-cli.ts
Line: 655-676
Comment:
**`--dry-run` in plain value mode performs no validation — always succeeds silently**
When all operations have `inputMode === "value"` (i.e. no `--strict-json`, no builder flags, no batch mode), both `hasJsonMode` and `hasBuilderMode` are `false`. As a result, neither `collectDryRunSchemaErrors` nor `collectDryRunResolvabilityErrors` is called, `errors` stays empty, and dry-run always reports success — regardless of whether the value is valid for the schema.
For example:
```bash
openclaw config set gateway.port '"not-a-number"' --dry-run
# ✓ Dry run successful: 1 update(s) validated ← no schema check ran
```
The docs do note this scoping, but users who instinctively add `--dry-run` to any `config set` invocation will receive a false sense of safety. At a minimum, consider emitting a warning when dry-run is requested in value mode and no checks will be performed, or document this limitation prominently in the CLI help text for `--dry-run`.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: "Docs: revert README ..." |
| export function hasBatchMode(opts: ConfigSetOptions): boolean { | ||
| return Boolean( | ||
| (opts.batchJson && opts.batchJson.trim().length > 0) || | ||
| (opts.batchFile && opts.batchFile.trim().length > 0), | ||
| ); | ||
| } | ||
|
|
There was a problem hiding this comment.
Exported
hasBatchMode is dead code — logic duplicated inline in runConfigSet
hasBatchMode is exported here but is never imported by config-cli.ts. Instead, config-cli.ts (lines 860–864) contains an inline duplicate of the same boolean expression:
// config-cli.ts (duplicated inline, never uses the export)
const hasBatchMode = Boolean(
(opts.cliOptions.batchJson && opts.cliOptions.batchJson.trim().length > 0) ||
(opts.cliOptions.batchFile && opts.cliOptions.batchFile.trim().length > 0),
);If the batch-detection logic changes in config-set-input.ts (e.g. adding a new batch flag), the change won't propagate to runConfigSet, and the two copies will silently diverge. Either import and call hasBatchMode(opts.cliOptions) inside runConfigSet, or remove the export entirely and keep the logic local.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/config-set-input.ts
Line: 38-44
Comment:
**Exported `hasBatchMode` is dead code — logic duplicated inline in `runConfigSet`**
`hasBatchMode` is exported here but is never imported by `config-cli.ts`. Instead, `config-cli.ts` (lines 860–864) contains an inline duplicate of the same boolean expression:
```ts
// config-cli.ts (duplicated inline, never uses the export)
const hasBatchMode = Boolean(
(opts.cliOptions.batchJson && opts.cliOptions.batchJson.trim().length > 0) ||
(opts.cliOptions.batchFile && opts.cliOptions.batchFile.trim().length > 0),
);
```
If the batch-detection logic changes in `config-set-input.ts` (e.g. adding a new batch flag), the change won't propagate to `runConfigSet`, and the two copies will silently diverge. Either import and call `hasBatchMode(opts.cliOptions)` inside `runConfigSet`, or remove the export entirely and keep the logic local.
How can I resolve this? If you propose a fix, please make it concise.| }); | ||
| continue; | ||
| } | ||
| operations.push( | ||
| buildValueAssignmentOperation({ | ||
| requestedPath: path, | ||
| value: entry.value, | ||
| inputMode: "json", | ||
| }), | ||
| ); | ||
| } | ||
| return operations; | ||
| } | ||
|
|
||
| function modeError(message: string): Error { | ||
| return new Error(`config set mode error: ${message}`); | ||
| } | ||
|
|
||
| function buildSingleSetOperations(params: { | ||
| path?: string; | ||
| value?: string; | ||
| opts: ConfigSetOptions; |
There was a problem hiding this comment.
--dry-run in plain value mode performs no validation — always succeeds silently
When all operations have inputMode === "value" (i.e. no --strict-json, no builder flags, no batch mode), both hasJsonMode and hasBuilderMode are false. As a result, neither collectDryRunSchemaErrors nor collectDryRunResolvabilityErrors is called, errors stays empty, and dry-run always reports success — regardless of whether the value is valid for the schema.
For example:
openclaw config set gateway.port '"not-a-number"' --dry-run
# ✓ Dry run successful: 1 update(s) validated ← no schema check ranThe docs do note this scoping, but users who instinctively add --dry-run to any config set invocation will receive a false sense of safety. At a minimum, consider emitting a warning when dry-run is requested in value mode and no checks will be performed, or document this limitation prominently in the CLI help text for --dry-run.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/config-cli.ts
Line: 655-676
Comment:
**`--dry-run` in plain value mode performs no validation — always succeeds silently**
When all operations have `inputMode === "value"` (i.e. no `--strict-json`, no builder flags, no batch mode), both `hasJsonMode` and `hasBuilderMode` are `false`. As a result, neither `collectDryRunSchemaErrors` nor `collectDryRunResolvabilityErrors` is called, `errors` stays empty, and dry-run always reports success — regardless of whether the value is valid for the schema.
For example:
```bash
openclaw config set gateway.port '"not-a-number"' --dry-run
# ✓ Dry run successful: 1 update(s) validated ← no schema check ran
```
The docs do note this scoping, but users who instinctively add `--dry-run` to any `config set` invocation will receive a false sense of safety. At a minimum, consider emitting a warning when dry-run is requested in value mode and no checks will be performed, or document this limitation prominently in the CLI help text for `--dry-run`.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 754ef5ddcf
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| path.length === 3 && | ||
| path[0] === SECRET_PROVIDER_PATH_PREFIX[0] && | ||
| path[1] === SECRET_PROVIDER_PATH_PREFIX[1] | ||
| ) { | ||
| return path[2] ?? null; |
There was a problem hiding this comment.
Track nested provider edits in dry-run ref checks
When config set updates a nested provider field (for example secrets.providers.default.path) in JSON/value mode, this helper returns null unless the path is exactly 3 segments, so buildValueAssignmentOperation never marks the provider alias as touched. As a result, collectDryRunRefs skips refs that depend on that provider and --dry-run can incorrectly succeed even though existing refs become unresolvable after the provider change; this contradicts the documented "full resolvability" dry-run behavior for JSON/batch mode.
Useful? React with 👍 / 👎.
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
…penclaw#49296) * CLI: expand config set ref/provider builder and dry-run * Docs: revert README Discord token example
Summary
Implements the expanded
openclaw config setsurface discussed for SecretRef/provider assignment and dry-run validation.This PR keeps the feature scoped to editing
openclaw.jsononly (no secret-store write behavior) and extends the existing CLI surface rather than adding separate secret-writing commands.What changed
config setassignment modes with explicit mode resolution:config set <path> <value>)--ref-provider --ref-source --ref-id)secrets.providers.<alias>(--provider-*)--batch-json/--batch-file)--dry-runbehavior:--dry-run --jsonsrc/cli/config-set-parser.tssrc/cli/config-set-input.tssrc/cli/config-set-dryrun.tssrc/secrets/target-registry-query.tsdocs/cli/config.mddocs/cli/index.mddocs/channels/discord.mdREADME.mdUsage examples
Validation
pnpm test -- src/cli/config-set-mode.test.ts src/cli/config-set-input.test.ts src/cli/config-cli.test.ts src/cli/config-cli.integration.test.ts src/secrets/target-registry.test.tsScope notes
Linked issues
openclaw secrets setfor GUI/automation use #33702openclaw secrets setfor GUI/automation use #33702