Skip to content

Commit

Permalink
Add check for symlink in _safe_extract (#11611)
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishree <[email protected]>
  • Loading branch information
athitten authored and pablo-garay committed Dec 20, 2024
1 parent 5ec7a36 commit b1df3e4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nemo/core/connectors/save_restore_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,12 @@ def _is_safe_path(member, extract_to):
# Construct the full path where the member would be extracted
full_path = os.path.join(extract_to, member_path)
# Ensure the member would be extracted within the intended directory
return os.path.commonprefix([full_path, extract_to]) == extract_to
if os.path.commonprefix([full_path, extract_to]) != extract_to:
return False
# Check if the member is a symbolic link
if member.issym() or member.islnk():
return False
return True

@staticmethod
def _safe_extract(tar, out_folder: str, members=None):
Expand Down

0 comments on commit b1df3e4

Please sign in to comment.