3

我认为这是clojure/tools.logging. 我有以下db.clj文件。它做什么并不重要。重要的是,为了安全起见,我禁用了*read-eval*. 我调用db/start没有问题。但是,如果我取消注释#_(log/info "Failed to bootstrap")表单,则会引发EvalReader not allowed错误。log/info我已经为通话尝试了各种组合。如果它在try街区之外,那很好。在try块内的任何地方,无论是在正文中catch,还是在 中finally,都会引发此异常。但是,当我在其他地方环绕时trylog/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 修剪代码。未显示引导程序实现。我最初包含所有内容,因为这似乎是一个特定于上下文的错误,我觉得提供尽可能多的上下文更安全。

编辑:每个@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!-))
4

1 回答 1

0

这不是一个错误,真的。该clojure.tools.logging库只是对其他 Java 日志记录工具的抽象。为了发现哪一个可用,它使用eval表达式。欢迎您自己检查:这是一个快速搜索结果和一个使用它的特定文件

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

于 2019-03-01T07:54:43.223 回答