Skip to content

[java] InsecureCryptoIv false negative for later assignments #3803

@Zustin

Description

@Zustin

Affects PMD Version:6.42.0

Rule:InsecureCryptoIv

Link:
https://pmd.github.io/pmd-6.42.0/pmd_rules_java_security.html#insecurecryptoiv

Description:
Hi, I found a false negative when tried to use PMD to enhance code security. The minimal case is below. Our tool should report a warning at line 6, because secret key is originated from a constant string. This FN may lead to privacy information leakage.

Code Sample demonstrating the issue:

public void func(SecretKeySpec key) {
    try {
        byte[] ivBytes, ivs;
        ivs = "hardcoded initial vector".getBytes();
        final IvParameterSpec iv = new IvParameterSpec(ivs); // should report a warning about this line
        final Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
        // .......
    } catch (Exception e) {
        e.printStackTrace();
    }
}

However, the following case can be detected:

public void func(SecretKeySpec key) {
    try {
        byte[] ivBytes, ivs = "hardcoded initial vector".getBytes();  // can be detected
        final IvParameterSpec iv = new IvParameterSpec(ivs);
        final Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
        // .......
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Expected outcome: A warning

PMD should report a violation at line 4, but doesn't. This is a false-negative.

Running PMD through: [Maven]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions