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.
Security Issue:
The LFS file upload API (
/info/lfs/:oid/:size
) does not validate whether the file's SHA256 matches the LFS object's OID.GitLab Handling Method:
GitLab’s LFS file upload process involves interactions between Rails and Go services, and the logic is quite complex. However, the following two PRs/issues provide insight into how they handle this:
Git LFS: Validate upload size and SHA256 in Rails Merge Request 85819
Object Store uses undocumented tmp/ for uploads Issue 416222
Their upload logic is as follows: First, the file is uploaded to a temporary directory. Once the SHA256 validation is successful, the file is copied to the actual directory.
Fix:
Adopting the same approach as GitLab:
lfs/tmp/{oid_key}
directory while performing SHA256 validation.lfs/tmp/{oid_key}
tolfs/{oid_key}
and the database is updated.lfs/tmp/{oid_key}
will be deleted.PR Details:
UploadAndValidate
method, which uploads the file while performing the validation.UploadAndValidate
method includes part size and concurrency restrictions to prevent excessive memory usage. The maximum memory used for a single upload is approximately 25MB (5 * 5). The default git lfs concurrency is 8, which means if you upload more than 8 files, the estimated memory used will be 8 * 25 = 200MB.LfsUpload
method in the GitHTTPComponent has been updated to useUploadAndValidate
.LfsUpload
method for checking file existence has been adjusted. Previously, any error fromStatObject
was considered as the file not existing. Now, only specific errors are checked.buildUploadLink
method in the GitHTTPComponent no longer checks file size and always returns the server's intermediate upload URL.