Guest User

Untitled

a guest
Apr 26th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. def handlePost(): Action[NodeSeq] = Action.async(parse.xml) {
  2. implicit request =>
  3. Future.successful(Ok(request.body))
  4. }
  5.  
  6. class RoutesSpec extends PlaySpec with GuiceOneAppPerSuite {
  7. "The POST route" must {
  8. "not handle XXE XML" in {
  9. val xml: Elem = scala.xml.XML.loadString(
  10. """<?xml version="1.0" encoding="utf-8"?>
  11. |<!DOCTYPE foo [
  12. |<!ELEMENT foo (bar)>
  13. | <!ELEMENT bar (#PCDATA)>
  14. |]>
  15. |<foo>
  16. | <bar>string</bar>
  17. |</foo>
  18. """.stripMargin)
  19. val Some(result) = route(app, FakeRequest(POST_REQUEST, "/my-route")
  20. .withXmlBody(xml))
  21. status(result) mustEqual 400 // currently returns 200
  22. }
  23. }
  24. }
  25.  
  26. class RoutesSpec extends PlaySpec with GuiceOneAppPerSuite {
  27. "The POST route" must {
  28. "not handle XXE XML" in {
  29. val xml = scala.xml.Unparsed(
  30. """<?xml version="1.0" encoding="utf-8"?>
  31. |<!DOCTYPE foo [
  32. |<!ELEMENT foo (bar)>
  33. | <!ELEMENT bar (#PCDATA)>
  34. |]>
  35. |<foo>
  36. | <bar>string</bar>
  37. |</foo>
  38. """.stripMargin)
  39.  
  40. val Some(result) = route(app, FakeRequest(POST_REQUEST, "/my-route")
  41. .withXmlBody(xml))
  42.  
  43. status(result) mustEqual 400
  44. contentAsString(result) mustBe """{"statusCode":400,"message":"bad request"}"""
  45. }
  46. }
  47. }
Add Comment
Please, Sign In to add comment