Skip to content

Commit 16e6daa

Browse files
committed
fix(config): fix path traversal detection for windows compatibility (python-semantic-release#1014)
The original implementation of the path traversal detection expected that `resolve()` works the same on windows as it does with Linux/Mac. Windows requires the folder paths to exist to be resolved and that is not the case when the `template_dir` is not being used. Resolves: python-semantic-release#994
1 parent dadf0cd commit 16e6daa

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

semantic_release/cli/config.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,25 @@ def from_raw_config( # noqa: C901
568568
)
569569

570570
# changelog_file
571-
changelog_file = Path(raw.changelog.changelog_file).expanduser().resolve()
571+
# Must use absolute after resolve because windows does not resolve if the path does not exist
572+
# which means it returns a relative path. So we force absolute to ensure path is complete
573+
# for the next check of path matching
574+
changelog_file = (
575+
Path(raw.changelog.changelog_file).expanduser().resolve().absolute()
576+
)
572577

573578
# Prevent path traversal attacks
574579
if raw.repo_dir not in changelog_file.parents:
575580
raise InvalidConfiguration(
576581
"Changelog file destination must be inside of the repository directory."
577582
)
578583

579-
template_dir = Path(raw.changelog.template_dir).expanduser().resolve()
584+
# Must use absolute after resolve because windows does not resolve if the path does not exist
585+
# which means it returns a relative path. So we force absolute to ensure path is complete
586+
# for the next check of path matching
587+
template_dir = (
588+
Path(raw.changelog.template_dir).expanduser().resolve().absolute()
589+
)
580590

581591
# Prevent path traversal attacks
582592
if raw.repo_dir not in template_dir.parents:

0 commit comments

Comments
 (0)