Conversation
| const decipher = crypto.createDecipheriv( | ||
| 'aes-256-gcm', | ||
| key, | ||
| Buffer.from(ivHex, 'hex') | ||
| ); |
There was a problem hiding this comment.
Semgrep identified an issue in your code:
The call to 'createDecipheriv' with the Galois Counter Mode (GCM) mode of operation is missing an expected authentication tag length. If the expected authentication tag length is not specified or otherwise checked, the application might be tricked into verifying a shorter-than-expected authentication tag. This can be abused by an attacker to spoof ciphertexts or recover the implicit authentication key of GCM, allowing arbitrary forgeries.
To resolve this comment:
✨ Commit Assistant fix suggestion
| const decipher = crypto.createDecipheriv( | |
| 'aes-256-gcm', | |
| key, | |
| Buffer.from(ivHex, 'hex') | |
| ); | |
| const decipher = crypto.createDecipheriv( | |
| 'aes-256-gcm', | |
| key, | |
| Buffer.from(ivHex, 'hex'), | |
| { authTagLength: 16 } // Specify the expected authentication tag length in bytes | |
| ); |
View step-by-step instructions
- Pass an additional options object with the
authTagLengthproperty set to 16 as the fourth parameter tocrypto.createDecipheriv. For example:
const decipher = crypto.createDecipheriv('aes-256-gcm', key, Buffer.from(ivHex, 'hex'), { authTagLength: 16 }); - Make sure that the value for
authTagLengthmatches the length of the authentication tag you use when callingdecipher.setAuthTag.
In AES-GCM, a typical tag length is 16 bytes (128 bits). This helps prevent attackers from supplying shorter authentication tags when decrypting. - Review and update any other instances of
createDecipherivwith a GCM mode in your codebase to use theauthTagLengthoption as well.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by gcm-no-tag-length.
Questions about this issue? Reach out to Product Security in #prodsec-tools.
You can view more details about this finding in the Semgrep AppSec Platform.
No description provided.