mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
Merge pull request #7021 from erik-krogh/cwe326
JS: Add insufficient key size query
This commit is contained in:
43
javascript/ql/src/Security/CWE-326/InsufficientKeySize.qhelp
Normal file
43
javascript/ql/src/Security/CWE-326/InsufficientKeySize.qhelp
Normal file
@@ -0,0 +1,43 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
<overview>
|
||||
<p>
|
||||
Modern encryption relies on it being computationally infeasible to break the cipher and decode a message without the key.
|
||||
As computational power increases, the ability to break ciphers grows and keys need to become larger.
|
||||
</p>
|
||||
</overview>
|
||||
|
||||
<recommendation>
|
||||
<p>
|
||||
An encryption key should be at least 2048-bit long when using RSA encryption, and 128-bit long when using
|
||||
symmetric encryption.
|
||||
</p>
|
||||
</recommendation>
|
||||
|
||||
<references>
|
||||
<li>
|
||||
Wikipedia:
|
||||
<a href="https://en.wikipedia.org/wiki/RSA_(cryptosystem)">RSA</a>.
|
||||
</li>
|
||||
<li>
|
||||
Wikipedia:
|
||||
<a href="https://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES</a>.
|
||||
</li>
|
||||
<li>
|
||||
NodeJS:
|
||||
<a href="https://nodejs.org/api/crypto.html">Crypto</a>.
|
||||
</li>
|
||||
<li>
|
||||
NIST:
|
||||
<a href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf">
|
||||
Recommendation for Transitioning the Use of Cryptographic Algorithms and Key Lengths</a>.
|
||||
</li>
|
||||
<li>
|
||||
Wikipedia:
|
||||
<a href="https://en.wikipedia.org/wiki/Key_size">Key size</a>
|
||||
</li>
|
||||
</references>
|
||||
</qhelp>
|
||||
36
javascript/ql/src/Security/CWE-326/InsufficientKeySize.ql
Normal file
36
javascript/ql/src/Security/CWE-326/InsufficientKeySize.ql
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @name Use of a weak cryptographic key
|
||||
* @description Using a weak cryptographic key can allow an attacker to compromise security.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @security-severity 7.5
|
||||
* @precision high
|
||||
* @id js/insufficient-key-size
|
||||
* @tags security
|
||||
* external/cwe/cwe-326
|
||||
*/
|
||||
|
||||
import javascript
|
||||
|
||||
from CryptographicKeyCreation key, int size, string msg, string algo
|
||||
where
|
||||
size = key.getSize() and
|
||||
(
|
||||
algo = key.getAlgorithm() + " "
|
||||
or
|
||||
not exists(key.getAlgorithm()) and algo = ""
|
||||
) and
|
||||
(
|
||||
size < 128 and
|
||||
key.isSymmetricKey() and
|
||||
msg =
|
||||
"Creation of an symmetric " + algo + "key uses " + size +
|
||||
" bits, which is below 128 and considered breakable."
|
||||
or
|
||||
size < 2048 and
|
||||
not key.isSymmetricKey() and
|
||||
msg =
|
||||
"Creation of an asymmetric " + algo + "key uses " + size +
|
||||
" bits, which is below 2048 and considered breakable."
|
||||
)
|
||||
select key, msg
|
||||
Reference in New Issue
Block a user