GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] HardcodedCryptoKey false negative with variable assignments · Issue #3368 · pmd/pmd

[java] HardcodedCryptoKey false negative with variable assignments #3368

New issue
Copy link
New issue
Copy link
Closed
#3544
Closed
[java] HardcodedCryptoKey false negative with variable assignments#3368
#3544
Copy link
Assignees
adangel
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
6.40.0

Description

@ghost
ghost
opened on Jun 29, 2021

Affects PMD Version: 6.35.0

Rule:HardcodedCryptoKey

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/pmd-6.35.0/pmd_rules_java_security.html#hardcodedcryptokey

Description:
PMD should have reported a warning to detect the bug at line 9 because when str is assigned by a string constant in the true branch, the program will exist a security flaw.

Code Sample demonstrating the issue:

public void testHardCodedCryptoKey(boolean tag) {       
   String str;
   if(tag) {
      str = "Hardcoded Crypto Key1";
   } else {
      str = "Hardcoded Crypto Key2";
   }
   SecretKeySpec secretKeySpec = new SecretKeySpec(str.getBytes(), "AES");  // should report a warning here
}

Expected outcome:

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

Running PMD through: [Maven]

Activity

  1. ghost added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Jun 29, 2021
  2. adangel commented on Jul 2, 2021

    @adangel
    adangel
    on Jul 2, 2021
    Member
    More actions

    I think, that's a real false-negative. The rule currently only checks the initializer of the variable. In your code sample, the variable str is not initialized at all, so the rule doesn't see a problem.

    We probably would need to enhance the rule to check all assignments to the variable as well...

  3. adangel
    changed the title [-][java] Improve HardcodedCryptoKey[/-] [+][java] HardcodedCryptoKey false negative with variable assignments[/+] on Jul 2, 2021
  4. adangel
    added this to the 6.40.0 milestone on Oct 7, 2021
  5. adangel
    self-assigned this
    on Oct 7, 2021
  6. adangel
    added a commit that references this issue on Oct 7, 2021

    [java] HardcodedCryptoKey false negative with variable assignments pm…

    701938d
  7. adangel
    added a commit that references this issue on Oct 29, 2021

    Merge pull request pmd#3544 from adangel:issue-3368-hardcoded-crypto-key

    9a07b81
  8. adangel
    closed this as completedin #3544on Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @adangel
    adangel

Labels

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

Type

No type

Projects

No projects

    Milestone

    • 6.40.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.