Class WorkspaceArchiveExtractor
java.lang.Object
io.agentscope.harness.agent.sandbox.WorkspaceArchiveExtractor
Securely extracts tar archives into a target directory.
Applies strict path traversal guards before extracting each archive entry:
- Rejects entries with absolute paths (starting with
/or\) - Rejects entries containing
..path segments - Verifies the resolved destination path starts with the canonical root
These guards defend against the "Zip Slip" class of path traversal attacks.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidextractTarArchive(Path destRoot, InputStream tarStream) Extracts a tar archive stream into the given destination directory.
-
Method Details
-
extractTarArchive
Extracts a tar archive stream into the given destination directory.The destination directory must already exist. Existing files at the same paths will be replaced.
- Parameters:
destRoot- the directory to extract into; must already existtarStream- the tar archive input stream; caller is responsible for closing- Throws:
SandboxException.SandboxRuntimeException- if a path traversal attempt is detectedException- if extraction fails for any other reason
-