Skip to content

Conversation

owen-mc
Copy link
Contributor

@owen-mc owen-mc commented Oct 8, 2025

Currently it focusses too much on the risk of data being decrypted, and doesn't explain why using weak algorithms can be a problem in other contexts.

Note that many of these queries would only alert for encryption algorithms, so the current text makes sense for them. But java/potentially-weak-cryptographic-algorithm, which shares the same help text as java/weak-cryptographic-algorithm, alerts for more algorithms, and so does js/weak-cryptographic-algorithm. It seems good to update all the qhelp files at once.

Previously it focussed too much on the risk of data being decrypted,
and didn't explain why using weak algorithms is a problem in other
contexts.
@Copilot Copilot AI review requested due to automatic review settings October 8, 2025 13:23
@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Oct 8, 2025
@owen-mc owen-mc requested review from a team as code owners October 8, 2025 13:23
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the qhelp documentation for broken cryptographic algorithm queries across multiple programming languages to provide a more comprehensive explanation of the security risks beyond just data decryption.

  • Updates the overview text to explain that weak cryptographic algorithms may compromise confidentiality, integrity, and authenticity
  • Adds specific examples of risks for encryption, hashing, and digital signature algorithms
  • Standardizes the documentation across Rust, Ruby, Python, JavaScript, Java, and C++ implementations

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rust/ql/src/queries/security/CWE-327/BrokenCryptoAlgorithm.qhelp Enhanced overview with broader security context and specific risk examples
ruby/ql/src/queries/security/cwe-327/BrokenCryptoAlgorithm.qhelp Updated documentation with comprehensive security risk explanations
python/ql/src/Security/CWE-327/BrokenCryptoAlgorithm.qhelp Improved overview text with detailed risk scenarios
javascript/ql/src/Security/CWE-327/BrokenCryptoAlgorithm.qhelp Enhanced documentation with broader security risk context
java/ql/src/Security/CWE/CWE-327/BrokenCryptoAlgorithm.qhelp Updated overview with comprehensive security guarantees explanation
cpp/ql/src/Security/CWE/CWE-327/BrokenCryptoAlgorithm.qhelp Enhanced documentation with detailed security risk examples

@github-actions github-actions bot added Ruby Rust Pull requests that update Rust code labels Oct 8, 2025
Copy link
Contributor

github-actions bot commented Oct 8, 2025

QHelp previews:

cpp/ql/src/Security/CWE/CWE-327/BrokenCryptoAlgorithm.qhelp

Use of a broken or risky cryptographic algorithm

Using broken or weak cryptographic algorithms may compromise security guarantees such as confidentiality, integrity, and authenticity.

Many cryptographic algorithms are known to be weak or flawed. The security guarantees of a system often rely on the underlying cryptography, so using a weak algorithm can have severe consequences. For example:

  • If a weak encryption algorithm is used, an attacker may be able to decrypt sensitive data.
  • If a weak hashing algorithm is used to protect data integrity, an attacker may be able to craft a malicious input that has the same hash as a benign one.
  • If a weak algorithm is used for digital signatures, an attacker may be able to forge signatures and impersonate legitimate users.

Recommendation

Ensure that you use a strong, modern cryptographic algorithm. Use at least AES-128 or RSA-2048.

Example

The following code shows an example of using the advapi windows API to decrypt some data. When creating a key, you must specify which algorithm to use. The first example uses DES which is an older algorithm that is now considered weak. The second example uses AES, which is a strong modern algorithm.

void advapi() {
  HCRYPTPROV hCryptProv;
  HCRYPTKEY hKey;
  HCRYPTHASH hHash;
  // other preparation goes here

  // BAD: use 3DES for key
  CryptDeriveKey(hCryptProv, CALG_3DES, hHash, 0, &hKey);

  // GOOD: use AES
  CryptDeriveKey(hCryptProv, CALG_AES_256, hHash, 0, &hKey);
}

References

java/ql/src/Security/CWE/CWE-327/BrokenCryptoAlgorithm.qhelp

Use of a broken or risky cryptographic algorithm

Using broken or weak cryptographic algorithms may compromise security guarantees such as confidentiality, integrity, and authenticity.

