Skip to content

Commit 30754ea

Browse files
committed
Allow for large json strings in webdriver response
Etaoin uses cheshire which uses jackson. Jackson implemented, for security reasons, processing limits. Starting with cheshire 6.0.0 these jackson limits are configurable. The default json input string length for jackson is 20mb. This is small for Etaoin, a webdriver will return a base64 encoded pdf for a print page request. We've bumped the json input string limit to ~2gb. Closes #691
1 parent f42f282 commit 30754ea

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ A release with an intentional breaking changes is marked with:
2222
* Changes
2323
** Bumped deps.
2424
({lread})
25+
** {issue}691[#691]: Allow for large json strings in webdriver responses
26+
({lread})
2527
** {issue}696[#696]: Stop hiding json parse exceptions
2628
({lread})
2729
** {issue}676[#676]: Fix new driver creation so that it sidesteps some underlying Firefox race conditions and improves CI test stability. ({person}dgr[@dgr])

src/etaoin/impl/client.clj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
(:require
33
[babashka.http-client :as client]
44
[cheshire.core :as json]
5+
[cheshire.factory :as cheshire-factory]
56
[clojure.string :as str]
67
[clojure.tools.logging :as log]
78
[etaoin.impl.proc :as proc]
@@ -37,6 +38,12 @@
3738
;;
3839
;; helpers
3940
;;
41+
(def ^:private default-jackson-factory
42+
"The default jackson input string length is 20mb which is low for Etaoin.
43+
For example a webdriver print page returns the page pdf as a base64 encoded string.
44+
The current underlying jackson 2.8.3 option type is an `int` so we are effectively using the max
45+
possible for this option (just under 2GiB)."
46+
(cheshire-factory/make-json-factory {:max-input-string-length Integer/MAX_VALUE}))
4047

4148
(defn- url-item-str [item]
4249
(cond
@@ -50,7 +57,11 @@
5057

5158
(defn- parse-json [body]
5259
(let [body* (str/replace body #"Invalid Command Method -" "")]
53-
(json/parse-string body* true)))
60+
;; override jackson options, prefer user specified binding
61+
;; (not officially supported but convenient for testing)
62+
(binding [cheshire-factory/*json-factory* (or cheshire-factory/*json-factory*
63+
default-jackson-factory)]
64+
(json/parse-string body* true))))
5465

5566
(defn- error-response [body]
5667
(if (string? body)

0 commit comments

Comments
 (0)