Fix - [CodeQL:Warning]: SM04514: Weak hashes (in make-util.js) - AB#2236221 #20728
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.
Context
Change Description
This PR Addresses the CodeQL warning of using a weak Hash algorithm in make-util.js by replacing the MD5 algorithm with the SHA256 algorithm as per the recommendation - [SM04514] Weak hashes.
Considerations
The length of
targetPath
will increase proportionally with the hash output length.Most modern filesystems (e.g., NTFS, ext4) support filenames up to 255 characters and full paths up to ~32,000 characters. However, if our Agent runs in environments with stricter limits, this could be a concern.
Change Validation
Created a simple NodeJS project and tested the
downloadArchiveAsync
function with MD5 and SHA algorithms -javascript-project-crypto.zip
Test URL: https://download.visualstudio.microsoft.com/download/pr/cfecd946-5932-496c-a2b6-ba3c99318f24/4a5b2d8e244b4db3db110ff5751ed35b/dotnet-runtime-9.0.0-win-arm64.zip
Archive name with MD5 - 043bc67c06ea458d7a44e4c4933cd918.completed
Archive name with SHA256- a7984e2162beebede2ad3973384753a3b354b6abf5b7c0c382e3012f8852f7c5.completed
Observation: Length of the name of the archive when using SHA256 hash is double when compared to the MD5 hash.
Task Name: NA
Documentation changes required: (Y/N) N
Added unit tests: (Y/N) N
Attached related issue: (Y/N) Y
Checklist:
Related Links