-
Notifications
You must be signed in to change notification settings - Fork 7
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 #235 from sphereio/avoid_denial_service_big_number
avoid denial of service with big numbers
- Loading branch information
Showing
7 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
json/json-core/src/main/scala/io/sphere/json/SphereJsonParser.scala
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,16 @@ | ||
package io.sphere.json | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature.{USE_BIG_DECIMAL_FOR_FLOATS, USE_BIG_INTEGER_FOR_INTS} | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.json4s.jackson.{Json4sScalaModule, JsonMethods} | ||
|
||
// extends the default JsonMethods to configure a different default jackson parser | ||
private object SphereJsonParser extends JsonMethods { | ||
override val mapper: ObjectMapper = { | ||
val m = new ObjectMapper() | ||
m.registerModule(new Json4sScalaModule) | ||
m.configure(USE_BIG_INTEGER_FOR_INTS, false) | ||
m.configure(USE_BIG_DECIMAL_FOR_FLOATS, false) | ||
m | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
json/json-core/src/test/scala/io/sphere/json/BigNumberParsingSpec.scala
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,24 @@ | ||
package io.sphere.json | ||
|
||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
class BigNumberParsingSpec extends AnyWordSpec with Matchers { | ||
import BigNumberParsingSpec._ | ||
|
||
"parsing a big number" should { | ||
"not take much time when parsed as Double" in { | ||
fromJSON[Double](bigNumberAsString).isValid should be (false) | ||
} | ||
"not take much time when parsed as Long" in { | ||
fromJSON[Long](bigNumberAsString).isValid should be (false) | ||
} | ||
"not take much time when parsed as Int" in { | ||
fromJSON[Int](bigNumberAsString).isValid should be (false) | ||
} | ||
} | ||
} | ||
|
||
object BigNumberParsingSpec { | ||
private val bigNumberAsString = "9" * 10000000 | ||
} |
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
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