Skip to content

SonarQube: Weak Cryptography in generateRandomToken #61

Closed
@Uzlopak

Description

@Uzlopak

I am currently running node-oauth2-server through sonarqube.

I know this part of the code was touched in #38.

Sonarqube shows for generateRandomToken following Security Hotspot
Cryptographic hash algorithms such as MD2, MD4, MD5, MD6, HAVAL-128, HMAC-MD5, DSA (which uses SHA-1), RIPEMD, RIPEMD-128, RIPEMD-160, HMACRIPEMD160 and SHA-1 are no longer considered secure, because it is possible to have collisions (little computational effort is enough to find two or more different inputs that produce the same hash).

We actually just want to create a random token. So this finding is not a security issue anyway.

But when I read the code it makes for me no sense, why the output of randomBytes, which outputs a cryptographical secure random value should be hashed again with sha256. We could replace this by simply doing

  generateRandomToken: function() {
    return Promise.resolve(crypto.randomBytes(32).toString('hex'));
  }

and all tests would pass. SonarQube would also not remark this as potential security issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussion 🗨️Discussion about a particular topic.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions