Skip to content

Commit a3d6b17

Browse files
authored
fix(share): lock bundle fetches to the configured publisher (anomalyco#1241)
Keep server-side share publish and fetch traffic on the configured OpenWork publisher so bundle links cannot steer host requests to arbitrary targets. Add a warning-backed client-side fallback for manual imports from untrusted bundle URLs. Co-authored-by: src-opn <[email protected]>
1 parent af4b9e8 commit a3d6b17

13 files changed

Lines changed: 279 additions & 52 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { strict as assert } from "node:assert";
2+
3+
import { describeBundleUrlTrust, isConfiguredBundlePublisherUrl } from "../src/app/bundles/url-policy";
4+
5+
const trusted = describeBundleUrlTrust(
6+
"https://share.openworklabs.com/b/01ARZ3NDEKTSV4RRFFQ69G5FAV",
7+
"https://share.openworklabs.com",
8+
);
9+
10+
assert.deepEqual(trusted, {
11+
trusted: true,
12+
bundleId: "01ARZ3NDEKTSV4RRFFQ69G5FAV",
13+
actualOrigin: "https://share.openworklabs.com",
14+
configuredOrigin: "https://share.openworklabs.com",
15+
});
16+
17+
const untrusted = describeBundleUrlTrust(
18+
"https://evil.example/b/01ARZ3NDEKTSV4RRFFQ69G5FAV",
19+
"https://share.openworklabs.com",
20+
);
21+
22+
assert.deepEqual(untrusted, {
23+
trusted: false,
24+
bundleId: "01ARZ3NDEKTSV4RRFFQ69G5FAV",
25+
actualOrigin: "https://evil.example",
26+
configuredOrigin: "https://share.openworklabs.com",
27+
});
28+
29+
assert.equal(
30+
isConfiguredBundlePublisherUrl(
31+
"https://share.openworklabs.com/b/01ARZ3NDEKTSV4RRFFQ69G5FAV",
32+
"https://share.openworklabs.com",
33+
),
34+
true,
35+
);
36+
37+
assert.equal(
38+
isConfiguredBundlePublisherUrl(
39+
"https://share.openworklabs.com/not-a-bundle",
40+
"https://share.openworklabs.com",
41+
),
42+
false,
43+
);
44+
45+
console.log("bundle-url-policy ok");

‎apps/app/src/app/app.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { Session } from "@opencode-ai/sdk/v2/client";
1616
import { getVersion } from "@tauri-apps/api/app";
1717
import { getCurrentWebview } from "@tauri-apps/api/webview";
1818
import ModelPickerModal from "./components/model-picker-modal";
19+
import ConfirmModal from "./components/confirm-modal";
1920
import ResetModal from "./components/reset-modal";
2021
import SkillDestinationModal from "./bundles/skill-destination-modal";
2122
import BundleImportModal from "./bundles/import-modal";
@@ -2400,6 +2401,24 @@ export default function App() {
24002401
}}
24012402
/>
24022403

2404+
<ConfirmModal
2405+
open={Boolean(bundlesStore.untrustedBundleWarning())}
2406+
title="Import from an untrusted bundle link?"
2407+
message={(() => {
2408+
const warning = bundlesStore.untrustedBundleWarning();
2409+
const actualOrigin = warning?.actualOrigin?.trim() || "an unknown origin";
2410+
const configuredOrigin = warning?.configuredOrigin?.trim() || "the configured OpenWork share service";
2411+
return `This link points to ${actualOrigin}, but OpenWork only auto-imports bundles from ${configuredOrigin}. Untrusted bundles can contain malicious instructions or settings. Only continue if you trust the sender and expect this import.`;
2412+
})()}
2413+
confirmLabel="Import anyway"
2414+
cancelLabel="Cancel"
2415+
variant="warning"
2416+
onConfirm={() => {
2417+
void bundlesStore.confirmUntrustedBundleWarning();
2418+
}}
2419+
onCancel={bundlesStore.dismissUntrustedBundleWarning}
2420+
/>
2421+
24032422
<BundleStartModal
24042423
open={Boolean(bundlesStore.bundleStartRequest())}
24052424
templateName={bundlesStore.bundleStartRequest()?.bundle.name?.trim() || "this template"}

