@@ -8,6 +8,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
88
99const RENDERER_DIR = path . resolve ( __dirname , ".." , "renderer" ) ;
1010const DESIGN_RENDERER_DIR = path . join ( RENDERER_DIR , "design-system" ) ;
11+ const ASSETS_RENDERER_DIR = path . join ( RENDERER_DIR , "assets" ) ;
1112const DESIGN_RENDERER_URL = "app://renderer/design-system/index.html" ;
1213const APP_PROTOCOL = "app" ;
1314const EXTERNAL_LINK_HOSTS = new Set ( [
@@ -89,11 +90,12 @@ function serveAppProtocolAsset(request: Request): Response {
8990 return new Response ( "Bad request" , { status : 400 } ) ;
9091 }
9192
92- if (
93- ! decodedPathname . startsWith ( "/design-system/" ) ||
94- decodedPathname . includes ( "\0" ) ||
95- decodedPathname . includes ( "\\" )
96- ) {
93+ if ( decodedPathname . includes ( "\0" ) || decodedPathname . includes ( "\\" ) ) {
94+ return new Response ( "Not found" , { status : 404 } ) ;
95+ }
96+
97+ const assetRoot = resolveAppProtocolRoot ( decodedPathname ) ;
98+ if ( ! assetRoot ) {
9799 return new Response ( "Not found" , { status : 404 } ) ;
98100 }
99101
@@ -104,7 +106,7 @@ function serveAppProtocolAsset(request: Request): Response {
104106 }
105107
106108 const filePath = path . resolve ( RENDERER_DIR , relativePath ) ;
107- if ( ! isPathInside ( filePath , DESIGN_RENDERER_DIR ) ) {
109+ if ( ! isPathInside ( filePath , assetRoot ) ) {
108110 return new Response ( "Forbidden" , { status : 403 } ) ;
109111 }
110112
@@ -120,7 +122,7 @@ function serveAppProtocolAsset(request: Request): Response {
120122 let realRoot : string ;
121123 let realFile : string ;
122124 try {
123- realRoot = realpathSync ( DESIGN_RENDERER_DIR ) ;
125+ realRoot = realpathSync ( assetRoot ) ;
124126 realFile = realpathSync ( filePath ) ;
125127 if ( ! statSync ( realFile ) . isFile ( ) || ! isPathInside ( realFile , realRoot ) ) {
126128 return new Response ( "Forbidden" , { status : 403 } ) ;
@@ -136,6 +138,16 @@ function serveAppProtocolAsset(request: Request): Response {
136138 } ) ;
137139}
138140
141+ function resolveAppProtocolRoot ( pathname : string ) : string | null {
142+ if ( pathname . startsWith ( "/design-system/" ) ) {
143+ return DESIGN_RENDERER_DIR ;
144+ }
145+ if ( pathname . startsWith ( "/assets/" ) ) {
146+ return ASSETS_RENDERER_DIR ;
147+ }
148+ return null ;
149+ }
150+
139151export class DesktopWindow {
140152 private browserWindow : BrowserWindow | null = null ;
141153 private disposing = false ;
0 commit comments