summaryrefslogtreecommitdiff
path: root/src/main/scala/spray/json/JsonParserSettings.scala
diff options
context:
space:
mode:
authorJohannes Rudolph <johannes.rudolph@gmail.com>2018-11-07 15:11:06 +0100
committerGitHub <noreply@github.com>2018-11-07 15:11:06 +0100
commitd56d7f42134ffdc3266188c4a459780b699d8056 (patch)
treefd9a2b8513d1cfb8afb47ab59bb5dbf41bca6539 /src/main/scala/spray/json/JsonParserSettings.scala
parent659d7e3efcec060305b5f7a1cd432c95bd702f47 (diff)
parenta55875309b804f10c22dffb1a37358518d8ac48d (diff)
downloadspray-json-d56d7f42134ffdc3266188c4a459780b699d8056.tar.gz
spray-json-d56d7f42134ffdc3266188c4a459780b699d8056.tar.bz2
spray-json-d56d7f42134ffdc3266188c4a459780b699d8056.zip
Merge pull request #284 from jrudolph/fix-uncontrolled-recursion
CVE-2018-18855 Fix uncontrolled recursion in JsonParser
Diffstat (limited to 'src/main/scala/spray/json/JsonParserSettings.scala')
-rw-r--r--src/main/scala/spray/json/JsonParserSettings.scala19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/scala/spray/json/JsonParserSettings.scala b/src/main/scala/spray/json/JsonParserSettings.scala
index 31692fd..d07075e 100644
--- a/src/main/scala/spray/json/JsonParserSettings.scala
+++ b/src/main/scala/spray/json/JsonParserSettings.scala
@@ -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)
+ }
} \ No newline at end of file