Skip to content

Commit e494277

Browse files
steverepbdraco
andauthored
Fix response to circular symlinks with Python v3.13 (#8642)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent 0a88bab commit e494277

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGES/8565.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed server checks for circular symbolic links to be compatible with Python 3.13 -- by :user:`steverep`.

aiohttp/web_fileresponse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ async def prepare(self, request: "BaseRequest") -> Optional[AbstractStreamWriter
188188
file_path, st, file_encoding = await loop.run_in_executor(
189189
None, self._get_file_path_stat_encoding, accept_encoding
190190
)
191-
except FileNotFoundError:
191+
except OSError:
192+
# Most likely to be FileNotFoundError or OSError for circular
193+
# symlinks in python >= 3.13, so respond with 404.
192194
self.set_status(HTTPNotFound.status_code)
193195
return await super().prepare(request)
194196

aiohttp/web_urldispatcher.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
BaseDict = dict
7878

7979
CIRCULAR_SYMLINK_ERROR = (
80-
OSError
80+
(OSError,)
8181
if sys.version_info < (3, 10) and sys.platform.startswith("win32")
82-
else RuntimeError
82+
else (RuntimeError,) if sys.version_info < (3, 13) else ()
8383
)
8484

8585
YARL_VERSION: Final[Tuple[int, ...]] = tuple(map(int, yarl_version.split(".")[:2]))
@@ -672,8 +672,9 @@ def _resolve_path_to_response(self, unresolved_path: Path) -> StreamResponse:
672672
else:
673673
file_path = unresolved_path.resolve()
674674
file_path.relative_to(self._directory)
675-
except (ValueError, CIRCULAR_SYMLINK_ERROR) as error:
676-
# ValueError for relative check; RuntimeError for circular symlink.
675+
except (ValueError, *CIRCULAR_SYMLINK_ERROR) as error:
676+
# ValueError is raised for the relative check. Circular symlinks
677+
# raise here on resolving for python < 3.13.
677678
raise HTTPNotFound() from error
678679

679680
# if path is a directory, return the contents if permitted. Note the

0 commit comments

Comments
 (0)