mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:34:32 +00:00
fix(gateway): allowlist system.run params
This commit is contained in:
@@ -85,6 +85,28 @@ function approvalMatchesRequest(params: SystemRunParamsLike, record: ExecApprova
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pickSystemRunParams(raw: Record<string, unknown>): Record<string, unknown> {
|
||||||
|
// Defensive allowlist: only forward fields that the node-host `system.run` handler understands.
|
||||||
|
// This prevents future internal control fields from being smuggled through the gateway.
|
||||||
|
const next: Record<string, unknown> = {};
|
||||||
|
for (const key of [
|
||||||
|
"command",
|
||||||
|
"rawCommand",
|
||||||
|
"cwd",
|
||||||
|
"env",
|
||||||
|
"timeoutMs",
|
||||||
|
"needsScreenRecording",
|
||||||
|
"agentId",
|
||||||
|
"sessionKey",
|
||||||
|
"runId",
|
||||||
|
]) {
|
||||||
|
if (key in raw) {
|
||||||
|
next[key] = raw[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gate `system.run` approval flags (`approved`, `approvalDecision`) behind a real
|
* Gate `system.run` approval flags (`approved`, `approvalDecision`) behind a real
|
||||||
* `exec.approval.*` record. This prevents users with only `operator.write` from
|
* `exec.approval.*` record. This prevents users with only `operator.write` from
|
||||||
@@ -110,9 +132,7 @@ export function sanitizeSystemRunParamsForForwarding(opts: {
|
|||||||
|
|
||||||
// Always strip control fields from user input. If the override is allowed,
|
// Always strip control fields from user input. If the override is allowed,
|
||||||
// we re-add trusted fields based on the gateway approval record.
|
// we re-add trusted fields based on the gateway approval record.
|
||||||
const next: Record<string, unknown> = { ...obj };
|
const next: Record<string, unknown> = pickSystemRunParams(obj);
|
||||||
delete next.approved;
|
|
||||||
delete next.approvalDecision;
|
|
||||||
|
|
||||||
if (!wantsApprovalOverride) {
|
if (!wantsApprovalOverride) {
|
||||||
return { ok: true, params: next };
|
return { ok: true, params: next };
|
||||||
|
|||||||
Reference in New Issue
Block a user