-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CVE-2018-18855 Fix uncontrolled recursion in the JsonParser by imposi…
…ng a configurable limit on the depth, fixes #286
- Loading branch information
Showing
3 changed files
with
68 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
package spray.json | ||
|
||
trait JsonParserSettings { | ||
/** | ||
* The JsonParser uses recursive decent parsing that keeps intermediate values on the stack. To prevent | ||
* StackOverflowExceptions a limit is enforced on the depth of the parsed JSON structure. | ||
* | ||
* As a guideline we tested that one level of depth needs about 300 bytes of stack space. | ||
* | ||
* The default is a depth of 1000. | ||
*/ | ||
def maxDepth: Int | ||
|
||
/** | ||
* Return a copy of this settings object with the `maxDepth` setting changed to the new value. | ||
*/ | ||
def withMaxDepth(newValue: Int): JsonParserSettings | ||
} | ||
object JsonParserSettings { | ||
val default: JsonParserSettings = SettingsImpl() | ||
|
||
private case class SettingsImpl() extends JsonParserSettings | ||
private case class SettingsImpl( | ||
maxDepth: Int = 1000 | ||
) extends JsonParserSettings { | ||
override def withMaxDepth(newValue: Int): JsonParserSettings = copy(maxDepth = newValue) | ||
} | ||
} |
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