-
-
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.
fix CVE-2024-57699 for predefined parsers
- Loading branch information
1 parent
7f01adf
commit c21d854
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(); | ||
} | ||
} |
c21d854
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has that 2.5.2 version been cut? (given that it's marked as released on 2025-02-07 in the README here)
I don't see a corresponding tag or GitHub release and there's no 2.5.2 in the Central Repository either.
c21d854
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's confusing at the moment. The maintainer is currently waiting for approval by Sonatype to be able to push to Maven Central. See #233