From ab2410c754b67902f002bfcc0c3895bd7772d39f Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 23 Mar 2018 21:45:41 -0400 Subject: [PATCH] MimeTypeUtils uses SecureRandom The prevailing current wisdom is to use the default constructor for secure and let it pick the best algorithm for the OS. On Java 8 (Oracle), Linux this results in "NativePRNG" which uses /dev/random (potentially blocking) for the initial seed, and /dev/urandom (non-blocking) for subsequent calls to nextInt. Issue: SPR-16635 --- .../src/main/java/org/springframework/util/MimeTypeUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java index 259a4448733..98a0c59caf4 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java @@ -18,6 +18,7 @@ package org.springframework.util; import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -45,7 +46,7 @@ public abstract class MimeTypeUtils { 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; - private static final Random RND = new Random(); + private static final Random RND = new SecureRandom(); /** * Comparator used by {@link #sortBySpecificity(List)}.