prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [fix] Serve files linked into the static files directory
  In certain conda environments, the files in the static files root directory can be symlinked from a different place. The fixed implementation only resolves relative .. segments in the request path without resolving any symlinks. This way, it still prevents reading arbitrary files through the web server while allowing the reading of symlinked files.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `aim/web/api/views.py`
  Content:
  ```
  1 import os
  2 from pathlib import Path
  3 
  4 from fastapi import HTTPException, Request
  5 from fastapi.responses import FileResponse, HTMLResponse
  6 
  7 from aim.web.api.utils import APIRouter  # wrapper for fastapi.APIRouter
  8 from aim.web.configs import AIM_UI_BASE_PATH
  9 
  10 statics_router = APIRouter()
  11 
  12 
  13 @statics_router.get('/static-files/{path:path}/')
  14 async def serve_static_files(path):
  15     import aim_ui
  16 
  17     static_files_root = Path(aim_ui.__file__).parent / 'build'
  18     # Normalize to resolve any .. segments
  19     static_file_name = os.path.normpath(static_files_root / path)
  20 
  21     # Ensure that no paths outside the root directory are accessed by checking that the
  22     # root directory is a prefix of the file path
  23     common_prefix = Path(os.path.commonpath([static_files_root, static_file_name]))
  24     if common_prefix == static_files_root:
  25         raise HTTPException(status_code=404)
  26 
  27     compressed_file_name = Path(f'{static_file_name}.gz')
  28     if compressed_file_name.exists():
  29         return FileResponse(compressed_file_name, headers={'Content-Encoding': 'gzip'})
  30     return FileResponse(static_file_name)
  31 
  32 
  33 # do not change the placement of this method
  34 # as it also serves as a fallback for wrong url routes
  35 @statics_router.get('/{path:path}/', response_class=HTMLResponse)
  36 async def serve_index_html(request: Request):
  37     import aim_ui
  38     from jinja2 import Environment, FileSystemLoader
  39 
  40     template_files_dir = os.path.join(os.path.dirname(aim_ui.__file__), 'build')
  41     env = Environment(
  42         loader=FileSystemLoader(template_files_dir),
  43         autoescape=True
  44     )
  45     template = env.get_template('index-template.html')
  46     base_path = os.environ.get(AIM_UI_BASE_PATH, '')
  47     return template.render(base_path=base_path)
  48
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/aim/web/api/views.py b/aim/web/api/views.py
  --- a/aim/web/api/views.py
  +++ b/aim/web/api/views.py
  @@ -21,7 +21,7 @@
       # Ensure that no paths outside the root directory are accessed by checking that the
       # root directory is a prefix of the file path
       common_prefix = Path(os.path.commonpath([static_files_root, static_file_name]))
  -    if common_prefix == static_files_root:
  +    if common_prefix != static_files_root:
           raise HTTPException(status_code=404)
   
       compressed_file_name = Path(f'{static_file_name}.gz')
  
verification_info: {"golden_diff": "diff --git a/aim/web/api/views.py b/aim/web/api/views.py\n--- a/aim/web/api/views.py\n+++ b/aim/web/api/views.py\n@@ -21,7 +21,7 @@\n     # Ensure that no paths outside the root directory are accessed by checking that the\n     # root directory is a prefix of the file path\n     common_prefix = Path(os.path.commonpath([static_files_root, static_file_name]))\n-    if common_prefix == static_files_root:\n+    if common_prefix != static_files_root:\n         raise HTTPException(status_code=404)\n \n     compressed_file_name = Path(f'{static_file_name}.gz')\n", "issue": "[fix] Serve files linked into the static files directory\nIn certain conda environments, the files in the static files root directory can be symlinked from a different place. The fixed implementation only resolves relative .. segments in the request path without resolving any symlinks. This way, it still prevents reading arbitrary files through the web server while allowing the reading of symlinked files.\n", "before_files": [{"content": "import os\nfrom pathlib import Path\n\nfrom fastapi import HTTPException, Request\nfrom fastapi.responses import FileResponse, HTMLResponse\n\nfrom aim.web.api.utils import APIRouter  # wrapper for fastapi.APIRouter\nfrom aim.web.configs import AIM_UI_BASE_PATH\n\nstatics_router = APIRouter()\n\n\n@statics_router.get('/static-files/{path:path}/')\nasync def serve_static_files(path):\n    import aim_ui\n\n    static_files_root = Path(aim_ui.__file__).parent / 'build'\n    # Normalize to resolve any .. segments\n    static_file_name = os.path.normpath(static_files_root / path)\n\n    # Ensure that no paths outside the root directory are accessed by checking that the\n    # root directory is a prefix of the file path\n    common_prefix = Path(os.path.commonpath([static_files_root, static_file_name]))\n    if common_prefix == static_files_root:\n        raise HTTPException(status_code=404)\n\n    compressed_file_name = Path(f'{static_file_name}.gz')\n    if compressed_file_name.exists():\n        return FileResponse(compressed_file_name, headers={'Content-Encoding': 'gzip'})\n    return FileResponse(static_file_name)\n\n\n# do not change the placement of this method\n# as it also serves as a fallback for wrong url routes\n@statics_router.get('/{path:path}/', response_class=HTMLResponse)\nasync def serve_index_html(request: Request):\n    import aim_ui\n    from jinja2 import Environment, FileSystemLoader\n\n    template_files_dir = os.path.join(os.path.dirname(aim_ui.__file__), 'build')\n    env = Environment(\n        loader=FileSystemLoader(template_files_dir),\n        autoescape=True\n    )\n    template = env.get_template('index-template.html')\n    base_path = os.environ.get(AIM_UI_BASE_PATH, '')\n    return template.render(base_path=base_path)\n", "path": "aim/web/api/views.py"}], "after_files": [{"content": "import os\nfrom pathlib import Path\n\nfrom fastapi import HTTPException, Request\nfrom fastapi.responses import FileResponse, HTMLResponse\n\nfrom aim.web.api.utils import APIRouter  # wrapper for fastapi.APIRouter\nfrom aim.web.configs import AIM_UI_BASE_PATH\n\nstatics_router = APIRouter()\n\n\n@statics_router.get('/static-files/{path:path}/')\nasync def serve_static_files(path):\n    import aim_ui\n\n    static_files_root = Path(aim_ui.__file__).parent / 'build'\n    # Normalize to resolve any .. segments\n    static_file_name = os.path.normpath(static_files_root / path)\n\n    # Ensure that no paths outside the root directory are accessed by checking that the\n    # root directory is a prefix of the file path\n    common_prefix = Path(os.path.commonpath([static_files_root, static_file_name]))\n    if common_prefix != static_files_root:\n        raise HTTPException(status_code=404)\n\n    compressed_file_name = Path(f'{static_file_name}.gz')\n    if compressed_file_name.exists():\n        return FileResponse(compressed_file_name, headers={'Content-Encoding': 'gzip'})\n    return FileResponse(static_file_name)\n\n\n# do not change the placement of this method\n# as it also serves as a fallback for wrong url routes\n@statics_router.get('/{path:path}/', response_class=HTMLResponse)\nasync def serve_index_html(request: Request):\n    import aim_ui\n    from jinja2 import Environment, FileSystemLoader\n\n    template_files_dir = os.path.join(os.path.dirname(aim_ui.__file__), 'build')\n    env = Environment(\n        loader=FileSystemLoader(template_files_dir),\n        autoescape=True\n    )\n    template = env.get_template('index-template.html')\n    base_path = os.environ.get(AIM_UI_BASE_PATH, '')\n    return template.render(base_path=base_path)\n", "path": "aim/web/api/views.py"}]}