-
Notifications
You must be signed in to change notification settings - Fork 249
CLDSRV-744: add missing md5 checksum checks tests #5941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bert-e
merged 3 commits into
development/9.0
from
feature/CLDSRV-744-check-content-md5-2
Sep 24, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,5 +142,8 @@ | |
}, | ||
"kmip": { | ||
"providerName": "thales" | ||
}, | ||
"integrityChecks": { | ||
"objectPutRetention": true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const crypto = require('crypto'); | ||
const { errors: ArsenalErrors } = require('arsenal'); | ||
const { config } = require('../../../Config'); | ||
|
||
const ChecksumError = Object.freeze({ | ||
MD5Mismatch: 'MD5Mismatch', | ||
MissingChecksum: 'MissingChecksum', | ||
}); | ||
|
||
/** | ||
* validateChecksumsNoChunking - Validate the checksums of a request. | ||
* @param {object} headers - http headers | ||
* @param {Buffer} body - http request body | ||
* @return {object} - error | ||
*/ | ||
function validateChecksumsNoChunking(headers, body) { | ||
if (headers && 'content-md5' in headers) { | ||
const md5 = crypto.createHash('md5').update(body).digest('base64'); | ||
if (md5 !== headers['content-md5']) { | ||
return { error: ChecksumError.MD5Mismatch, details: { calculated: md5, expected: headers['content-md5'] } }; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
return { error: ChecksumError.MissingChecksum, details: null }; | ||
} | ||
|
||
function defaultValidationFunc(request, body, log) { | ||
const err = validateChecksumsNoChunking(request.headers, body); | ||
if (err && err.error !== ChecksumError.MissingChecksum) { | ||
log.debug('failed checksum validation', { method: request.apiMethod }, err); | ||
return ArsenalErrors.BadDigest; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
const methodValidationFunc = Object.freeze({ | ||
'bucketPutACL': defaultValidationFunc, | ||
'bucketPutCors': defaultValidationFunc, | ||
'bucketPutEncryption': defaultValidationFunc, | ||
'bucketPutLifecycle': defaultValidationFunc, | ||
'bucketPutNotification': defaultValidationFunc, | ||
'bucketPutObjectLock': defaultValidationFunc, | ||
'bucketPutPolicy': defaultValidationFunc, | ||
'bucketPutReplication': defaultValidationFunc, | ||
'bucketPutVersioning': defaultValidationFunc, | ||
'bucketPutWebsite': defaultValidationFunc, | ||
// TODO: DeleteObjects requires a checksum. Should return an error if ChecksumError.MissingChecksum. | ||
'multiObjectDelete': defaultValidationFunc, | ||
'objectPutACL': defaultValidationFunc, | ||
'objectPutLegalHold': defaultValidationFunc, | ||
'objectPutTagging': defaultValidationFunc, | ||
'objectPutRetention': defaultValidationFunc, | ||
}); | ||
|
||
/** | ||
* validateMethodChecksumsNoChunking - Validate the checksums of a request. | ||
* @param {object} request - http request | ||
* @param {Buffer} body - http request body | ||
* @param {object} log - logger | ||
* @return {object} - error | ||
*/ | ||
function validateMethodChecksumNoChunking(request, body, log) { | ||
if (config.integrityChecks[request.apiMethod]) { | ||
const validationFunc = methodValidationFunc[request.apiMethod]; | ||
if (!validationFunc) { | ||
return null; | ||
} | ||
|
||
return validationFunc(request, body, log); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
module.exports = { | ||
ChecksumError, | ||
validateChecksumsNoChunking, | ||
validateMethodChecksumNoChunking, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently do nothing of this object, when we handle errors. Should we just return the error and add a log in this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the caller should do the logging.
In the next iteration I will add
SHA256Mismatch
,CRC32Mismatch
, etc. I don't see why we would want to squash all the possible errors intoBadDigest