Many cryptographic algorithms are known to be weak or flawed. The security guarantees of a system often rely on the underlying cryptography, so using a weak algorithm can have severe consequences. For example:

  • If a weak encryption algorithm is used, an attacker may be able to decrypt sensitive data.
  • If a weak hashing algorithm is used to protect data integrity, an attacker may be able to craft a malicious input that has the same hash as a benign one.
  • If a weak algorithm is used for digital signatures, an attacker may be able to forge signatures and impersonate legitimate users.

Recommendation

Ensure that you use a strong, modern cryptographic algorithm. Use at least AES-128 or RSA-2048. Do not use the ECB encryption mode since it is vulnerable to replay and other attacks.

Example

The following code shows an example of using a java Cipher to encrypt some data. When creating a Cipher instance, you must specify the encryption algorithm to use. The first example uses DES, which is an older algorithm that is now considered weak. The second example uses AES, which is a strong modern algorithm.

// BAD: DES is a weak algorithm 
Cipher des = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);

byte[] encrypted = cipher.doFinal(input.getBytes("UTF-8"));

// ...

// GOOD: AES is a strong algorithm
Cipher aes = Cipher.getInstance("AES");

// ...

References

javascript/ql/src/Security/CWE-327/BrokenCryptoAlgorithm.qhelp

Use of a broken or weak cryptographic algorithm

Using broken or weak cryptographic algorithms may compromise security guarantees such as confidentiality, integrity, and authenticity.

Many cryptographic algorithms are known to be weak or flawed. The security guarantees of a system often rely on the underlying cryptography, so using a weak algorithm can have severe consequences. For example:

  • If a weak encryption algorithm is used, an attacker may be able to decrypt sensitive data.
  • If a weak hashing algorithm is used to protect data integrity, an attacker may be able to craft a malicious input that has the same hash as a benign one.
  • If a weak algorithm is used for digital signatures, an attacker may be able to forge signatures and impersonate legitimate users.

Recommendation

Ensure that you use a strong, modern cryptographic algorithm. Use at least AES-128 or RSA-2048 for encryption, and SHA-2 or SHA-3 for secure hashing.

Example

The following code shows an example of using the builtin cryptographic library of NodeJS to encrypt some secret data. When creating a Cipher instance to encrypt the secret data with, you must specify the encryption algorithm to use. The first example uses DES, which is an older algorithm that is now considered weak. The second example uses AES, which is a strong modern algorithm.

const crypto = require('crypto');

var secretText = obj.getSecretText();

const desCipher = crypto.createCipher('des', key);
let desEncrypted = desCipher.write(secretText, 'utf8', 'hex'); // BAD: weak encryption

const aesCipher = crypto.createCipher('aes-128', key);
let aesEncrypted = aesCipher.update(secretText, 'utf8', 'hex'); // GOOD: strong encryption

References

python/ql/src/Security/CWE-327/BrokenCryptoAlgorithm.qhelp

Use of a broken or weak cryptographic algorithm

Using broken or weak cryptographic algorithms may compromise security guarantees such as confidentiality, integrity, and authenticity.

Many cryptographic algorithms are known to be weak or flawed. The security guarantees of a system often rely on the underlying cryptography, so using a weak algorithm can have severe consequences. For example:

  • If a weak encryption algorithm is used, an attacker may be able to decrypt sensitive data.
  • If a weak algorithm is used for digital signatures, an attacker may be able to forge signatures and impersonate legitimate users.
    This query alerts on any use of a weak cryptographic algorithm that is not a hashing algorithm. Use of broken or weak cryptographic hash functions are handled by the py/weak-sensitive-data-hashing query.

Recommendation

Ensure that you use a strong, modern cryptographic algorithm, such as AES-128 or RSA-2048.

Example

The following code uses the pycryptodome library to encrypt some secret data. When you create a cipher using pycryptodome you must specify the encryption algorithm to use. The first example uses DES, which is an older algorithm that is now considered weak. The second example uses AES, which is a stronger modern algorithm.

from Crypto.Cipher import DES, AES

cipher = DES.new(SECRET_KEY)

def send_encrypted(channel, message):
    channel.send(cipher.encrypt(message)) # BAD: weak encryption


cipher = AES.new(SECRET_KEY)

def send_encrypted(channel, message):
    channel.send(cipher.encrypt(message)) # GOOD: strong encryption

