clojure.tools.logging EvalReader 使用?

标签 clojure

我认为这是 clojure/tools.logging 中的一个错误。我有以下 db.clj 文件。它做什么并不重要。重要的是,为了安全起见,我禁用了*read-eval*。我调用 db/start 没有任何问题。但是,如果我取消注释 #_(log/info "Failed to bootstrap") 表单,则会引发 EvalReader not allowed 错误。我已经尝试了 log/info 调用的各种组合。如果它位于 try block 之外,那就没问题。在 try block 内的任何位置,无论是在正文、catch 还是 finally 中,都会引发此异常。但是,当我在其他地方用 try 包裹 log/info 时,就没有问题了。

什么给出了?

(ns extenium.db
  (:require [clojure.tools.logging :as log]
            [clojure.java.io :as io])
  (:import com.thinkaurelius.titan.core.TitanGraph
           com.thinkaurelius.titan.core.TitanFactory))

(def ^:private
  sentinel- (Object.))

(def ^:private
  db- (atom nil))

...

(defn start [^String path]
  (locking sentinel-
    (log/info "Starting database at path" path)
    (let [exists (.exists (io/file path))
          ^TitanGraph db_ (TitanFactory/open path)]
      (if exists
        (log/info "Path" path "exists")
        (log/info "Path" path "does not exist"))
      (log/info "Starting database engine")
      (swap! db- (constantly db_))
      (log/info "Started database engine")
      (if (not exists)
        (try
          (bootstrap-)
          (catch Throwable t
            #_(log/info "Failed to bootstrap")
            (stop)
            (.delete (io/file path))
            (throw t)))))
    (log/info "Started database")
    true))

编辑:根据@alex-taggart 修剪代码。 bootstrap- 实现未显示。我最初包含了所有内容,因为这似乎是一个特定于上下文的错误,我觉得提供尽可能多的上下文更安全。

编辑:根据@chouser,添加了我如何禁用*read-eval*。这是由 lein new app 生成的模板。

(defn -main
  "The main entry point into Extenium."
  [& args]
  ;; Prevent arbitrary eval injection
  (alter-var-root #'*read-eval* (constantly false))
  ;; Initialize system settings from the command line and configuration file
  (init!- args)
  ;; Start the service
  (start!-))

最佳答案

这真的不是一个错误。 clojure.tools.logging 库只是其他 Java 日志记录工具的抽象。为了发现哪一个可用,它使用 eval 表达式。欢迎您自行检查:这里有一个快速 search result和一个certain file它在哪里使用。

就您而言,我认为没有必要关心全局read-eval。这是一个内部功能,谁知道其他库依赖它。如果您验证用户输入并阻止对其进行评估,则可以按原样保留该标志。我想说,SQL注入(inject)和XSS是你首先应该担心的事情。

关于clojure.tools.logging EvalReader 使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16160633/

相关文章:

clojure - Clojure Repl中的先前表达

java - 主要的 Clojure NPE

matlab - 用于在 JVM 上进行富有表现力的、功能丰富的数值计算的工具

unit-testing - 如何在 test.check 中生成随机电子邮件地址?

用于 clojure korma 的 MySQL DB 驱动程序

clojure - 试图理解隐式 Leiningen 源路径/命名空间设置假设

java - android 上 java 的替代品

clojure - 我应该如何迭代序列?

emacs - 我可以将两个 emacs/slimes 连接到同一个 swank 实例吗?

syntax - 我什么时候应该使用 clojure 箭头宏?