clojail icon indicating copy to clipboard operation
clojail copied to clipboard

Poor error messages for testers using ClojailWrapper

Open dgshep opened this issue 4 years ago • 0 comments

When tripping a tester that uses the ClojailWrapper, the error message uses the default Object.toString and thus doesn't contain much useful context:

=> (let [sb (sandbox secure-tester)]
     (sb '(java.util.concurrent.ForkJoinPool.)))

Execution error (SecurityException) at clojail.core/security-exception (core.clj:119).
You tripped the alarm! clojail.testers.ClojailWrapper@5f0e3437 is bad!

It looks like this could be fixed by adding a toString implementation to ClojailWrapper:

--- a/src/clojail/testers.clj
+++ b/src/clojail/testers.clj
@@ -5,12 +5,15 @@
   (:require [bultitude.core :as nses]
             [serializable.fn :as sfn]))

-(deftype ClojailWrapper [object])
+(deftype ClojailWrapper [object]
+  Object
+  (toString [this]
+    (pr-str object)))

 (defmethod print-method ClojailWrapper
   [p out]
   (.write out (str "#clojail.testers.ClojailWrapper["
-                   (binding [*print-dup* true] (pr-str (.object p)))
+                   (binding [*print-dup* true] (str p))
                    "]")))

 (defn wrap-object
=> (let [sb (sandbox secure-tester)]
     (sb '(java.util.concurrent.ForkJoinPool.)))

Execution error (SecurityException) at clojail.core/security-exception (core.clj:119).
You tripped the alarm! "java.util.concurrent" is bad!

dgshep avatar Nov 28 '20 18:11 dgshep