@clawchatsai/connector 0.1.20 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",
@@ -9,17 +9,26 @@ import { sendError } from '../util/http.js';
9
9
  // User-sent attachments live in the gateway's inbound media store (`media://inbound/<file>`),
10
10
  // served by the Control UI's authenticated assistant-media route:
11
11
  // /__<platform>__/assistant-media?source=media://inbound/<file>&sessionKey=…&agentId=…
12
- // The route is matched by shape (no brand string), and only plain inbound sources pass.
12
+ // The same route serves raw `MEDIA:<path>` lines left in assistant text (claude-cli replies),
13
+ // which the Control UI parses client-side (chat-message-local-media.ts). Local sources need a
14
+ // sessionKey: the gateway then applies that session's file-read policy (it refuses e.g.
15
+ // /etc/passwd and its own config). `meta=1` (a GET returning the availability JSON the Control
16
+ // UI uses for "Unavailable · <reason>") passes; `allow` (admin outside-folder grant, POST) and
17
+ // `mediaTicket` don't. The route is matched by shape (no brand string).
13
18
  const ALLOWED_PREFIX = '/api/chat/media/outgoing/';
14
19
  const INBOUND_ROUTE = /^\/__[a-z0-9-]+__\/assistant-media\?/;
15
20
  const INBOUND_SOURCE = /^media:\/\/inbound\/[^/?#\\]+$/;
21
+ const LOCAL_SOURCE = /^(?:\/|~\/|\.\/|file:|[a-zA-Z]:[\\/])|^[^:]+$/;
16
22
 
17
23
  export function isAllowedMediaTarget(target) {
18
24
  if (typeof target !== 'string' || target.includes('..')) return false;
19
25
  if (target.startsWith(ALLOWED_PREFIX)) return true;
20
26
  if (!INBOUND_ROUTE.test(target)) return false;
21
27
  const q = new URLSearchParams(target.slice(target.indexOf('?') + 1));
22
- return INBOUND_SOURCE.test(q.get('source') || '') && !q.has('meta') && !q.has('allow') && !q.has('mediaTicket');
28
+ if ((q.has('meta') && q.getAll('meta').join() !== '1') || q.has('allow') || q.has('mediaTicket')) return false;
29
+ const source = q.get('source') || '';
30
+ if (INBOUND_SOURCE.test(source)) return true;
31
+ return !!source && !source.includes('\0') && LOCAL_SOURCE.test(source) && !!q.get('sessionKey');
23
32
  }
24
33
 
25
34
  export function createGatewayMediaHandler({ gatewayWsUrl, gatewayToken }) {
@@ -12,10 +12,25 @@ test('inbound user media via the assistant-media route is allowed', () => {
12
12
  assert.equal(isAllowedMediaTarget(inbound('media://inbound/red---9c45.png')), true);
13
13
  });
14
14
 
15
+ test('local MEDIA: sources pass with a sessionKey (the gateway applies its file policy)', () => {
16
+ for (const s of ['/tmp/shot.png', '~/ws/a.png', './report.pdf', 'mockups/a.png', 'file:///tmp/a.png']) {
17
+ assert.equal(isAllowedMediaTarget(inbound(s)), true, s);
18
+ }
19
+ assert.equal(isAllowedMediaTarget(`/__gw__/assistant-media?source=${encodeURIComponent('/tmp/shot.png')}`), false);
20
+ assert.equal(isAllowedMediaTarget(inbound('/tmp/../etc/passwd')), false);
21
+ assert.equal(isAllowedMediaTarget(inbound('https://example.com/a.png')), false);
22
+ assert.equal(isAllowedMediaTarget(inbound('/tmp/a.png', '&mediaTicket=x')), false);
23
+ });
24
+
25
+ test('meta=1 availability lookups pass; allow and other meta values do not', () => {
26
+ assert.equal(isAllowedMediaTarget(inbound('/tmp/a.png', '&meta=1')), true);
27
+ assert.equal(isAllowedMediaTarget(inbound('/tmp/a.png', '&meta=1&allow=1')), false);
28
+ assert.equal(isAllowedMediaTarget(inbound('/tmp/a.png', '&meta=2')), false);
29
+ assert.equal(isAllowedMediaTarget(inbound('/tmp/a.png', '&meta=1&meta=1')), false);
30
+ });
31
+
15
32
  test('anything else is rejected', () => {
16
33
  assert.equal(isAllowedMediaTarget('/api/sessions'), false);
17
- assert.equal(isAllowedMediaTarget(inbound('/etc/passwd')), false);
18
- assert.equal(isAllowedMediaTarget(inbound('file:///etc/passwd')), false);
19
34
  assert.equal(isAllowedMediaTarget(inbound('media://inbound/a/b.png')), false);
20
35
  assert.equal(isAllowedMediaTarget(inbound('media://inbound/..png')), false);
21
36
  assert.equal(isAllowedMediaTarget(inbound('media://inbound/x.png', '&meta=1&allow=1')), false);
@@ -27,7 +27,7 @@ export const ROW_FIELDS = new Set([
27
27
  'category', 'pinned', 'pinnedAt', 'archived', 'archivedAt',
28
28
  'unread', 'lastReadAt', 'markedUnreadAt',
29
29
  'createdAt', 'updatedAt', 'lastActivityAt', 'lastInteractionAt',
30
- 'status', 'hasActiveRun', 'activeRunIds', 'lastRunId', 'lastRunError',
30
+ 'status', 'hasActiveRun', 'activeRunIds', 'lastRunId', 'lastRunError', 'endedAt', 'agentStatus',
31
31
  'model', 'modelProvider', 'thinkingLevel', 'contextTokens', 'totalTokens', 'totalTokensFresh',
32
32
  'inputTokens', 'outputTokens', 'permissionMode', 'contextBudgetStatus', 'fastMode', 'effectiveFastMode',
33
33
  ]);