Last active
August 31, 2019 22:09
-
-
Save borkdude/a600082397bb4f81de5173fe8a19e890 to your computer and use it in GitHub Desktop.
Safe read-eval with edamame and sci
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
$ clj -Sdeps '{:deps {borkdude/edamame {:mvn/version "0.0.2"} borkdude/sci {:mvn/version "0.0.9"}}}' | |
Clojure 1.10.1 | |
user=> (require '[sci.core :as sci]) | |
nil | |
user=> (require '[edamame.core :as edamame]) | |
nil | |
user=> (def trusted "{:version #=(slurp \"resources/EDAMAME_VERSION\")}") | |
#'user/trusted | |
user=> (edamame/parse-string trusted {:dispatch {\# {\= (fn [expr] (sci/eval-string (str expr) {:bindings {'slurp slurp}}))}}}) | |
{:version "0.0.3-SNAPSHOT\n"} | |
user=> (def dangerous "{:version #=(.delete (clojure.java.io/file \"README.md\"))}") | |
#'user/dangerous | |
user=> (edamame/parse-string dangerous {:dispatch {\# {\= (fn [expr] (sci/eval-string (str expr) {:bindings {'slurp slurp}}))}}}) | |
Execution error (ExceptionInfo) at sci.impl.utils/throw-error-with-location (utils.cljc:48). | |
Could not resolve symbol: .delete [at line 1, column 2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment