11import os
22from aiohttp import web
33
4+ from ..utils import sub_abspath
5+
46THIS_DIR = os .path .dirname (os .path .abspath (__file__ ))
57DIR_WEB = os .path .abspath (f'{ THIS_DIR } /../../web/' )
68
@@ -23,18 +25,25 @@ def is_param_truthy(request, param):
2325
2426
2527def set_default_page_resources (path , routes ):
26- """ Sets up routes for handling static files under a path."""
28+ """Sets up routes for handling static files under a path."""
2729
2830 @routes .get (f'/rgthree/{ path } /{{file}}' )
2931 async def get_resource (request ):
30- """ Returns a resource file. """
31- return web .FileResponse (os .path .join (DIR_WEB , path , request .match_info ['file' ]))
32+ """Returns a resource file."""
33+ filepath = request .match_info ['file' ]
34+ abspath = sub_abspath (os .path .join (DIR_WEB , path ), filepath )
35+ if abspath is None :
36+ return web .HTTPNotFound ()
37+ return web .FileResponse (abspath )
3238
3339 @routes .get (f'/rgthree/{ path } /{{subdir}}/{{file}}' )
3440 async def get_resource_subdir (request ):
35- """ Returns a resource file. """
36- return web .FileResponse (
37- os .path .join (DIR_WEB , path , request .match_info ['subdir' ], request .match_info ['file' ]))
41+ """Returns a resource file."""
42+ filepath = os .path .join (request .match_info ['subdir' ], request .match_info ['file' ])
43+ abspath = sub_abspath (os .path .join (DIR_WEB , path ), filepath )
44+ if abspath is None :
45+ return web .HTTPNotFound ()
46+ return web .FileResponse (abspath )
3847
3948
4049def set_default_page_routes (path , routes ):
0 commit comments