Merge pull request #403 from Pixee-Bot-Java/pixeebot/drip-2023-10-05-pixee-java/secure-random

Introduced protections against predictable RNG abuse
This commit is contained in:
Anthony Stirling 2023-11-03 00:58:11 +00:00 committed by GitHub
commit ddc48429b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,6 +13,7 @@ import java.io.ByteArrayOutputStream;
//Required for file input/output //Required for file input/output
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.security.SecureRandom;
//Other required classes //Other required classes
import java.util.Random; import java.util.Random;
@ -85,7 +86,7 @@ public class FakeScanControllerWIP {
op.filter(sourceImage, destinationImage); op.filter(sourceImage, destinationImage);
// Apply a rotation effect // Apply a rotation effect
double rotationRequired = Math.toRadians((new Random().nextInt(3 - 1) + 1)); // Random angle between 1 and 3 degrees double rotationRequired = Math.toRadians((new SecureRandom().nextInt(3 - 1) + 1)); // Random angle between 1 and 3 degrees
double locationX = destinationImage.getWidth() / 2; double locationX = destinationImage.getWidth() / 2;
double locationY = destinationImage.getHeight() / 2; double locationY = destinationImage.getHeight() / 2;
AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY); AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
@ -103,7 +104,7 @@ public class FakeScanControllerWIP {
destinationImage = blurOp.filter(destinationImage, null); destinationImage = blurOp.filter(destinationImage, null);
// Add noise to the image based on the "dirtiness" // Add noise to the image based on the "dirtiness"
Random random = new Random(); Random random = new SecureRandom();
for (int y = 0; y < destinationImage.getHeight(); y++) { for (int y = 0; y < destinationImage.getHeight(); y++) {
for (int x = 0; x < destinationImage.getWidth(); x++) { for (int x = 0; x < destinationImage.getWidth(); x++) {
if (random.nextInt(100) < dirtiness) { if (random.nextInt(100) < dirtiness) {