NOTICE: the original [pycrypto](https://pypi.org/project/pycrypto/) PyPI package that provided the Crypto module is not longer actively maintained, so you should use the [pycryptodome](https://pypi.org/project/pycryptodome/) PyPI package instead (which has a compatible API).

References

ruby/ql/src/queries/security/cwe-327/BrokenCryptoAlgorithm.qhelp

Use of a broken or weak cryptographic algorithm

Using broken or weak cryptographic algorithms may compromise security guarantees such as confidentiality, integrity, and authenticity.

Many cryptographic algorithms are known to be weak or flawed. The security guarantees of a system often rely on the underlying cryptography, so using a weak algorithm can have severe consequences. For example:

  • If a weak encryption algorithm is used, an attacker may be able to decrypt sensitive data.
  • If a weak algorithm is used for digital signatures, an attacker may be able to forge signatures and impersonate legitimate users.
    This query alerts on any use of a weak cryptographic algorithm that is not a hashing algorithm. Use of broken or weak cryptographic hash functions are handled by the rb/weak-sensitive-data-hashing query.

Recommendation

Ensure that you use a strong, modern cryptographic algorithm, such as AES-128 or RSA-2048.

Example

The following code uses the OpenSSL library to encrypt some secret data. When you create a cipher using OpenSSL you must specify the encryption algorithm to use. The first example uses DES, which is an older algorithm that is now considered weak. The second example uses AES, which is a stronger modern algorithm.

require 'openssl'

class Encryptor
  attr_accessor :secret_key

  def encrypt_message_weak(message)
    cipher = OpenSSL::Cipher.new('des') # BAD: weak encryption
    cipher.encrypt
    cipher.key = secret_key
    cipher.update(message)
    cipher.final
  end

  def encrypt_message_strong(message)
    cipher = OpenSSL::Cipher::AES128.new # GOOD: strong encryption
    cipher.encrypt
    cipher.key = secret_key
    cipher.update(message)
    cipher.final
  end
end

References

rust/ql/src/queries/security/CWE-327/BrokenCryptoAlgorithm.qhelp

Use of a broken or weak cryptographic algorithm

Using broken or weak cryptographic algorithms may compromise security guarantees such as confidentiality, integrity, and authenticity.

Many cryptographic algorithms are known to be weak or flawed. The security guarantees of a system often rely on the underlying cryptography, so using a weak algorithm can have severe consequences. For example:

  • If a weak encryption algorithm is used, an attacker may be able to decrypt sensitive data.
  • If a weak algorithm is used for digital signatures, an attacker may be able to forge signatures and impersonate legitimate users.
    This query alerts on any use of a weak cryptographic algorithm that is not a hashing algorithm. Use of broken or weak cryptographic hash functions are handled by the rust/weak-sensitive-data-hashing query.

Recommendation

Ensure that you use a strong, modern cryptographic algorithm, such as AES-128 or RSA-2048.

Example

The following code uses the des crate from the RustCrypto family to encrypt some secret data. The DES algorithm is old and considered very weak.

let des_cipher = cbc::Encryptor::<des::Des>::new(key.into(), iv.into()); // BAD: weak encryption
let encryption_result = des_cipher.encrypt_padded_mut::<des::cipher::block_padding::Pkcs7>(data, data_len);

Instead, we should use a strong modern algorithm. In this case, we have selected the 256-bit version of the AES algorithm.

let aes_cipher = cbc::Encryptor::<aes::Aes256>::new(key.into(), iv.into()); // GOOD: strong encryption
let encryption_result = aes_cipher.encrypt_padded_mut::<aes::cipher::block_padding::Pkcs7>(data, data_len);

References

@aibaars
Copy link
Contributor

aibaars commented Oct 8, 2025

That's a nice improvement! Would it be useful/possible to extract the common text in a shared snippet that is imported in the various qhelp files?

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C/C++ 👍

Rust 👍 - personally I would delete the bullet point about weak hashing from this file, but I'm also OK with this being merged as is (after a docs review that is) --- update: it's deleted now :)

@owen-mc
Copy link
Contributor Author

owen-mc commented Oct 9, 2025

@aibaars My only issue with that is where it should go. A new shared library with things related to (security) queries? I guess we will want one at some point, if we implement concepts further. Or in the shared concepts library, by the crypto information? I was about to say that most of the languages already depend on that, but I see that it's the library qlpacks that depend on it, and we would be adding this dependency to the source qlpacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ documentation Java JS no-change-note-required This PR does not need a change note Python Ruby Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants