summaryrefslogtreecommitdiff
path: root/src/main/scala/spray/json/JsonParserSettings.scala
diff options
context:
space:
mode:
authorJohannes Rudolph <johannes.rudolph@gmail.com>2018-11-08 10:38:05 +0100
committerGitHub <noreply@github.com>2018-11-08 10:38:05 +0100
commitb2f485e695f8ba2789089f20d48554bb80c77396 (patch)
tree42dbd2c37a172f9534b33a04fbef589dfa5ea886 /src/main/scala/spray/json/JsonParserSettings.scala
parentd56d7f42134ffdc3266188c4a459780b699d8056 (diff)
parenta8c45e7abb575705e5538c00d1113688197e1849 (diff)
downloadspray-json-b2f485e695f8ba2789089f20d48554bb80c77396.tar.gz
spray-json-b2f485e695f8ba2789089f20d48554bb80c77396.tar.bz2
spray-json-b2f485e695f8ba2789089f20d48554bb80c77396.zip
Merge pull request #283 from jrudolph/limit-size-of-numbers
CVE-2018-18853 Limit the number of characters for numbers in the parser, fixes #278
Diffstat (limited to 'src/main/scala/spray/json/JsonParserSettings.scala')
-rw-r--r--src/main/scala/spray/json/JsonParserSettings.scala17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/main/scala/spray/json/JsonParserSettings.scala b/src/main/scala/spray/json/JsonParserSettings.scala
index d07075e..b82c47d 100644
--- a/src/main/scala/spray/json/JsonParserSettings.scala
+++ b/src/main/scala/spray/json/JsonParserSettings.scala
@@ -12,16 +12,29 @@ trait JsonParserSettings {
def maxDepth: Int
/**
- * Return a copy of this settings object with the `maxDepth` setting changed to the new value.
+ * Returns a copy of this settings object with the `maxDepth` setting changed to the new value.
*/
def withMaxDepth(newValue: Int): JsonParserSettings
+
+ /**
+ * The maximum number of characters the parser should support for numbers. This is restricted because creating
+ * `BigDecimal`s with high precision can be very slow (approx. quadratic runtime per amount of characters).
+ */
+ def maxNumberCharacters: Int
+
+ /**
+ * Returns a copy of this settings object with the `maxNumberCharacters` setting changed to the new value.
+ */
+ def withMaxNumberCharacters(newValue: Int): JsonParserSettings
}
object JsonParserSettings {
val default: JsonParserSettings = SettingsImpl()
private case class SettingsImpl(
- maxDepth: Int = 1000
+ maxDepth: Int = 1000,
+ maxNumberCharacters: Int = 100
) extends JsonParserSettings {
override def withMaxDepth(newValue: Int): JsonParserSettings = copy(maxDepth = newValue)
+ override def withMaxNumberCharacters(newValue: Int): JsonParserSettings = copy(maxNumberCharacters = newValue)
}
} \ No newline at end of file