7676WAITING_DOT_NUMBER = 10
7777MAX_ITEMS = 100
7878PAGE_SIZE = 10
79+ _MAX_BUFFER_SIZE = 100 * 1024 * 1024 # 100 MB - Maximum buffer size for streaming iterators
80+
81+ _SENSITIVE_SYSTEM_PATHS = [
82+ abspath (os .path .expanduser ("~/.aws" )),
83+ abspath (os .path .expanduser ("~/.ssh" )),
84+ abspath (os .path .expanduser ("~/.kube" )),
85+ abspath (os .path .expanduser ("~/.docker" )),
86+ abspath (os .path .expanduser ("~/.config" )),
87+ abspath (os .path .expanduser ("~/.credentials" )),
88+ "/etc" ,
89+ "/root" ,
90+ "/home" ,
91+ "/var/lib" ,
92+ "/opt/ml/metadata" ,
93+ ]
7994
8095logger = logging .getLogger (__name__ )
8196
@@ -616,35 +631,17 @@ def _validate_source_directory(source_directory):
616631 # S3 paths and None are safe
617632 return
618633
619- abs_source = abspath (source_directory )
620-
621- # Blocklist of sensitive directories that should not be accessible
622- sensitive_paths = [
623- abspath (os .path .expanduser ("~/.aws" )),
624- abspath (os .path .expanduser ("~/.ssh" )),
625- abspath (os .path .expanduser ("~/.kube" )),
626- abspath (os .path .expanduser ("~/.docker" )),
627- abspath (os .path .expanduser ("~/.config" )),
628- abspath (os .path .expanduser ("~/.credentials" )),
629- "/etc" ,
630- "/root" ,
631- "/home" ,
632- "/var/lib" ,
633- "/opt/ml/metadata" ,
634- ]
634+ # Resolve symlinks to get the actual path
635+ abs_source = abspath (realpath (source_directory ))
635636
636637 # Check if the source path is under any sensitive directory
637- for sensitive_path in sensitive_paths :
638+ for sensitive_path in _SENSITIVE_SYSTEM_PATHS :
638639 if abs_source .startswith (sensitive_path ):
639640 raise ValueError (
640641 f"source_directory cannot access sensitive system paths. "
641642 f"Got: { source_directory } (resolved to { abs_source } )"
642643 )
643644
644- # Check for symlinks to prevent symlink-based escapes
645- if os .path .islink (abs_source ):
646- raise ValueError (f"source_directory cannot be a symlink: { source_directory } " )
647-
648645
649646def _validate_dependency_path (dependency ):
650647 """Validate that a dependency path is safe to use.
@@ -660,35 +657,17 @@ def _validate_dependency_path(dependency):
660657 if not dependency :
661658 return
662659
663- abs_dependency = abspath (dependency )
664-
665- # Blocklist of sensitive directories that should not be accessible
666- sensitive_paths = [
667- abspath (os .path .expanduser ("~/.aws" )),
668- abspath (os .path .expanduser ("~/.ssh" )),
669- abspath (os .path .expanduser ("~/.kube" )),
670- abspath (os .path .expanduser ("~/.docker" )),
671- abspath (os .path .expanduser ("~/.config" )),
672- abspath (os .path .expanduser ("~/.credentials" )),
673- "/etc" ,
674- "/root" ,
675- "/home" ,
676- "/var/lib" ,
677- "/opt/ml/metadata" ,
678- ]
660+ # Resolve symlinks to get the actual path
661+ abs_dependency = abspath (realpath (dependency ))
679662
680663 # Check if the dependency path is under any sensitive directory
681- for sensitive_path in sensitive_paths :
664+ for sensitive_path in _SENSITIVE_SYSTEM_PATHS :
682665 if abs_dependency .startswith (sensitive_path ):
683666 raise ValueError (
684667 f"dependency path cannot access sensitive system paths. "
685668 f"Got: { dependency } (resolved to { abs_dependency } )"
686669 )
687670
688- # Check for symlinks to prevent symlink-based escapes
689- if os .path .islink (abs_dependency ):
690- raise ValueError (f"dependency path cannot be a symlink: { dependency } " )
691-
692671
693672def _create_or_update_code_dir (
694673 model_dir , inference_script , source_directory , dependencies , sagemaker_session , tmp
0 commit comments