Skip to content

Random() is not secure because it provides insufficient entropy. CWE ID 331. #536

@tdhintz

Description

@tdhintz

Steps to reproduce

  1. Static code security scan. Example:
		private static void WriteEncryptionHeader(Stream stream, long crcValue)
		{
			byte[] cryptBuffer = new byte[ZipConstants.CryptoHeaderSize];
			var rnd = new Random();
			rnd.NextBytes(cryptBuffer);
			cryptBuffer[11] = (byte)(crcValue >> 24);
			stream.Write(cryptBuffer, 0, cryptBuffer.Length);
		}

Expected behavior

Replace all uses of System.Random() with a cryptographic version such as that provided by RNGCryptoServiceProvider.

Actual behavior

SharpZipLib fails security scans.

Version of SharpZipLib

1.3.0

Obtained from (only keep the relevant lines)

  • Package installed using NuGet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions