Skip to content

Commit 3a9d853

Browse files
fix: prevent backward relative paths in readme (#2354)
Co-authored-by: Cary Hawkins <[email protected]>
1 parent c4dc4f8 commit 3a9d853

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • backend/src/hatchling/metadata

‎backend/src/hatchling/metadata/core.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ def readme(self) -> str:
528528
raise TypeError(message)
529529

530530
readme_path = os.path.normpath(os.path.join(self.root, readme))
531+
if os.path.isabs(readme) or os.path.relpath(readme_path, self.root).startswith(".."):
532+
message = f"Readme path must be within the project directory: {readme}"
533+
raise ValueError(message)
531534
if not os.path.isfile(readme_path):
532535
message = f"Readme file does not exist: {readme}"
533536
raise OSError(message)
@@ -565,6 +568,9 @@ def readme(self) -> str:
565568
raise TypeError(message)
566569

567570
path = os.path.normpath(os.path.join(self.root, relative_path))
571+
if os.path.isabs(relative_path) or os.path.relpath(path, self.root).startswith(".."):
572+
message = f"Readme path must be within the project directory: {relative_path}"
573+
raise ValueError(message)
568574
if not os.path.isfile(path):
569575
message = f"Readme file does not exist: {relative_path}"
570576
raise OSError(message)

0 commit comments

Comments
 (0)