-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from ccudennec-otto/fix-CVE-2024-57699
fix CVE-2024-57699 for predefined parsers
- Loading branch information
Showing
3 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
json-smart/src/test/java/net/minidev/json/test/TestCVE202457699.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.minidev.json.test; | ||
|
||
import net.minidev.json.parser.JSONParser; | ||
import net.minidev.json.parser.ParseException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class TestCVE202457699 { | ||
|
||
private static final String MALICIOUS_STRING = createMaliciousString(); | ||
|
||
@Test | ||
public void jsonSimpleParserShouldRestrictDepth() { | ||
JSONParser p = new JSONParser(JSONParser.MODE_JSON_SIMPLE); | ||
assertThrows(ParseException.class, | ||
() -> p.parse(MALICIOUS_STRING), | ||
"Malicious payload, having non natural depths"); | ||
} | ||
|
||
@Test | ||
public void strictestParserShouldRestrictDepth() { | ||
JSONParser p = new JSONParser(JSONParser.MODE_STRICTEST); | ||
assertThrows(ParseException.class, | ||
() -> p.parse(MALICIOUS_STRING), | ||
"Malicious payload, having non natural depths"); | ||
} | ||
|
||
@Test | ||
public void rfc4627ParserShouldRestrictDepth() { | ||
JSONParser p = new JSONParser(JSONParser.MODE_RFC4627); | ||
assertThrows(ParseException.class, | ||
() -> p.parse(MALICIOUS_STRING), | ||
"Malicious payload, having non natural depths"); | ||
} | ||
|
||
@Test | ||
public void permissiveParserShouldRestrictDepth() { | ||
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE); | ||
assertThrows(ParseException.class, | ||
() -> p.parse(MALICIOUS_STRING), | ||
"Malicious payload, having non natural depths"); | ||
} | ||
|
||
private static String createMaliciousString() { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < 10000 ; i++) { | ||
sb.append("{\"a\":"); | ||
} | ||
sb.append("1"); | ||
for (int i = 0; i < 10000 ; i++) { | ||
sb.append("}"); | ||
} | ||
return sb.toString(); | ||
} | ||
} |