Skip to content

Commit 1f92213

Browse files
[PR #8642/e4942771 backport][3.10] Fix response to circular symlinks with Python v3.13 (#8648)
Co-authored-by: Steve Repsher <[email protected]>
1 parent 2ef14a6 commit 1f92213

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGES/8565.bugfix.rst

+1
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

+3-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ async def prepare(self, request: "BaseRequest") -> Optional[AbstractStreamWriter
191191
file_path, st, file_encoding = await loop.run_in_executor(
192192
None, self._get_file_path_stat_encoding, accept_encoding
193193
)
194-
except FileNotFoundError:
194+
except OSError:
195+
# Most likely to be FileNotFoundError or OSError for circular
196+
# symlinks in python >= 3.13, so respond with 404.
195197
self.set_status(HTTPNotFound.status_code)
196198
return await super().prepare(request)
197199

aiohttp/web_urldispatcher.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
BaseDict = dict
8181

8282
CIRCULAR_SYMLINK_ERROR = (
83-
OSError
83+
(OSError,)
8484
if sys.version_info < (3, 10) and sys.platform.startswith("win32")
85-
else RuntimeError
85+
else (RuntimeError,) if sys.version_info < (3, 13) else ()
8686
)
8787

8888
YARL_VERSION: Final[Tuple[int, ...]] = tuple(map(int, yarl_version.split(".")[:2]))
@@ -694,8 +694,9 @@ def _resolve_path_to_response(self, unresolved_path: Path) -> StreamResponse:
694694
else:
695695
file_path = unresolved_path.resolve()
696696
file_path.relative_to(self._directory)
697-
except (ValueError, CIRCULAR_SYMLINK_ERROR) as error:
698-
# ValueError for relative check; RuntimeError for circular symlink.
697+
except (ValueError, *CIRCULAR_SYMLINK_ERROR) as error:
698+
# ValueError is raised for the relative check. Circular symlinks
699+
# raise here on resolving for python < 3.13.
699700
raise HTTPNotFound() from error
700701

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

0 commit comments

Comments
 (0)