Skip to content

Commit 424521a

Browse files
authored
fix(file-transfer): keep remembered approvals exact (#129762)
* fix(file-transfer): bind standing approvals exactly * fix(file-transfer): keep validator error lint-safe * fix(file-transfer): bind directory listing target before I/O * fix(file-transfer): keep dir list preflight type stable * test(file-transfer): split directory listing policy coverage * fix(file-transfer): bind final node effects * fix(file-transfer): close migration and archive gaps * fix(file-transfer): bind standing grants before preflight * fix(file-transfer): bind directory listings to checked target * fix(file-transfer): bind final effects to filesystem identity * test(file-transfer): prove exact approval transport * fix(file-transfer): keep reapproval prompts path-scoped * chore(config): refresh generated baselines
1 parent d001975 commit 424521a

40 files changed

Lines changed: 3932 additions & 921 deletions

‎config/max-lines-baseline.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ extensions/feishu/src/outbound.ts
105105
extensions/feishu/src/reply-dispatcher.test.ts
106106
extensions/feishu/src/reply-dispatcher.ts
107107
extensions/feishu/src/streaming-card.test.ts
108-
extensions/file-transfer/src/shared/node-invoke-policy.ts
109108
extensions/firecrawl/src/firecrawl-tools.test.ts
110109
extensions/github-copilot/index.test.ts
111110
extensions/google-meet/index.test.ts
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"core": 2353,
2+
"core": 2356,
33
"channel": 3615,
4-
"plugin": 4003
4+
"plugin": 4015
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
c9e6f7282f817aa0fc6f1176058e7018ec5c8d7fb2bad7ca9bd8f2c4450e531c config-baseline.json
2-
030667715ee8a20bfd348082dde1b1e51b8bf601f9c1029c30f1b3949e1c3f42 config-baseline.core.json
1+
51e54cf1cbb023f1d15c3fd473e1b51d0ee87e45a135d414b26be96b12ad7217 config-baseline.json
2+
27d8ef9ccc1e2964a38d45c1d1ec35b84065cd1b03d7b5886be6f17f934f6b90 config-baseline.core.json
33
555ba0d69bdff8ea8160eb1602c6283cb831641b0f2c883c903c0fd29a923daa config-baseline.channel.json
4-
55b3a04ee8e04f1d96c67c7b5cd69c525f1bfded220a9ecfa24c9bf1452db494 config-baseline.plugin.json
4+
70ec49c2648217d806e0ed77e5cd0283ea9c4db797e5cee4ed74833f7a32a179 config-baseline.plugin.json

‎docs/plugins/reference/file-transfer.md‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,37 @@ Fetch, list, and write files on paired nodes via dedicated node commands. Bypass
1616

1717
## Surface
1818

19-
contracts: `tools`
19+
CLI commands: `openclaw file-transfer`; contracts: `tools`
20+
21+
<!-- openclaw-plugin-reference:manual-start -->
22+
23+
## Migrate existing permissions
24+
25+
After upgrading, older positive file-transfer permissions remain inactive until
26+
you review them. Deny rules, size limits, and symlink settings continue to
27+
apply. Run this command on the Gateway host in an interactive terminal:
28+
29+
```bash
30+
openclaw file-transfer approvals migrate
31+
```
32+
33+
For each older path, choose one outcome:
34+
35+
- **Require exact reapproval** removes the ambiguous permission. The next use
36+
prompts once and records the exact node, command, requested path, and
37+
canonical target.
38+
- **Keep as an intentional wildcard** preserves the entry as an
39+
operator-authored glob.
40+
- **Remove this permission** deletes the positive entry.
41+
42+
Use `--dry-run` to review the plan without writing. Non-interactive and `--json`
43+
runs never guess; they list unresolved items and direct you back to the same
44+
interactive command.
45+
46+
The migration writes the new format once after confirmation and reports whether
47+
the adjacent config backup was verified. Older OpenClaw versions cannot read
48+
the migrated format. To downgrade, restore that reported `.bak` file before
49+
starting the older version; doing so also restores the older permission
50+
semantics.
51+
52+
<!-- openclaw-plugin-reference:manual-end -->
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { describe, expect, it } from "vitest";
2+
import { legacyConfigRules } from "./doctor-contract-api.js";
3+
4+
describe("file-transfer Doctor handoff", () => {
5+
const rule = legacyConfigRules[0];
6+
7+
it("reports legacy positive permissions with the exact migration command", () => {
8+
expect(rule?.match({ nodes: { node: { allowReadPaths: ["/tmp/report-*.txt"] } } })).toBe(true);
9+
expect(rule?.message).toContain("openclaw file-transfer approvals migrate");
10+
});
11+
12+
it("does not report reviewed or deny-only policy", () => {
13+
expect(rule?.match({ policyVersion: 2, nodes: { node: { allowReadPaths: ["/**"] } } })).toBe(
14+
false,
15+
);
16+
expect(rule?.match({ nodes: { node: { denyPaths: ["**/.ssh/**"] } } })).toBe(false);
17+
});
18+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { asNullableRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
2+
3+
function hasLegacyPositivePolicy(value: unknown): boolean {
4+
const config = asNullableRecord(value);
5+
if (!config || config.policyVersion === 2) {
6+
return false;
7+
}
8+
const nodes = asNullableRecord(config.nodes);
9+
if (!nodes) {
10+
return false;
11+
}
12+
return Object.values(nodes).some((rawNode) => {
13+
const node = asNullableRecord(rawNode);
14+
return Boolean(
15+
node &&
16+
((Array.isArray(node.allowReadPaths) && node.allowReadPaths.length > 0) ||
17+
(Array.isArray(node.allowWritePaths) && node.allowWritePaths.length > 0)),
18+
);
19+
});
20+
}
21+
22+
export const legacyConfigRules = [
23+
{
24+
path: ["plugins", "entries", "file-transfer", "config"],
25+
message:
26+
'File-transfer permissions need review and remain inactive. Run "openclaw file-transfer approvals migrate".',
27+
match: hasLegacyPositivePolicy,
28+
},
29+
];

‎extensions/file-transfer/index.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ describe("file-transfer plugin entry", () => {
3535
it("registers static command and tool descriptors without importing runtime handlers", () => {
3636
const registerNodeInvokePolicy = vi.fn();
3737
const registerTool = vi.fn();
38+
const registerCli = vi.fn();
3839

3940
pluginEntry.register({
41+
registerCli,
4042
registerNodeInvokePolicy,
4143
registerTool,
4244
} as never);
@@ -48,6 +50,13 @@ describe("file-transfer plugin entry", () => {
4850
"file.write",
4951
]);
5052
expect(registerNodeInvokePolicy).toHaveBeenCalledTimes(1);
53+
expect(registerCli.mock.calls[0]?.[1]?.descriptors).toEqual([
54+
{
55+
name: "file-transfer",
56+
description: "Review file-transfer standing approvals",
57+
hasSubcommands: true,
58+
},
59+
]);
5160
expect(registerNodeInvokePolicy.mock.calls[0]?.[0].commands).toEqual([
5261
"file.fetch",
5362
"dir.list",
@@ -65,9 +74,11 @@ describe("file-transfer plugin entry", () => {
6574
it("fails closed if the lazy policy module cannot load", async () => {
6675
const registerNodeInvokePolicy = vi.fn();
6776
const registerTool = vi.fn();
77+
const registerCli = vi.fn();
6878
const invokeNode = vi.fn();
6979

7080
pluginEntry.register({
81+
registerCli,
7182
registerNodeInvokePolicy,
7283
registerTool,
7384
} as never);

‎extensions/file-transfer/index.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ export default definePluginEntry({
9292
description: "Fetch, list, and write files on paired nodes via dedicated node commands.",
9393
nodeHostCommands: fileTransferNodeHostCommands,
9494
register(api) {
95+
api.registerCli(
96+
async ({ program }) => {
97+
const { registerFileTransferCli } = await import("./src/cli.js");
98+
registerFileTransferCli(program);
99+
},
100+
{
101+
descriptors: [
102+
{
103+
name: "file-transfer",
104+
description: "Review file-transfer standing approvals",
105+
hasSubcommands: true,
106+
},
107+
],
108+
},
109+
);
95110
api.registerNodeInvokePolicy(createLazyFileTransferNodeInvokePolicy());
96111
api.registerTool(
97112
createLazyTool(FILE_FETCH_TOOL_DESCRIPTOR, async () => {

‎extensions/file-transfer/openclaw.plugin.json‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,57 @@
66
"enabledByDefault": true,
77
"name": "File Transfer",
88
"description": "Fetch, list, and write files on paired nodes via dedicated node commands. Bypasses bash stdout truncation by using base64 over node.invoke for binaries up to 16 MB.",
9+
"cliCommands": [
10+
{
11+
"name": "file-transfer",
12+
"description": "Review file-transfer standing approvals",
13+
"hasSubcommands": true
14+
}
15+
],
16+
"doctorContract": {
17+
"configRepair": true
18+
},
919
"contracts": {
1020
"tools": ["file_fetch", "dir_list", "dir_fetch", "file_write"]
1121
},
1222
"configSchema": {
1323
"type": "object",
1424
"additionalProperties": false,
1525
"properties": {
26+
"policyVersion": {
27+
"type": "integer",
28+
"const": 2
29+
},
30+
"literalGrants": {
31+
"type": "array",
32+
"items": {
33+
"type": "object",
34+
"additionalProperties": false,
35+
"required": ["nodeId", "command", "requestedPath", "canonicalPath"],
36+
"properties": {
37+
"nodeId": { "type": "string", "minLength": 1 },
38+
"command": {
39+
"type": "string",
40+
"enum": ["file.fetch", "dir.list", "dir.fetch", "file.write"]
41+
},
42+
"requestedPath": { "type": "string", "minLength": 1 },
43+
"canonicalPath": { "type": "string", "minLength": 1 }
44+
}
45+
}
46+
},
47+
"pendingReapprovals": {
48+
"type": "array",
49+
"items": {
50+
"type": "object",
51+
"additionalProperties": false,
52+
"required": ["selector", "kind", "path"],
53+
"properties": {
54+
"selector": { "type": "string", "minLength": 1 },
55+
"kind": { "type": "string", "enum": ["read", "write"] },
56+
"path": { "type": "string", "minLength": 1 }
57+
}
58+
}
59+
},
1660
"nodes": {
1761
"type": "object",
1862
"additionalProperties": {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { describe, expect, it } from "vitest";
2+
import { applyApprovalMigration, listLegacyApprovalItems } from "./approvals-migration.js";
3+
4+
describe("file-transfer approval migration", () => {
5+
it("enumerates legacy positive permissions without changing wildcard semantics", () => {
6+
expect(
7+
listLegacyApprovalItems({
8+
nodes: {
9+
Shared: { allowReadPaths: ["/tmp/a", "/tmp/*.log", "/tmp/a"] },
10+
"*": { allowWritePaths: ["/tmp/**"] },
11+
},
12+
}),
13+
).toEqual([
14+
{ selector: "Shared", kind: "read", path: "/tmp/a" },
15+
{ selector: "Shared", kind: "read", path: "/tmp/*.log" },
16+
{ selector: "*", kind: "write", path: "/tmp/**" },
17+
]);
18+
});
19+
20+
it("atomically separates exact grants from confirmed authored globs", () => {
21+
const config = {
22+
nodes: {
23+
Shared: {
24+
ask: "off",
25+
allowReadPaths: ["/tmp/report-*.txt", "/var/log/**", "/tmp/remove.txt"],
26+
denyPaths: ["**/.ssh/**"],
27+
},
28+
},
29+
};
30+
const items = listLegacyApprovalItems(config);
31+
const migrated = applyApprovalMigration(config, [
32+
{
33+
item: items[0]!,
34+
action: "exact",
35+
},
36+
{ item: items[1]!, action: "keep-glob" },
37+
{ item: items[2]!, action: "remove" },
38+
]);
39+
40+
expect(migrated).toEqual({
41+
policyVersion: 2,
42+
pendingReapprovals: [{ selector: "Shared", kind: "read", path: "/tmp/report-*.txt" }],
43+
nodes: {
44+
Shared: {
45+
ask: "off",
46+
allowReadPaths: ["/var/log/**"],
47+
denyPaths: ["**/.ssh/**"],
48+
},
49+
},
50+
});
51+
expect(config.nodes.Shared.allowReadPaths).toEqual([
52+
"/tmp/report-*.txt",
53+
"/var/log/**",
54+
"/tmp/remove.txt",
55+
]);
56+
});
57+
58+
it("does not widen an off policy while scheduling one exact path for reapproval", () => {
59+
const migrated = applyApprovalMigration(
60+
{
61+
nodes: {
62+
node: { ask: "off", allowReadPaths: ["/tmp/report-*.txt"] },
63+
},
64+
},
65+
[
66+
{
67+
item: { selector: "node", kind: "read", path: "/tmp/report-*.txt" },
68+
action: "exact",
69+
},
70+
],
71+
);
72+
73+
expect(migrated.nodes).toEqual({ node: { ask: "off", allowReadPaths: [] } });
74+
expect(migrated.pendingReapprovals).toEqual([
75+
{ selector: "node", kind: "read", path: "/tmp/report-*.txt" },
76+
]);
77+
});
78+
});

0 commit comments

Comments
 (0)