‎apps/app/src/app/bundles/publish.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createDenClient, readDenSettings, writeDenSettings } from "../lib/den";
2-
import { DEFAULT_OPENWORK_PUBLISHER_BASE_URL } from "../lib/publisher";
32
import type {
43
OpenworkServerClient,
54
OpenworkWorkspaceExport,
@@ -47,7 +46,6 @@ export async function publishWorkspaceProfileBundleFromWorkspace(input: {
4746
client: OpenworkServerClient;
4847
workspaceId: string;
4948
workspaceName: string;
50-
baseUrl?: string;
5149
sensitiveMode?: Exclude<OpenworkWorkspaceExportSensitiveMode, "auto"> | null;
5250
}) {
5351
const exported = await input.client.exportWorkspace(input.workspaceId, {
@@ -56,23 +54,20 @@ export async function publishWorkspaceProfileBundleFromWorkspace(input: {
5654
const payload = buildWorkspaceProfileBundle(input.workspaceName, exported);
5755
return input.client.publishBundle(payload, "workspace-profile", {
5856
name: payload.name,
59-
baseUrl: input.baseUrl ?? DEFAULT_OPENWORK_PUBLISHER_BASE_URL,
6057
});
6158
}
6259

6360
export async function publishSkillsSetBundleFromWorkspace(input: {
6461
client: OpenworkServerClient;
6562
workspaceId: string;
6663
workspaceName: string;
67-
baseUrl?: string;
6864
}) {
6965
const exported = await input.client.exportWorkspace(input.workspaceId, {
7066
sensitiveMode: "exclude",
7167
});
7268
const payload = buildSkillsSetBundle(input.workspaceName, exported);
7369
return input.client.publishBundle(payload, "skills-set", {
7470
name: payload.name,
75-
baseUrl: input.baseUrl ?? DEFAULT_OPENWORK_PUBLISHER_BASE_URL,
7671
});
7772
}
7873

‎apps/app/src/app/bundles/sources.ts‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { OpenworkServerClient } from "../lib/openwork-server";
44
import { isTauriRuntime, safeStringify } from "../utils";
55
import { parseBundlePayload } from "./schema";
66
import type { BundleImportIntent, BundleRequest, BundleV1 } from "./types";
7+
import { extractBundleId, isConfiguredBundlePublisherUrl } from "./url-policy";
78

89
function isSupportedDeepLinkProtocol(protocol: string): boolean {
910
const normalized = protocol.toLowerCase();
@@ -44,14 +45,7 @@ export function parseBundleDeepLink(rawUrl: string): BundleRequest | null {
4445

4546
try {
4647
if ((protocol === "https:" || protocol === "http:") && !rawBundleUrl.trim()) {
47-
const host = url.hostname.toLowerCase();
48-
const path = url.pathname.replace(/^\/+/, "");
49-
const segments = path.split("/").filter(Boolean);
50-
if (
51-
(host === "share.openworklabs.com" || host.endsWith(".openworklabs.com") || host === "share.openwork.software" || host.endsWith(".openwork.software"))
52-
&& segments[0] === "b"
53-
&& segments[1]
54-
) {
48+
if (isConfiguredBundlePublisherUrl(url.toString())) {
5549
return {
5650
bundleUrl: url.toString(),
5751
intent: normalizeBundleImportIntent(url.searchParams.get("ow_intent") ?? url.searchParams.get("intent")),
@@ -100,7 +94,11 @@ export function stripBundleQuery(rawUrl: string): string | null {
10094
return `${url.pathname}${search ? `?${search}` : ""}${url.hash}`;
10195
}
10296

103-
export async function fetchBundle(bundleUrl: string, serverClient?: OpenworkServerClient | null): Promise<BundleV1> {
97+
export async function fetchBundle(
98+
bundleUrl: string,
99+
serverClient?: OpenworkServerClient | null,
100+
options?: { forceClientFetch?: boolean },
101+
): Promise<BundleV1> {
104102
let targetUrl: URL;
105103
try {
106104
targetUrl = new URL(bundleUrl);
@@ -112,19 +110,17 @@ export async function fetchBundle(bundleUrl: string, serverClient?: OpenworkServ
112110
throw new Error("Bundle URL must use http(s).");
113111
}
114112

115-
const segments = targetUrl.pathname.split("/").filter(Boolean);
116-
if (segments[0] === "b" && segments[1] && segments.length === 2) {
117-
targetUrl.pathname = `/b/${segments[1]}/data`;
118-
targetUrl.searchParams.delete("format");
119-
} else if (segments[0] === "b" && segments[1] && segments[2] === "data") {
113+
const bundleId = extractBundleId(targetUrl);
114+
if (bundleId) {
115+
targetUrl.pathname = `/b/${bundleId}/data`;
120116
targetUrl.searchParams.delete("format");
121117
}
122118

123119
if (!targetUrl.searchParams.has("format")) {
124120
targetUrl.searchParams.set("format", "json");
125121
}
126122

127-
if (serverClient) {
123+
if (serverClient && !options?.forceClientFetch) {
128124
return parseBundlePayload(await serverClient.fetchBundle(targetUrl.toString()));
129125
}
130126

‎apps/app/src/app/bundles/store.ts‎

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "./apply";
2121
import { defaultPresetFromWorkspaceProfileBundle, describeBundleImport, parseBundlePayload } from "./schema";
2222
import { fetchBundle, parseBundleDeepLink } from "./sources";
23+
import { describeBundleUrlTrust } from "./url-policy";
2324
import type {
2425
BundleCreateWorkspaceRequest,
2526
BundleImportChoice,
@@ -39,8 +40,15 @@ type BundleProcessResult =
3940
| { mode: "start_modal"; bundle: BundleV1 }
4041
| { mode: "blocked_import_current"; bundle: BundleV1 }
4142
| { mode: "blocked_new_worker"; bundle: BundleV1 }
43+
| { mode: "untrusted_warning" }
4244
| { mode: "imported"; bundle: BundleV1 };
4345

46+
type UntrustedBundleWarning = {
47+
request: BundleRequest;
48+
actualOrigin: string | null;
49+
configuredOrigin: string | null;
50+
};
51+
4452
export type BundlesStore = ReturnType<typeof createBundlesStore>;
4553

4654
export function createBundlesStore(options: {
@@ -69,6 +77,7 @@ export function createBundlesStore(options: {
6977
const [bundleImportBusy, setBundleImportBusy] = createSignal(false);
7078
const [bundleImportError, setBundleImportError] = createSignal<string | null>(null);
7179
const [bundleNoticeShown, setBundleNoticeShown] = createSignal(false);
80+
const [untrustedBundleWarning, setUntrustedBundleWarning] = createSignal<UntrustedBundleWarning | null>(null);
7281

7382
const showSkillSuccessToast = (toast: { title: string; description: string }) => {
7483
options.showStatusToast({
@@ -86,6 +95,20 @@ export function createBundlesStore(options: {
8695
setCreateWorkspaceRequest(null);
8796
setBundleImportError(null);
8897
setBundleNoticeShown(false);
98+
setUntrustedBundleWarning(null);
99+
};
100+
101+
const maybeWarnAboutUntrustedBundle = (request: BundleRequest, options?: { allowUntrustedClientFetch?: boolean }) => {
102+
const rawUrl = request.bundleUrl?.trim() ?? "";
103+
if (!rawUrl || options?.allowUntrustedClientFetch) return false;
104+
const trust = describeBundleUrlTrust(rawUrl);
105+
if (trust.trusted) return false;
106+
setUntrustedBundleWarning({
107+
request,
108+
actualOrigin: trust.actualOrigin,
109+
configuredOrigin: trust.configuredOrigin,
110+
});
111+
return true;
89112
};
90113

91114
const resolveBundleWorkerTarget = () => {
@@ -194,11 +217,14 @@ export function createBundlesStore(options: {
194217
request: BundleRequest,
195218
target?: BundleImportTarget,
196219
bundleOverride?: BundleV1,
220+
importOptions?: { allowUntrustedClientFetch?: boolean },
197221
) => {
198222
try {
199223
const bundle =
200224
bundleOverride ??
201-
(await fetchBundle(request.bundleUrl?.trim() ?? "", options.openworkServer.openworkServerClient()));
225+
(await fetchBundle(request.bundleUrl?.trim() ?? "", options.openworkServer.openworkServerClient(), {
226+
forceClientFetch: importOptions?.allowUntrustedClientFetch,
227+
}));
202228
await importBundlePayload(bundle, target);
203229
options.setError(null);
204230
return true;
@@ -320,8 +346,17 @@ export function createBundlesStore(options: {
320346
}
321347
};
322348

323-
const processBundleRequest = async (request: BundleRequest): Promise<BundleProcessResult> => {
324-
const bundle = await fetchBundle(request.bundleUrl?.trim() ?? "", options.openworkServer.openworkServerClient());
349+
const processBundleRequest = async (
350+
request: BundleRequest,
351+
processOptions?: { allowUntrustedClientFetch?: boolean },
352+
): Promise<BundleProcessResult> => {
353+
if (maybeWarnAboutUntrustedBundle(request, processOptions)) {
354+
return { mode: "untrusted_warning" };
355+
}
356+
357+
const bundle = await fetchBundle(request.bundleUrl?.trim() ?? "", options.openworkServer.openworkServerClient(), {
358+
forceClientFetch: processOptions?.allowUntrustedClientFetch,
359+
});
325360

326361
if (bundle.type === "skill") {
327362
options.setView("settings");
@@ -454,6 +489,8 @@ export function createBundlesStore(options: {
454489
case "blocked_import_current":
455490
case "blocked_new_worker":
456491
return { ok: false, message: options.error() || "The bundle needs more worker setup before it can open." };
492+
case "untrusted_warning":
493+
return { ok: false, message: "Showed a security warning for an untrusted bundle link." };
457494
case "imported":
458495
return { ok: true, message: "Imported the bundle into the current worker." };
459496
}
@@ -473,6 +510,30 @@ export function createBundlesStore(options: {
473510
setBundleImportError(null);
474511
};
475512

513+
const dismissUntrustedBundleWarning = () => {
514+
if (bundleImportBusy()) return;
515+
setUntrustedBundleWarning(null);
516+
};
517+
518+
const confirmUntrustedBundleWarning = async () => {
519+
const warning = untrustedBundleWarning();
520+
if (!warning || bundleImportBusy()) return;
521+
setUntrustedBundleWarning(null);
522+
setBundleImportError(null);
523+
options.setError(null);
524+
525+
try {
526+
setBundleImportBusy(true);
527+
await processBundleRequest(warning.request, { allowUntrustedClientFetch: true });
528+
} catch (error) {
529+
const message = error instanceof Error ? error.message : safeStringify(error);
530+
const friendly = addOpencodeCacheHint(message);
531+
options.setError(friendly);
532+
} finally {
533+
setBundleImportBusy(false);
534+
}
535+
};
536+
476537
const openTeamBundle = async (input: {
477538
templateId?: string;
478539
name: string;
@@ -805,6 +866,8 @@ export function createBundlesStore(options: {
805866
openRemoteConnectFromSkillDestination,
806867
handleCreateWorkspaceConfirm,
807868
handleCreateSandboxConfirm,
869+
dismissUntrustedBundleWarning,
870+
confirmUntrustedBundleWarning,
808871
bundleImportChoice,
809872
bundleImportSummary,
810873
bundleWorkerOptions,
@@ -815,6 +878,7 @@ export function createBundlesStore(options: {
815878
bundleStartBusy,
816879
createWorkspaceRequest,
817880
createWorkspaceDefaultPreset,
881+
untrustedBundleWarning,
818882
skillDestinationRequest,
819883
skillDestinationWorkspaces,
820884
skillDestinationBusyId,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { DEFAULT_OPENWORK_PUBLISHER_BASE_URL } from "../lib/publisher";
2+
3+
export type BundleUrlTrust = {
4+
trusted: boolean;
5+
bundleId: string | null;
6+
actualOrigin: string | null;
7+
configuredOrigin: string | null;
8+
};
9+
10+
export function extractBundleId(url: URL): string | null {
11+
const segments = url.pathname.split("/").filter(Boolean);
12+
if (segments[0] === "b" && segments[1] && (segments.length === 2 || (segments.length === 3 && segments[2] === "data"))) {
13+
return segments[1];
14+
}
15+
return null;
16+
}
17+
18+
export function resolveConfiguredBundlePublisherOrigin(baseUrl = DEFAULT_OPENWORK_PUBLISHER_BASE_URL): string | null {
19+
try {
20+
return new URL(baseUrl).origin;
21+
} catch {
22+
return null;
23+
}
24+
}
25+
26+
export function describeBundleUrlTrust(bundleUrl: string, baseUrl = DEFAULT_OPENWORK_PUBLISHER_BASE_URL): BundleUrlTrust {
27+
const configuredOrigin = resolveConfiguredBundlePublisherOrigin(baseUrl);
28+
try {
29+
const url = new URL(bundleUrl);
30+
const bundleId = extractBundleId(url);
31+
return {
32+
trusted: Boolean(configuredOrigin && url.origin === configuredOrigin && bundleId),
33+
bundleId,
34+
actualOrigin: url.origin,
35+
configuredOrigin,
36+
};
37+
} catch {
38+
return {
39+
trusted: false,
40+
bundleId: null,
41+
actualOrigin: null,
42+
configuredOrigin,
43+
};
44+
}
45+
}
46+
47+
export function isConfiguredBundlePublisherUrl(bundleUrl: string, baseUrl = DEFAULT_OPENWORK_PUBLISHER_BASE_URL): boolean {
48+
return describeBundleUrlTrust(bundleUrl, baseUrl).trusted;
49+
}

‎apps/app/src/app/lib/openwork-server.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
10431043
timeoutMs: timeouts.workspaceImport,
10441044
},
10451045
),
1046-
publishBundle: (payload: unknown, bundleType: "skill" | "workspace-profile" | "skills-set", options?: { name?: string; baseUrl?: string | null; timeoutMs?: number }) =>
1046+
publishBundle: (payload: unknown, bundleType: "skill" | "workspace-profile" | "skills-set", options?: { name?: string; timeoutMs?: number }) =>
10471047
requestJson<{ url: string }>(baseUrl, "/share/bundles/publish", {
10481048
token,
10491049
hostToken,
@@ -1052,7 +1052,6 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
10521052
payload,
10531053
bundleType,
10541054
name: options?.name,
1055-
baseUrl: options?.baseUrl ?? undefined,
10561055
timeoutMs: options?.timeoutMs,
10571056
},
10581057
timeoutMs: options?.timeoutMs ?? timeouts.shareBundle,

0 commit comments

Comments
 (0)