Serializable: mod whitelist check impl. to match Tufte

This commit is contained in:
Peter Taoussanis 2020-08-28 14:03:47 +02:00
parent 252d898ff1
commit b4b5450d97
2 changed files with 12 additions and 4 deletions

View file

@ -420,12 +420,20 @@
(comment (.getName (.getSuperclass (.getClass (java.util.concurrent.TimeoutException.))))) (comment (.getName (.getSuperclass (.getClass (java.util.concurrent.TimeoutException.)))))
(let [compile-whitelist (enc/memoize_ (fn [x] (if (set? x) (enc/compile-str-filter x) x)))] (let [fn? fn?
compile (enc/fmemoize (fn [x] (enc/compile-str-filter x)))
conform?* (fn [x ns] ((compile x) ns)) ; Uncached because input domain possibly infinite
conform?
(fn [x ns]
(if (fn? x)
(x ns) ; Intentionally uncached, can be handy
(conform?* x ns)))]
(defn- serializable-whitelisted? [class-name] (defn- serializable-whitelisted? [class-name]
((compile-whitelist *serializable-whitelist*) class-name))) (conform? *serializable-whitelist* class-name)))
(comment (comment
(enc/qb 1e5 (serializable-whitelisted? "foo")) (enc/qb 1e6 (serializable-whitelisted? "foo"))
(binding [*serializable-whitelist* #{"foo.*" "bar"}] (binding [*serializable-whitelist* #{"foo.*" "bar"}]
(serializable-whitelisted? "foo.bar"))) (serializable-whitelisted? "foo.bar")))

View file

@ -280,7 +280,7 @@
(get-in (get-in
(binding [nippy/*serializable-whitelist* #{}] (binding [nippy/*serializable-whitelist* #{}]
(nippy/thaw (nippy/thaw
(binding [nippy/*serializable-whitelist* #{"java.util.concurrent.Semaphore"}] (binding [nippy/*serializable-whitelist* "*"]
(nippy/freeze (java.util.concurrent.Semaphore. 1))))) (nippy/freeze (java.util.concurrent.Semaphore. 1)))))
[:nippy/unthawable :serializable-whitelist-pass?])) [:nippy/unthawable :serializable-whitelist-pass?]))