Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tdhintz opened this issue Nov 10, 2020 · 2 comments · Fixed by #538
Closed

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

tdhintz opened this issue Nov 10, 2020 · 2 comments · Fixed by #538

Comments

@tdhintz
Copy link

tdhintz commented Nov 10, 2020

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
@piksel
Copy link
Member

piksel commented Nov 10, 2020

The referenced code is this:

private static void WriteEncryptionHeader(Stream stream, long crcValue)

But the same method is also used in:

private void WriteEncryptionHeader(long crcValue)

@tdhintz
Copy link
Author

tdhintz commented Nov 10, 2020

There are possibly 3 uses of the insecure Random() found throughout the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants