@@ -20,6 +20,7 @@ import {
2020} from "./apply" ;
2121import { defaultPresetFromWorkspaceProfileBundle , describeBundleImport , parseBundlePayload } from "./schema" ;
2222import { fetchBundle , parseBundleDeepLink } from "./sources" ;
23+ import { describeBundleUrlTrust } from "./url-policy" ;
2324import 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+
4452export type BundlesStore = ReturnType < typeof createBundlesStore > ;
4553
4654export 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,
0 commit comments