You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/eu/righettod/SecurityUtils.java
+48-8Lines changed: 48 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,7 @@
74
74
importjava.util.concurrent.atomic.AtomicInteger;
75
75
importjava.util.regex.Matcher;
76
76
importjava.util.regex.Pattern;
77
+
importjava.util.zip.GZIPInputStream;
77
78
importjava.util.zip.ZipEntry;
78
79
importjava.util.zip.ZipFile;
79
80
@@ -735,9 +736,9 @@ public static boolean isExcelCSVSafe(String csvFilePath) {
735
736
* Provide a way to add an integrity marker (<a href="https://en.wikipedia.org/wiki/HMAC">HMAC</a>) to a serialized object serialized using the <a href="https://www.baeldung.com/java-serialization">java native system</a> (binary).<br>
736
737
* The goal is to provide <b>a temporary workaround</b> to try to prevent deserialization attacks and give time to move to a text-based serialization approach.
737
738
*
738
-
* @param processingMode Define the mode of processing i.e. protect or validate. ({@link eu.righettod.ProcessingMode})
739
-
* @param input When the processing mode is "protect" than the expected input (string) is a java serialized object encoded in Base64 otherwise (processing mode is "validate") expected input is the output of this method when the "protect" mode was used.
740
-
* @param secret Secret to use to compute the SHA256 HMAC.
739
+
* @param processingModeType Define the mode of processing i.e. protect or validate. ({@link ProcessingModeType})
740
+
* @param input When the processing mode is "protect" than the expected input (string) is a java serialized object encoded in Base64 otherwise (processing mode is "validate") expected input is the output of this method when the "protect" mode was used.
741
+
* @param secret Secret to use to compute the SHA256 HMAC.
741
742
* @return A map with the following keys: <ul><li><b>PROCESSING_MODE</b>: Processing mode used to compute the result.</li><li><b>STATUS</b>: A boolean indicating if the processing was successful or not.</li><li><b>RESULT</b>: Always contains a string representing the protected serialized object in the format <code>[SERIALIZED_OBJECT_BASE64_ENCODED]:[SERIALIZED_OBJECT_HMAC_BASE64_ENCODED]</code>.</li></ul>
@@ -1542,4 +1543,43 @@ public static Map<SensitiveInformationType, Set<String>> extractAllSensitiveInfo
1542
1543
1543
1544
returndata;
1544
1545
}
1546
+
1547
+
/**
1548
+
* Apply a collection of validations on a bytes array provided representing GZIP compressed data:
1549
+
* <ul>
1550
+
* <li>Are valid GZIP compressed data.</li>
1551
+
* <li>The number of bytes once decompressed is under the specified limit.</li>
1552
+
* </ul>
1553
+
* <br><b>Note:</b> The value <code>Integer.MAX_VALUE - 8</code> was chosen because during my tests on Java 25 (JDK 64 bits on Windows 11 Pro), it was possible to decompress such amount of data with the default JVM settings without causing an <a href="https://docs.oracle.com/en/java/javase/25/docs/api//java.base/java/lang/OutOfMemoryError.html">Out Of Memory error</a>.
1554
+
*
1555
+
* @param compressedBytes Array of bytes containing the GZIP compressed data to check.
1556
+
* @param maxCountOfDecompressedBytesAllowed Maximum number of decompressed bytes allowed. Default to 10 MB if the specified value is inferior to 1 or superior to Integer.MAX_VALUE - 8.
1557
+
* @return True only if the file pass all validations.
0 commit comments