Potential fix for code scanning alert no. 4: Arbitrary file access during archive extraction ("Zip Slip") #6909
+10
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#minor
Potential fix for https://github.com/microsoft/botbuilder-dotnet/security/code-scanning/4
The fix is to ensure that any file path derived from the archive is not able to escape the intended extraction directory. The standard mitigation is to combine the extraction root (
path) with the archive entry’s file name (as currently), then resolve this combined path to an absolute path (resolving traversals/links), and confirm it is still within the extraction root (also resolved to a canonical absolute path). If not, extraction should immediately abort with an exception. This must be done both for files and directory creation.Specifically, in
ExtractZipFolder:Path.Combine(path, entryName), usePath.GetFullPathon it.This change needs to be applied to both branches: directory creation (line 167) and file extraction (line 171).
No additional dependencies are needed, but care needs to be taken to only change the vulnerable region.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.